@truenewx/tnxet
Version:
互联网技术解决方案:Electron扩展支持
40 lines (38 loc) • 1.24 kB
JavaScript
/**
* 对Electron主进程的扩展支持
*/
import {BrowserWindow} from 'electron';
import common from './tnxet-common.js';
import util from './main/main-util.js';
import ipc from './main/main-ipc.js';
export default {
isProduction() {
return !process.argv[0].endsWith('electron.exe');
},
getAbsolutePathBasedOnApp(filePath) {
return util.file.getAbsolutePathBasedOnApp(filePath);
},
init() {
ipc.register();
},
createWindow(options) {
let win = new BrowserWindow(options);
this.init();
win.enableDevTools = inputKey => {
this.enableDevTools(win, inputKey);
}
return win;
},
enableDevTools(browserWindow, inputKey) {
inputKey = inputKey || 'F12';
browserWindow.webContents.on('before-input-event', (event, input) => {
if (input.key === inputKey) {
event.preventDefault(); // 阻止默认行为
browserWindow.webContents.toggleDevTools(); // 打开或关闭开发者工具
}
});
},
sendCommand(win, name, ...args) {
win.webContents.send(common.channel.command, {name, args});
},
};