标签:efault log 打开 开发实战 menu not show containe orb turn
//在文件管理器中打开
const { ..., shell } = require(‘electron‘);
const showFile = () => {
if (!filePath) { return alert(‘This file has not been saved to the file system.‘); }
shell.showItemInFolder(filePath);
};
//使用默认程序打开
const openInDefaultApplication = () => {
if (!filePath) { return alert(‘This file has not been saved to the file system.‘); }
//electron-9.x 已经不存在了
shell.openItem(fullPath)
};
{ type: ‘separator‘ },
{
label: ‘Show File‘,
enabled: hasFilePath,
click(item, focusedWindow) {
if (!focusedWindow) {
return dialog.showErrorBox(
‘Cannot Show File\‘s Location‘,
‘There is currently no active document show.‘
);
}
focusedWindow.webContents.send(‘show-file‘);
},
},
{
label: ‘Open in Default Application‘,
enabled: hasFilePath,
click(item, focusedWindow) {
if (!focusedWindow) {
return dialog.showErrorBox(
‘Cannot Open File in Default Application‘,
‘There is currently no active document to open.‘
);
}
focusedWindow.webContents.send(‘open-in-default‘);
},
},
ipcRenderer.on(‘show-file‘, showFile);
ipcRenderer.on(‘open-in-default‘, openInDefaultApplication);
//上下文菜单
const markdownContextMenu = Menu.buildFromTemplate([
...
{
label: ‘Show File in Folder‘,
click: showFile,
enabled: !!filePath
},
{
label: ‘Open in Default‘,
click: openInDefaultApplication,
enabled: !!filePath
},
{ type: ‘separator‘ },
...
]);
markdownView.addEventListener(‘contextmenu‘, (event) => {
event.preventDefault();
markdownContextMenu.popup();
});
08.《Electron 跨平台开发实战》- chapter08-深入集成(shell模块)、动态启动菜单项
标签:efault log 打开 开发实战 menu not show containe orb turn
原文地址:https://www.cnblogs.com/easy5weikai/p/13143293.html