diff --git a/main.js b/main.js index f2103ce..efd442c 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow } = require('electron') +const { app, BrowserWindow, globalShortcut } = require('electron') if (process.env.ELECTRON_IGNORE_CERT_ERRORS === '1') { app.commandLine.appendSwitch('ignore-certificate-errors') @@ -6,7 +6,7 @@ if (process.env.ELECTRON_IGNORE_CERT_ERRORS === '1') { function createWindow() { const win = new BrowserWindow({ - fullscreen: false, + fullscreen: true, autoHideMenuBar: true, webPreferences: { contextIsolation: true, @@ -14,12 +14,23 @@ function createWindow() { sandbox: true } }) - const targetUrl = process.env.APP_URL || 'https://www.baidu.com' + const targetUrl = process.env.APP_URL || 'http://localhost:8000' win.loadURL(targetUrl) } app.whenReady().then(() => { createWindow() + globalShortcut.register('F11', () => { + const w = BrowserWindow.getFocusedWindow() + if (w) w.setFullScreen(!w.isFullScreen()) + }) + globalShortcut.register('Escape', () => { + const w = BrowserWindow.getFocusedWindow() + if (w) w.setFullScreen(false) + }) + globalShortcut.register('CommandOrControl+Q', () => { + app.quit() + }) app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) @@ -27,4 +38,8 @@ app.whenReady().then(() => { app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit() +}) + +app.on('will-quit', () => { + globalShortcut.unregisterAll() }) \ No newline at end of file