2024-01-24 21:07:09 -05:00
|
|
|
const {app, Menu, shell, dialog} = require('electron')
|
|
|
|
const {stat, readdir} = require("fs/promises");
|
2024-02-19 23:38:49 -05:00
|
|
|
const pathOp = require('path')
|
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,
|
2024-02-19 23:38:49 -05:00
|
|
|
"children": fileChildList
|
2024-02-04 21:59:35 -05:00
|
|
|
})
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
2024-02-19 23:38:49 -05:00
|
|
|
const state = await stat(filePath + pathOp.sep + files[i]);
|
2024-02-04 21:59:35 -05:00
|
|
|
if (state.isDirectory()
|
|
|
|
|| files[i].endsWith(".md")
|
|
|
|
|| files[i].endsWith(".html")
|
|
|
|
|| files[i].endsWith(".lexical")) {
|
|
|
|
fileChildList.push({
|
|
|
|
'fileName': files[i],
|
2024-02-19 23:38:49 -05:00
|
|
|
"filePath": filePath + pathOp.sep + files[i],
|
2024-02-04 21:59:35 -05:00
|
|
|
'dirFlag': state.isDirectory(),
|
2024-02-19 23:38:49 -05:00
|
|
|
"children":[]
|
2024-02-04 21:59:35 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fileStateList
|
|
|
|
}
|
2024-01-24 21:07:09 -05:00
|
|
|
exports.menuRebuild = (mainWindow) => {
|
2024-01-05 05:01:13 -05:00
|
|
|
return template = [
|
|
|
|
{
|
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
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2024-03-08 04:54:39 -05:00
|
|
|
label: '编辑',
|
2024-01-05 05:01:13 -05:00
|
|
|
submenu: [
|
2024-03-08 04:54:39 -05:00
|
|
|
{label: '撤销'},
|
|
|
|
{label: '取消撤销'},
|
2024-01-24 21:07:09 -05:00
|
|
|
{type: 'separator'},// 分割线
|
2024-03-08 04:54:39 -05:00
|
|
|
{label: '剪切'},
|
|
|
|
{label: '复制'},
|
|
|
|
{label: '粘贴'},
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
|
|
|
},
|
|
|
|
// { role: 'viewMenu' }
|
|
|
|
{
|
2024-03-08 04:54:39 -05:00
|
|
|
label: '视图',
|
2024-01-05 05:01:13 -05:00
|
|
|
submenu: [
|
2024-01-24 21:07:09 -05:00
|
|
|
{label: '界面布局'},
|
2024-01-05 03:24:35 -05:00
|
|
|
]
|
2024-01-05 05:01:13 -05:00
|
|
|
},
|
|
|
|
{
|
2024-03-08 04:54:39 -05:00
|
|
|
label: '帮助',
|
2024-01-05 05:01:13 -05:00
|
|
|
submenu: [
|
|
|
|
{
|
2024-03-08 04:54:39 -05:00
|
|
|
label: '了解更多',
|
2024-01-05 05:01:13 -05:00
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('http://www.huaruyu.com')
|
2024-01-05 03:24:35 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-05 05:01:13 -05:00
|
|
|
]
|
2024-03-13 04:21:03 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '云服务',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: '同步上传',
|
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('http://www.huaruyu.com')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '同步下载',
|
|
|
|
click: async () => {
|
|
|
|
await shell.openExternal('http://www.huaruyu.com')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2024-01-05 05:01:13 -05:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|