1
1
const electron = require ( 'electron' ) ;
2
2
const app = electron . app ;
3
3
const Menu = electron . Menu ;
4
+ const Tray = electron . Tray ;
4
5
const menuTemplate = require ( './menutemplate' ) ;
5
6
const BrowserWindow = electron . BrowserWindow ;
6
7
const path = require ( 'path' ) ;
7
8
const url = require ( 'url' ) ;
8
9
const instagram = require ( './instagram' ) ;
9
10
const autoUpdater = require ( './autoupdater' ) ;
10
11
11
- // fixes electron's timeout inconsistency
12
- // not doing this on windows because the fix doesn't work for windows.
12
+ // on windows it is recommended to use ICO icons to get best visual effects
13
+ let trayImage = 'icon.ico' ;
14
+
13
15
if ( process . platform != 'win32' ) {
16
+ // fixes electron's timeout inconsistency
17
+ // not doing this on windows because the fix doesn't work for windows.
14
18
require ( './timeout-shim' ) . fix ( ) ;
19
+ trayImage = 'background.png' ;
15
20
}
16
21
22
+
17
23
const RATE_LIMIT_DELAY = 60000 ;
18
24
let pollingInterval = 10000 ;
19
25
@@ -45,7 +51,17 @@ function createWindow () {
45
51
} ) )
46
52
} )
47
53
48
- mainWindow . on ( 'closed' , ( ) => mainWindow = null )
54
+ mainWindow . on ( 'close' , function ( event ) {
55
+ if ( ! app . isQuiting ) {
56
+ event . preventDefault ( ) ;
57
+ mainWindow . hide ( ) ;
58
+ }
59
+ } )
60
+
61
+ mainWindow . on ( 'minimize' , function ( event ) {
62
+ event . preventDefault ( ) ;
63
+ mainWindow . hide ( ) ;
64
+ } )
49
65
}
50
66
51
67
function createCheckpointWindow ( ) {
@@ -71,14 +87,40 @@ function getChatList () {
71
87
}
72
88
instagram . getChatList ( session ) . then ( ( chats ) => {
73
89
mainWindow . webContents . send ( 'chatList' , chats )
74
-
90
+
75
91
if ( chatListTimeoutObj ) {
76
92
clearTimeout ( chatListTimeoutObj )
77
93
}
78
94
chatListTimeoutObj = setTimeout ( getChatList , pollingInterval ) ;
79
95
} ) . catch ( ( ) => setTimeout ( getChatList , RATE_LIMIT_DELAY ) )
80
96
}
81
97
98
+ function createTray ( ) {
99
+ tray = new Tray ( '//' ) ; //TODO replace insert path to image
100
+ tray . on ( 'click' , ( event , bounds , position ) => {
101
+ mainWindow . show ( ) ;
102
+ } ) ;
103
+ const contextMenu = Menu . buildFromTemplate ( [
104
+ { label : 'Show App' , click : function ( ) {
105
+ mainWindow . show ( ) ;
106
+ } } ,
107
+ { label : 'Light Icon' , type : 'checkbox' , checked : false , click : function ( item ) {
108
+ if ( item . checked ) {
109
+ trayImage = 'l_' + trayImage ;
110
+ } else {
111
+ trayImage = trayImage . substring ( 2 ) ;
112
+ }
113
+ tray . setImage ( '//' ) ; //TODO insert path to image
114
+ } } ,
115
+ { label : 'Quit' , click : function ( ) {
116
+ app . isQuiting = true ;
117
+ app . quit ( ) ;
118
+ } }
119
+ ] ) ;
120
+
121
+ tray . setContextMenu ( contextMenu ) ;
122
+ }
123
+
82
124
let chatTimeoutObj ;
83
125
let messagesThread ;
84
126
function getChat ( evt , id ) {
@@ -118,11 +160,12 @@ app.setAppUserModelId('com.ifedapoolarewaju.desktop.igdm')
118
160
119
161
app . on ( 'ready' , ( ) => {
120
162
createWindow ( ) ;
163
+ createTray ( ) ;
121
164
// only set the menu template when in production mode/
122
165
// this also leaves the dev console enabled when in dev mode.
123
166
if ( ! process . defaultApp ) {
124
167
const menu = Menu . buildFromTemplate ( menuTemplate ) ;
125
- Menu . setApplicationMenu ( menu ) ;
168
+ Menu . setApplicationMenu ( menu ) ;
126
169
}
127
170
autoUpdater . init ( ) ;
128
171
} )
0 commit comments