diff options
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/index.js b/src/index.js index 3244c44ad..9ca059f48 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -2,21 +2,22 @@ import { app, BrowserWindow, shell } from 'electron'; | |||
2 | import fs from 'fs-extra'; | 2 | import fs from 'fs-extra'; |
3 | import path from 'path'; | 3 | import path from 'path'; |
4 | 4 | ||
5 | // eslint-disable-next-line | 5 | /* eslint-disable */ |
6 | if (require('electron-squirrel-startup')) app.quit(); | 6 | if (require('electron-squirrel-startup')) app.quit(); |
7 | 7 | ||
8 | import windowStateKeeper from 'electron-window-state'; // eslint-disable-line | 8 | import windowStateKeeper from 'electron-window-state'; |
9 | 9 | ||
10 | import { isDevMode, isWindows } from './environment'; // eslint-disable-line | 10 | import { isDevMode, isWindows } from './environment'; |
11 | import ipcApi from './electron/ipc-api'; // eslint-disable-line | 11 | import ipcApi from './electron/ipc-api'; |
12 | import Settings from './electron/Settings'; // eslint-disable-line | 12 | import Tray from './lib/Tray'; |
13 | import { appId } from './package.json'; // eslint-disable-line | 13 | import Settings from './electron/Settings'; |
14 | import './electron/exception'; // eslint-disable-line | 14 | import { appId } from './package.json'; |
15 | import './electron/exception'; | ||
16 | /* eslint-enable */ | ||
15 | 17 | ||
16 | // Keep a global reference of the window object, if you don't, the window will | 18 | // Keep a global reference of the window object, if you don't, the window will |
17 | // be closed automatically when the JavaScript object is garbage collected. | 19 | // be closed automatically when the JavaScript object is garbage collected. |
18 | let mainWindow; | 20 | let mainWindow; |
19 | const settings = new Settings(); | ||
20 | let willQuitApp = false; | 21 | let willQuitApp = false; |
21 | 22 | ||
22 | // Ensure that the recipe directory exists | 23 | // Ensure that the recipe directory exists |
@@ -27,6 +28,23 @@ if (isWindows) { | |||
27 | app.setAppUserModelId(appId); | 28 | app.setAppUserModelId(appId); |
28 | } | 29 | } |
29 | 30 | ||
31 | // Force single window | ||
32 | if (process.platform !== 'darwin') { | ||
33 | const isSecondInstance = app.makeSingleInstance(() => { | ||
34 | if (mainWindow) { | ||
35 | if (mainWindow.isMinimized()) mainWindow.restore(); | ||
36 | mainWindow.focus(); | ||
37 | } | ||
38 | }); | ||
39 | |||
40 | if (isSecondInstance) { | ||
41 | app.quit(); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | // Initialize Settings | ||
46 | const settings = new Settings(); | ||
47 | |||
30 | const createWindow = async () => { | 48 | const createWindow = async () => { |
31 | // Remember window size | 49 | // Remember window size |
32 | const mainWindowState = windowStateKeeper({ | 50 | const mainWindowState = windowStateKeeper({ |
@@ -47,8 +65,11 @@ const createWindow = async () => { | |||
47 | autoHideMenuBar: true, | 65 | autoHideMenuBar: true, |
48 | }); | 66 | }); |
49 | 67 | ||
68 | // Initialize System Tray | ||
69 | const trayIcon = new Tray(mainWindow); | ||
70 | |||
50 | // Initialize ipcApi | 71 | // Initialize ipcApi |
51 | ipcApi({ mainWindow, settings }); | 72 | ipcApi({ mainWindow, settings, trayIcon }); |
52 | 73 | ||
53 | // Manage Window State | 74 | // Manage Window State |
54 | mainWindowState.manage(mainWindow); | 75 | mainWindowState.manage(mainWindow); |
@@ -85,6 +106,7 @@ const createWindow = async () => { | |||
85 | 106 | ||
86 | if (settings.get('minimizeToSystemTray')) { | 107 | if (settings.get('minimizeToSystemTray')) { |
87 | mainWindow.setSkipTaskbar(true); | 108 | mainWindow.setSkipTaskbar(true); |
109 | trayIcon.show(); | ||
88 | } | 110 | } |
89 | }); | 111 | }); |
90 | 112 | ||
@@ -102,6 +124,10 @@ const createWindow = async () => { | |||
102 | if (app.wasMaximized) { | 124 | if (app.wasMaximized) { |
103 | mainWindow.maximize(); | 125 | mainWindow.maximize(); |
104 | } | 126 | } |
127 | |||
128 | if (!settings.get('enableSystemTray')) { | ||
129 | trayIcon.hide(); | ||
130 | } | ||
105 | }); | 131 | }); |
106 | 132 | ||
107 | mainWindow.on('show', () => { | 133 | mainWindow.on('show', () => { |