11
11
import 'core-js/stable' ;
12
12
import 'regenerator-runtime/runtime' ;
13
13
import path from 'path' ;
14
- import { app , BrowserWindow , dialog , ipcMain , shell } from 'electron' ;
14
+ import {
15
+ app ,
16
+ BrowserWindow ,
17
+ dialog ,
18
+ ipcMain ,
19
+ nativeTheme ,
20
+ shell ,
21
+ Tray ,
22
+ } from 'electron' ;
15
23
import { autoUpdater } from 'electron-updater' ;
16
24
import log from 'electron-log' ;
17
25
import { FileFilter , IpcMainInvokeEvent } from 'electron/main' ;
@@ -29,6 +37,7 @@ export default class AppUpdater {
29
37
}
30
38
31
39
let mainWindow : BrowserWindow | null = null ;
40
+ let tray = null ;
32
41
33
42
if ( process . env . NODE_ENV === 'production' ) {
34
43
const sourceMapSupport = require ( 'source-map-support' ) ;
@@ -115,6 +124,25 @@ const createWindow = async () => {
115
124
new AppUpdater ( ) ;
116
125
} ;
117
126
127
+ const getIcon = ( ) => {
128
+ if ( process . platform === 'win32' ) return '16x16.png' ;
129
+ if ( nativeTheme . shouldUseDarkColors ) return '16x16.png' ;
130
+ return '16x16.png' ;
131
+ } ;
132
+
133
+ const createTray = async ( ) => {
134
+ tray = new Tray ( path . join ( __dirname , '../assets/icons' , getIcon ( ) ) ) ;
135
+
136
+ tray . on ( 'click' , async ( ) => {
137
+ if ( mainWindow == null ) {
138
+ await createWindow ( ) ;
139
+ }
140
+ mainWindow ?. show ( ) ;
141
+ } ) ;
142
+
143
+ tray . setToolTip ( 'PlainBelt' ) ;
144
+ } ;
145
+
118
146
/**
119
147
* Handlers events from React
120
148
*/
@@ -179,7 +207,7 @@ app.on('window-all-closed', () => {
179
207
}
180
208
} ) ;
181
209
182
- app . whenReady ( ) . then ( createWindow ) . catch ( console . log ) ;
210
+ app . whenReady ( ) . then ( createWindow ) . then ( createTray ) . catch ( console . log ) ;
183
211
184
212
app . on ( 'activate' , ( ) => {
185
213
// On macOS it's common to re-create a window in the app when the
0 commit comments