electron launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.6 KiB

const { app, BrowserWindow, dialog, protocol } = require('electron')
const { create: createMainWindow } = require('./windows/main')
const { MANUAL_CREATED_FLAG } = require('./constant')
const handleIPC = require('./ipc')
app.commandLine.appendSwitch("--disable-http-cache");
app.whenReady().then(() => {
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = decodeURI(request.url.replace('file:///', ''));
callback(pathname);
});
handleIPC();
createMainWindow()
app.on('browser-window-created', (event, window) => {
setTimeout(() => {
if (window[MANUAL_CREATED_FLAG]) { // allow safe created manually
return
}
dialog.showMessageBox({
type: "warning",
title: "提示",
message: "新开窗口必须使用内置openWindow接口",
})
try {
window.destroy()
} catch (e) {
console.error(e)
}
}, 100)
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow()
}
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})