diff --git a/Makefile b/Makefile index e2ee693ed83ea3eaba85fc86bb9f39cec2cbf59c..ba84005da40704b16d35b6a5a9b2da23ad25192b 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,6 @@ debug: $(YARN) test --no-sandbox style: - $(YARN) prettier --write instance common style client test >/dev/null + $(YARN) prettier --write instance common style client test main.js >/dev/null .PHONY: test debug run prepare style diff --git a/instance/main.js b/instance/main.js index 8b0dc0ea7d990fe7691238add7558355a53b86b0..3068e65d58069fbc3078db2e989dbbad9196568a 100644 --- a/instance/main.js +++ b/instance/main.js @@ -221,7 +221,8 @@ ipcRenderer.on('send-song-time-data', (event, timeData) => { } document.getElementsByClassName('karaQueue')[timeData.song].style.background = '#6b7d8e'; } else { - document.getElementsByClassName('karaQueue')[timeData.song].style.background = '#4e5d6c'; + if (document.getElementsByClassName('karaQueue')[timeData.song]) + document.getElementsByClassName('karaQueue')[timeData.song].style.background = '#4e5d6c'; } }); diff --git a/main.js b/main.js index 68b997f9a5c77aea2ccbfce9b74c74e2b0cd6aed..f43be823ab90471122e6eb5bf3393eeae7824583 100644 --- a/main.js +++ b/main.js @@ -10,8 +10,33 @@ var db = require.main.require('./common/db.js'); var tail = require('tail').Tail; var client; /* Sub process for the express server */ -var lektor; /* Sub process, the lektord player */ -var lektor_closed = false; /* Is lektord closed? */ + +class Lektor { + constructor() { + this.closed = false; + this.process = spawn('lektord', ['-F']); + + this.process.stderr.on('data', data => { + logger.lektord(data); + }); + + this.process.on('close', code => { + logger.warn('main', `Lektor exited with code ${code}`); + this.lektor_closed = true; + app.quit(); + }); + } + + exit() { + if (this.closed) { + logger.warning('main', 'Lektord is already closed'); + return; + } + logger.info('main', 'Closing lektord'); + this.closed = true; + this.process.kill('SIGTERM'); + } +} /* The last thing we got from the search bar */ var __lastFilter = ''; @@ -42,6 +67,8 @@ function createInstanceWindow() { menuBarVisible: true, webPreferences: { nodeIntegration: true, + worldSafeExecuteJavaScript: true, + contextIsolation: false /* XXX: Otherwise 'require' is not defined in instance/index.html */, }, }); win.loadFile('instance/index.html'); @@ -57,6 +84,8 @@ function createKurisuWindow() { parent: win, webPreferences: { nodeIntegration: true, + worldSafeExecuteJavaScript: true, + contextIsolation: true, }, }); kurisu.loadURL('https://kurisu.iiens.net'); @@ -74,14 +103,9 @@ ipcMain.on('close-app', (evt, arg) => { }); app.on('quit', () => { - logger.info( - 'main', - 'Send SIGTERM to express process, lektord and tailler process' - ); + logger.info('main', 'Send SIGTERM to express process, lektord and tailler process'); client.kill('SIGTERM'); - if (!lektor_closed) { - lektor.kill('SIGTERM'); - } + lektor.exit(); }); /********************************* @@ -92,7 +116,7 @@ app.on('ready', () => { logger.info('main', 'Main window is ready'); createInstanceWindow(); client = fork('client/main.js'); - lektor = spawn('lektord', ['-F']); + lektor = new Lektor(); globalShortcut.register('CommandOrControl+D', () => { var win = BrowserWindow.getFocusedWindow(); @@ -112,20 +136,12 @@ app.on('ready', () => { } }); - lektor.stderr.on('data', data => { - logger.lektord(data); - }); setTimeout(() => { lkt.idleActualisation(); }, 1000); setTimeout(() => { lkt.statusActualisation(); }, 1500); - lektor.on('close', code => { - logger.warn('main', `Lektor exited with code ${code}`); - lektor_closed = true; - app.quit(); - }); }); /*************** @@ -214,19 +230,14 @@ ipcMain.on('delete-kara-queue-pos', (event, arg) => { }); ipcMain.on('add-kara-queue-pos', (event, addparams) => { - lkt.commandQueueAddId(addparams.id).then(() => - lkt.commandMove(addparams.queueSize + 1, addparams.position) - ); + lkt.commandQueueAddId(addparams.id).then(() => lkt.commandMove(addparams.queueSize + 1, addparams.position)); }); var songTimeData = { elapsed: 0, total: 100, state: 'stop', song: '0' }; var counterTime = 0; ipcMain.on('get-song-time-data', (event, arg) => { var newSongTimeData = lkt.getSongTimeData(); - if ( - newSongTimeData.elapsed != songTimeData.elapsed || - newSongTimeData.song != songTimeData.song - ) { + if (newSongTimeData.elapsed != songTimeData.elapsed || newSongTimeData.song != songTimeData.song) { songTimeData = newSongTimeData; event.reply('send-song-time-data', { elapsed: songTimeData.elapsed, diff --git a/package.json b/package.json index f7df599600f8c3892a9176445b3a595bc4eba510..efe7462553b27196331760e70df2cffe38de8cb9 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ ], "license": "ISC", "scripts": { - "start": "electron .", - "test": "ELECTRON_ENABLE_LOGGING=0 ELECTRON_NO_ATTACH_CONSOLE=true electron --trace-uncaught ." + "start": "ELECTRON_ENABLE_LOGGING=0 ELECTRON_NO_ATTACH_CONSOLE=true electron --trace-uncaught ." }, "dependencies": { "ejs": "^3.1.5",