2024-01-24 21:07:09 -05:00
|
|
|
const {app, Menu, shell, dialog} = require('electron')
|
|
|
|
const {stat, readdir} = require("fs/promises");
|
2024-01-05 03:24:35 -05:00
|
|
|
const isMac = process.platform === 'darwin'
|
2024-02-04 21:59:35 -05:00
|
|
|
const readDirLocal=async (filePath) => {
|
|
|
|
const files = await readdir(filePath);
|
|
|
|
const fileStateList = []
|
|
|
|
const fileChildList = []
|
|
|
|
fileStateList.push({
|
|
|
|
"fileName": filePath,
|
|
|
|
"filePath": filePath,
|
|
|
|
"dirFlag": true,
|
|
|
|
"childList": fileChildList
|
|
|
|
})
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
const state = await stat(filePath + '/' + files[i]);
|
|
|
|
if (state.isDirectory()
|
|
|
|
|| files[i].endsWith(".md")
|
|
|
|
|| files[i].endsWith(".html")
|
|
|
|
|| files[i].endsWith(".lexical")) {
|
|
|
|
fileChildList.push({
|
|
|
|
'fileName': files[i],
|
|
|
|
"filePath": filePath + '/' + files[i],
|
|
|
|
'dirFlag': state.isDirectory(),
|
|
|
|
"childList":[]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fileStateList
|
|
|
|
}
|
2024-01-24 21:07:09 -05:00
|
|
|
exports.menuRebuild = (mainWindow) => {
|
2024-01-05 05:01:13 -05:00
|
|
|
return template = [
|
|
|
|
// { role: 'appMenu' }
|
|
|
|
...(isMac
|
|
|
|
? [{
|
|
|
|
label: app.name,
|
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'about'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'services'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'hide'},
|
|
|
|
{role: 'hideOthers'},
|
|
|
|
{role: 'unhide'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'quit'}
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
}]
|
|
|
|
: []),
|
|
|
|
// { role: 'fileMenu' }
|
|
|
|
{
|
2024-01-27 22:48:48 -05:00
|
|
|
label: '文件',
|
2024-01-05 03:24:35 -05:00
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{
|
|
|
|
label: '打开目录',
|
2024-01-05 05:01:13 -05:00
|
|
|
click: async () => {
|
2024-01-24 21:07:09 -05:00
|
|
|
const {dialog} = require('electron')
|
2024-01-05 05:01:13 -05:00
|
|
|
dialog.showOpenDialog({
|
|
|
|
properties: ['openDirectory']
|
|
|
|
}).then(async result => {
|
|
|
|
// 不取消就发送目录
|
|
|
|
if (!result.canceled) {
|
2024-01-24 21:07:09 -05:00
|
|
|
console.log('result.filePaths', result.filePaths)
|
2024-01-05 05:01:13 -05:00
|
|
|
try {
|
2024-02-05 03:34:41 -05:00
|
|
|
readDirLocal(result.filePaths[0]).then(dirDirectory=>{
|
|
|
|
mainWindow.webContents.send('openDirectory', dirDirectory)
|
|
|
|
})
|
2024-01-05 05:01:13 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2024-01-31 21:36:30 -05:00
|
|
|
{
|
|
|
|
label: '保存文件',
|
|
|
|
accelerator: 'Ctrl+S',
|
|
|
|
click: () => { // console.log('Electron rocks!')
|
|
|
|
}
|
|
|
|
},
|
2024-01-24 21:07:09 -05:00
|
|
|
{
|
|
|
|
label: '全部应用',
|
2024-01-24 01:50:27 -05:00
|
|
|
click: () => {
|
|
|
|
mainWindow.webContents.send('redirectUrl', '/GateWay')
|
|
|
|
}
|
|
|
|
},
|
2024-01-24 21:07:09 -05:00
|
|
|
isMac ? {role: 'close'} : {role: 'quit'},
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
},
|
|
|
|
// { role: 'editMenu' }
|
|
|
|
{
|
|
|
|
label: 'Edit',
|
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'undo'},
|
|
|
|
{role: 'redo'},
|
|
|
|
{type: 'separator'},// 分割线
|
|
|
|
{role: 'cut'},
|
|
|
|
{role: 'copy'},
|
|
|
|
{role: 'paste'},
|
2024-01-05 05:01:13 -05:00
|
|
|
...(isMac
|
|
|
|
? [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'pasteAndMatchStyle'},
|
|
|
|
{role: 'delete'},
|
|
|
|
{role: 'selectAll'},
|
|
|
|
{type: 'separator'},
|
2024-01-05 05:01:13 -05:00
|
|
|
{
|
|
|
|
label: 'Speech',
|
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'startSpeaking'},
|
|
|
|
{role: 'stopSpeaking'}
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'delete'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'selectAll'}
|
2024-01-05 05:01:13 -05:00
|
|
|
])
|
|
|
|
]
|
|
|
|
},
|
|
|
|
// { role: 'viewMenu' }
|
|
|
|
{
|
|
|
|
label: 'View',
|
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{label: '界面布局'},
|
|
|
|
{role: 'reload'},
|
|
|
|
{role: 'forceReload'},
|
|
|
|
{role: 'toggleDevTools'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'resetZoom'},
|
|
|
|
{role: 'zoomIn'},
|
|
|
|
{role: 'zoomOut'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'togglefullscreen'}
|
2024-01-05 03:24:35 -05:00
|
|
|
]
|
2024-01-05 05:01:13 -05:00
|
|
|
},
|
|
|
|
// { role: 'windowMenu' }
|
|
|
|
{
|
|
|
|
label: 'Window',
|
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'minimize'},
|
|
|
|
{role: 'zoom'},
|
2024-01-05 05:01:13 -05:00
|
|
|
...(isMac
|
|
|
|
? [
|
2024-01-24 21:07:09 -05:00
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'front'},
|
|
|
|
{type: 'separator'},
|
|
|
|
{role: 'window'}
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{role: 'close'}
|
2024-01-05 05:01:13 -05:00
|
|
|
])
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: 'Learn More',
|
|
|
|
click: async () => {
|
2024-01-24 21:07:09 -05:00
|
|
|
const {shell} = require('electron')
|
2024-01-05 05:01:13 -05:00
|
|
|
await shell.openExternal('http://www.huaruyu.com')
|
2024-01-05 03:24:35 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|