src/renderer/util/option.js
export const mainOption = { 1000, height: 520, // width 和 height 将设置为 web 页面的尺寸 useContentSize: true, // 窗口在屏幕居中 center: true, // 窗口是否可以改变尺寸 开启后maximizable失效 resizable: false, // 窗口是否可以移动 // movable: true, // 窗口是否可以最小化 minimizable: true, // 窗口是否可以最大化 maximizable: true, // 置顶窗口 alwaysOnTop: false, webPreferences: { // 是否开启 DevTools,开发模式默认位true // devTools:true, // 是否集成Node // nodeIntegration: false, // 禁用同源策略 webSecurity: false, // 是否允许一个使用 https的界面来展示由 http URLs 传过来的资源。默认false allowDisplayingInsecureContent: false, // 是否允许一个使用 https的界面来渲染由 http URLs 提交的html,css,javascript。默认为 false。 allowRunningInsecureContent: false, nativeWindowOpen: true }, show: false, backgroundColor: '#fff' };
src/main/index.js
import {app, BrowserWindow} from 'electron'
import {mainOption} from "../renderer/util/option";
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\/g, '\\')
}
let mainWindow;
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`;
const createWindow = () => {
mainWindow = new BrowserWindow(mainOption);
mainWindow.once('ready-to-show', () => {
mainWindow.show()
});
mainWindow.loadURL(winURL);
mainWindow.setMenu(null);
mainWindow.on('closed', () => {
mainWindow = null
});
};
// 完成初始化
app.on('ready', createWindow);
// 当所有的窗口都被关闭时触发
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
});
/**
* Auto Updater
*
* Uncomment the following code below and install `electron-updater` to
* support auto updating. Code Signing with a valid certificate is required.
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
*/
/*
import { autoUpdater } from 'electron-updater'
autoUpdater.on('update-downloaded', () => {
autoUpdater.quitAndInstall()
})
app.on('ready', () => {
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
})
*/