144 lines
5.1 KiB
JavaScript
144 lines
5.1 KiB
JavaScript
const { app, Menu, shell, dialog} = require('electron')
|
|
const {stat,readdir} = require("fs/promises");
|
|
const isMac = process.platform === 'darwin'
|
|
exports.menuRebuild=(mainWindow)=> {
|
|
return template = [
|
|
// { role: 'appMenu' }
|
|
...(isMac
|
|
? [{
|
|
label: app.name,
|
|
submenu: [
|
|
{ role: 'about' },
|
|
{ type: 'separator' },
|
|
{ role: 'services' },
|
|
{ type: 'separator' },
|
|
{ role: 'hide' },
|
|
{ role: 'hideOthers' },
|
|
{ role: 'unhide' },
|
|
{ type: 'separator' },
|
|
{ role: 'quit' }
|
|
]
|
|
}]
|
|
: []),
|
|
// { role: 'fileMenu' }
|
|
{
|
|
label: 'File',
|
|
submenu: [
|
|
{label:'打开目录',
|
|
click: async () => {
|
|
const { dialog } = require('electron')
|
|
dialog.showOpenDialog({
|
|
properties: ['openDirectory']
|
|
}).then(async result => {
|
|
console.log(result.canceled)
|
|
// 不取消就发送目录
|
|
if (!result.canceled) {
|
|
console.log(result.filePaths)
|
|
const {readdir,stat} = require('fs/promises')
|
|
try {
|
|
const files = await readdir(result.filePaths[0]);
|
|
const fileStats = []
|
|
for (let i = 0; i < files.length; i++) {
|
|
const state = await stat(result.filePaths+'/'+files[i]);
|
|
fileStats.push({'fileName': files[i], 'dir':state.isDirectory()})
|
|
}
|
|
mainWindow.webContents.send('openDirectory',
|
|
{'fileDir':result.filePaths,'fileList':fileStats}
|
|
)
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
}
|
|
},
|
|
{label:'全部应用',
|
|
click: () => {
|
|
mainWindow.webContents.send('redirectUrl', '/GateWay')
|
|
}
|
|
},
|
|
isMac ? { role: 'close' } : { role: 'quit' },
|
|
]
|
|
},
|
|
// { role: 'editMenu' }
|
|
{
|
|
label: 'Edit',
|
|
submenu: [
|
|
{ role: 'undo' },
|
|
{ role: 'redo' },
|
|
{ type: 'separator' },// 分割线
|
|
{ role: 'cut' },
|
|
{ role: 'copy' },
|
|
{ role: 'paste' },
|
|
...(isMac
|
|
? [
|
|
{ role: 'pasteAndMatchStyle' },
|
|
{ role: 'delete' },
|
|
{ role: 'selectAll' },
|
|
{ type: 'separator' },
|
|
{
|
|
label: 'Speech',
|
|
submenu: [
|
|
{ role: 'startSpeaking' },
|
|
{ role: 'stopSpeaking' }
|
|
]
|
|
}
|
|
]
|
|
: [
|
|
{ role: 'delete' },
|
|
{ type: 'separator' },
|
|
{ role: 'selectAll' }
|
|
])
|
|
]
|
|
},
|
|
// { role: 'viewMenu' }
|
|
{
|
|
label: 'View',
|
|
submenu: [
|
|
{ label: '界面布局' },
|
|
{ role: 'reload' },
|
|
{ role: 'forceReload' },
|
|
{ role: 'toggleDevTools' },
|
|
{ type: 'separator' },
|
|
{ role: 'resetZoom' },
|
|
{ role: 'zoomIn' },
|
|
{ role: 'zoomOut' },
|
|
{ type: 'separator' },
|
|
{ role: 'togglefullscreen' }
|
|
]
|
|
},
|
|
// { role: 'windowMenu' }
|
|
{
|
|
label: 'Window',
|
|
submenu: [
|
|
{ role: 'minimize' },
|
|
{ role: 'zoom' },
|
|
...(isMac
|
|
? [
|
|
{ type: 'separator' },
|
|
{ role: 'front' },
|
|
{ type: 'separator' },
|
|
{ role: 'window' }
|
|
]
|
|
: [
|
|
{ role: 'close' }
|
|
])
|
|
]
|
|
},
|
|
{
|
|
role: 'help',
|
|
submenu: [
|
|
{
|
|
label: 'Learn More',
|
|
click: async () => {
|
|
const { shell } = require('electron')
|
|
await shell.openExternal('http://www.huaruyu.com')
|
|
}
|
|
}
|
|
]
|
|
}
|
|
];
|
|
}
|