|
| 1 | +const electron = require('electron') |
| 2 | +// Module to control application life. |
| 3 | +const app = electron.app |
| 4 | +// Module to create native browser window. |
| 5 | +const BrowserWindow = electron.BrowserWindow |
| 6 | + |
| 7 | +const path = require('path') |
| 8 | +const url = require('url') |
| 9 | +const sonos = require('./src/sonos/server.js') |
| 10 | + |
| 11 | +// Keep a global reference of the window object, if you don't, the window will |
| 12 | +// be closed automatically when the JavaScript object is garbage collected. |
| 13 | +let mainWindow |
| 14 | + |
| 15 | +function createWindow () { |
| 16 | + // Create the browser window. |
| 17 | + mainWindow = new BrowserWindow({width: 800, height: 600}) |
| 18 | + |
| 19 | + // and load the index.html of the app. |
| 20 | + mainWindow.loadURL(url.format({ |
| 21 | + pathname: path.join(__dirname, './src/index.html'), |
| 22 | + protocol: 'file:', |
| 23 | + slashes: true |
| 24 | + })) |
| 25 | + |
| 26 | + // Open the DevTools. |
| 27 | + mainWindow.webContents.openDevTools() |
| 28 | + |
| 29 | + // Emitted when the window is closed. |
| 30 | + mainWindow.on('closed', function () { |
| 31 | + // Dereference the window object, usually you would store windows |
| 32 | + // in an array if your app supports multi windows, this is the time |
| 33 | + // when you should delete the corresponding element. |
| 34 | + mainWindow = null |
| 35 | + }) |
| 36 | + |
| 37 | + sonos; |
| 38 | +} |
| 39 | + |
| 40 | +// This method will be called when Electron has finished |
| 41 | +// initialization and is ready to create browser windows. |
| 42 | +// Some APIs can only be used after this event occurs. |
| 43 | +app.on('ready', createWindow) |
| 44 | + |
| 45 | +// Quit when all windows are closed. |
| 46 | +app.on('window-all-closed', function () { |
| 47 | + // On OS X it is common for applications and their menu bar |
| 48 | + // to stay active until the user quits explicitly with Cmd + Q |
| 49 | + if (process.platform !== 'darwin') { |
| 50 | + app.quit() |
| 51 | + } |
| 52 | +}) |
| 53 | + |
| 54 | +app.on('activate', function () { |
| 55 | + // On OS X it's common to re-create a window in the app when the |
| 56 | + // dock icon is clicked and there are no other windows open. |
| 57 | + if (mainWindow === null) { |
| 58 | + createWindow() |
| 59 | + } |
| 60 | +}) |
| 61 | + |
| 62 | +// In this file you can include the rest of your app's specific main process |
| 63 | +// code. You can also put them in separate files and require them here. |
0 commit comments