1 Star 0 Fork 10

HalfView/shark_weight_electron

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.js 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
juju 提交于 2021-07-21 18:29 . # 系统设置
const { app,BrowserWindow,ipcMain,Menu,session } = require('electron');
const path = require('path');
const windows = new Set();
// process.env
function setWindowMenu(win, menu) {
if (process.platform === "darwin") {
Menu.setApplicationMenu(menu);
win.on("focus", () => {
Menu.setApplicationMenu(menu);
});
} else {
win.setMenu(menu);
}
}
const createWindow = (options={
url:process.env.NODE_ENV === 'production'?'./dist/index.html':'http://localhost:3000/#/login',
protocal:process.env.NODE_ENV === 'production'?'FILE':'URL',
hash:'Login',
isDevTools:true,
callback:function(){}}) => {
(async () =>await session.defaultSession.loadExtension("C:\\Apps\\react-devtools\\shells\\chrome\\build\\unpacked"))();
// BrowserWindow.addDevToolsExtension('D:\\soft\\nginx\\www\\react-devtools\\shells\\chrome');
let newWindow = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
preload: 'preload.tsx',
webSecurity: false,
// contextIsolation:false,
nodeIntegration: true,
contextIsolation:false,
enableRemoteModule:true
},
show:false
});
if(options.protocal === 'URL'){
newWindow.loadURL(options.url);
}
else{
newWindow.loadFile(options.url,{
hash: options.hash
});
}
newWindow.once('ready-to-show',() => {
newWindow.show();
});
if(options.isDevTools === true){
newWindow.openDevTools();
// newWindow.addDevToolsExtension('D:\\soft\\nginx\\www\\react-devtools\\shells\\chrome');
}
newWindow.on('closed', function () {
windows.delete(newWindow);
newWindow = null;
});
// options.callback();
windows.add(newWindow);
return newWindow;
}
app.allowRendererProcessReuse = false;
app.on('ready', ()=>{
createWindow();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
ipcMain.on('cmd',(e,msg1,msg2)=>{
// console.log(msg1);
// console.log(msg2);
// e.sender.send("sendMain","this is a main");
});
ipcMain.on('onTemplateSettingOpen',(e,recv) => {
});
// var menu = Menu.buildFromTemplate(options.menu);
exports.createWindow = createWindow;
exports.setWindowMenu = setWindowMenu;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/HalfView/shark_weight_electron.git
[email protected]:HalfView/shark_weight_electron.git
HalfView
shark_weight_electron
shark_weight_electron
master

搜索帮助