diff --git a/main.js b/main.js index 5dc65f26e050753514c91693e1c08a4ce6c4d2dd..528b6c2f11b5860ceb7a52d0e9874e053f7b5084 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,11 @@ var client; /* Sub process for the express server */ var loopIntervals = []; var loopTimeouts = []; +function clearTimers() { + loopIntervals.forEach(timer => clearInterval(timer)); + loopTimeouts.forEach(timer => clearTimeout(timer)); +} + class Lektor { constructor() { this.closed = true; @@ -79,71 +84,70 @@ tail.on('line', function (data) { * Creates the main window and process for the admin interface * ***************************************************************/ -function createInstanceWindow() { - /* Main window */ - win = new BrowserWindow({ - width: 1280, - height: 720, - minWidth: 1000, - minHeight: 360, +function defaultWindowOptions(title) { + return { + title: title, + width: 720, + height: 360, hasShadow: false, - frame: false, + frame: true, menuBarVisible: true, webPreferences: { nodeIntegration: true, worldSafeExecuteJavaScript: true, - contextIsolation: false /* XXX: Otherwise 'require' is not defined in instance/index.html */, + contextIsolation: true, }, - }); + }; +} + +function createInstanceWindow() { + /* Main window */ + const opt = defaultWindowOptions('Amadeus'); + opt.width = 1280; + opt.height = 720; + opt.minWidth = 1000; + opt.minHeight = 360; + opt.menuBarVisible = false; + opt.frame = false; + opt.webPreferences.contextIsolation = false; /* XXX: Otherwise 'require' is not defined in instance/index.html */ + win = new BrowserWindow(opt); win.loadURL(`file://${__dirname}/instance/index.ejs`); + win.once('ready-to-show', () => win.show()); +} + +function createLogWindow() { + /* Log window */ + const opt = defaultWindowOptions('Amadeus - Log window'); + opt.parent = win; + opt.webPreferences.contextIsolation = false; /* XXX: Otherwise 'require' is not defined in instance/index.html */ + const logwindow = new BrowserWindow(opt); + logwindow.loadURL(`file://${__dirname}/instance/log.ejs`); + logwindow.once('ready-to-show', () => logwindow.show()); } function createUserViewWindow() { /* User view window */ - const uv = new BrowserWindow({ - width: 720, - title: 'Kurisu', - height: 360, - frame: false, - parent: win, - webPreferences: { - nodeIntegration: true, - worldSafeExecuteJavaScript: true, - contextIsolation: true, - }, - }); + const opt = defaultWindowOptions('Amadeus - User view'); + const uv = new BrowserWindow(opt); uv.loadURL(`http://localhost:${config.content.client.port}/`); - uv.once('ready-to-show', () => { - uv.show(); - }); + uv.once('ready-to-show', () => uv.show()); } function createKurisuWindow() { /* Kurisu window */ - const kurisu = new BrowserWindow({ - width: 1280, - title: 'Kurisu', - height: 720, - frame: false, - parent: win, - webPreferences: { - nodeIntegration: true, - worldSafeExecuteJavaScript: true, - contextIsolation: true, - }, - }); + const opt = defaultWindowOptions('Amadeus - Kurisu'); + const kurisu = new BrowserWindow(opt); kurisu.loadURL(config.content.kurisu.url); - kurisu.once('ready-to-show', () => { - kurisu.show(); - }); + kurisu.once('ready-to-show', () => kurisu.show()); } /****************************** * The end of the application * ******************************/ -ipcMain.on('close-app', (evt, arg) => { +ipcMain.on('close-app', () => { app.quit(); + clearTimers(); }); app.on('quit', () => { @@ -291,8 +295,7 @@ ipcMain.on('verify-lektord', (event, arg) => { /* Install the clear function before registering all timers */ win.on('close', () => { logger.info('main', 'Close instance window, '); - loopIntervals.forEach(timer => clearInterval(timer)); - loopTimeouts.forEach(timer => clearTimeout(timer)); + clearTimers(); }); lkt.reloadState();