Skip to content

Commit

Permalink
fix windows file not found problem
Browse files Browse the repository at this point in the history
  • Loading branch information
lony2003 committed Jun 14, 2024
1 parent 1b4fa66 commit 2293cdb
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function getWrapperUrl() {
return urlUtil.format({
protocol: 'edge',
slashes: true,
pathname: path.join(process.env.DIST, 'index.html')
host: "copilot",
pathname: 'index.html'
})
}
}
Expand Down Expand Up @@ -98,38 +99,38 @@ function createWindow() {
// Get always on top settings
const alwaysOnTop = config.get('alwaysOnTop')
mainWindow.setAlwaysOnTop(alwaysOnTop)
// darwin表示macOS,针对macOS的设置 process.platform === 'darwin'
if (process.platform === 'darwin') {
const template = [{
label: '我的应用',
submenu: [
{ label: '关于', accelerator: 'CmdOrCtrl+I', role: 'about' },
{ type: 'separator' },
{ label: '隐藏', role: 'hide' },
{ label: '隐藏其他', role: 'hideOthers' },
{ type: 'separator' },
{ label: '服务', role: 'services' },
{ label: '退出', accelerator: 'Command+Q',role: 'quit' }
]
},
{
label: '编辑',
submenu: [
{ label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' },
{ label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' },
{ label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' },
{ label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo' },
{ label: '重做', accelerator: 'Shift+CmdOrCtrl+Z', role: 'redo' },
{ label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectAll' }
]
}]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
} else {
// windows及linux系统 Hide main menu
Menu.setApplicationMenu(Menu.buildFromTemplate([]))
}

// darwin表示macOS,针对macOS的设置 process.platform === 'darwin'
if (process.platform === 'darwin') {
const template = [{
label: '我的应用',
submenu: [
{label: '关于', accelerator: 'CmdOrCtrl+I', role: 'about'},
{type: 'separator'},
{label: '隐藏', role: 'hide'},
{label: '隐藏其他', role: 'hideOthers'},
{type: 'separator'},
{label: '服务', role: 'services'},
{label: '退出', accelerator: 'Command+Q', role: 'quit'}
]
},
{
label: '编辑',
submenu: [
{label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy'},
{label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste'},
{label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut'},
{label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo'},
{label: '重做', accelerator: 'Shift+CmdOrCtrl+Z', role: 'redo'},
{label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectAll'}
]
}]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
} else {
// windows及linux系统 Hide main menu
Menu.setApplicationMenu(Menu.buildFromTemplate([]))
}
// Create context menu
contextMenu({
window: mainWindow.webContents,
Expand Down Expand Up @@ -438,14 +439,26 @@ function createWindow() {
}

protocol.registerSchemesAsPrivileged([
{ scheme: 'edge', privileges: { standard: true, supportFetchAPI: true } }
{scheme: 'edge', privileges: {standard: true, supportFetchAPI: true}}
])

app.whenReady().then(() => {

protocol.handle('edge', (request) => {
const filePath = request.url.slice('edge://'.length)
return net.fetch(new URL(filePath, 'file:').toString())
const fileUrl = new URL(request.url);

// console.log(fileUrl)

let fileString = urlUtil.format({
protocol: 'file',
slashes: true,
pathname: path.join(process.env.DIST, fileUrl.pathname),
...fileUrl
})

// console.log(fileString);

return net.fetch(fileString)
})

autoUpdater.autoDownload = false;
Expand Down

0 comments on commit 2293cdb

Please sign in to comment.