@@ -9,6 +9,7 @@ const {fullSyncFactory} = require('@gyselroth/balloon-node-sync');
9
9
10
10
const i18n = require ( '../../lib/i18n.js' ) ;
11
11
const instance = require ( '../../lib/instance.js' ) ;
12
+ const menuFactory = require ( './menu-factory.js' ) ;
12
13
const clientConfig = require ( '../../lib/config.js' ) ;
13
14
const globalConfig = require ( '../../lib/global-config.js' ) ;
14
15
const appState = require ( '../../lib/state.js' ) ;
@@ -60,70 +61,7 @@ $(window).blur(function(){
60
61
} ) ;
61
62
62
63
function buildMenu ( ) {
63
- var label ;
64
- const { Menu, MenuItem} = remote
65
- const menu = new Menu ( )
66
-
67
- if ( showLogin === false && clientConfig . get ( 'username' ) ) {
68
- menu . append ( new MenuItem ( { label : clientConfig . get ( 'username' ) , enabled : false } ) )
69
- }
70
-
71
- if ( showLogin === true ) {
72
- label = i18n . __ ( 'tray.menu.link' ) ;
73
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
74
- ipcRenderer . send ( 'link-account' ) ;
75
- ipcRenderer . send ( 'tray-hide' ) ;
76
- } } ) )
77
- } else {
78
- label = i18n . __ ( 'tray.menu.unlink' ) ;
79
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
80
- ipcRenderer . send ( 'unlink-account' ) ;
81
- ipcRenderer . send ( 'tray-hide' ) ;
82
- } } ) )
83
- }
84
-
85
- menu . append ( new MenuItem ( { type : 'separator' , enabled : false } ) )
86
-
87
- if ( clientConfig . get ( 'loggedin' ) === true ) {
88
- if ( syncStatus === true ) {
89
- label = i18n . __ ( 'tray.menu.pauseSync' ) ;
90
- } else {
91
- label = i18n . __ ( 'tray.menu.continueSync' ) ;
92
- }
93
- menu . append ( new MenuItem ( { label : label , click :function ( ) {
94
- ipcRenderer . send ( 'sync-toggle-pause' ) ;
95
- ipcRenderer . send ( 'tray-hide' ) ;
96
- } } ) )
97
-
98
- menu . append ( new MenuItem ( { type : 'separator' , enabled : false } ) )
99
- }
100
-
101
- label = i18n . __ ( 'tray.menu.status' ) ;
102
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
103
- loadMenu ( 'status' ) ;
104
- } } ) )
105
-
106
- label = i18n . __ ( 'tray.menu.settings' ) ;
107
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
108
- loadMenu ( 'settings' ) ;
109
- } } ) )
110
-
111
- label = i18n . __ ( 'tray.menu.feedback' ) ;
112
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
113
- loadMenu ( 'feedback' ) ;
114
- } } ) )
115
-
116
- label = i18n . __ ( 'tray.menu.about' ) ;
117
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
118
- loadMenu ( 'about' ) ;
119
- } } ) )
120
-
121
- menu . append ( new MenuItem ( { type : 'separator' , enabled : false } ) )
122
-
123
- label = i18n . __ ( 'tray.menu.close' ) ;
124
- menu . append ( new MenuItem ( { label : label , click : function ( ) {
125
- ipcRenderer . send ( 'quit' ) ;
126
- } } ) )
64
+ const menu = menuFactory ( loadMenu , clientConfig , showLogin , syncStatus ) ;
127
65
128
66
menu . popup ( remote . getCurrentWindow ( ) ) ;
129
67
}
@@ -132,7 +70,9 @@ $('document').ready(function() {
132
70
$ ( 'body' ) . addClass ( process . platform ) ;
133
71
compileTemplate ( ) ;
134
72
135
- ipcRenderer . on ( 'update-window' , updateWindow ) ;
73
+ ipcRenderer . on ( 'update-window' , ( event , menu ) => {
74
+ updateWindow ( menu )
75
+ } ) ;
136
76
137
77
$ ( '#item-installupdate' ) . bind ( 'click' , function ( ) {
138
78
ipcRenderer . send ( 'tray-hide' ) ;
@@ -173,6 +113,10 @@ ipcRenderer.on('sync-paused' , function() {
173
113
syncStatus = false ;
174
114
} ) ;
175
115
116
+ ipcRenderer . on ( 'tray-load-menu' , function ( event , menu ) {
117
+ loadMenu ( menu ) ;
118
+ } ) ;
119
+
176
120
ipcRenderer . send ( 'tray-window-loaded' ) ;
177
121
ipcRenderer . on ( 'config' , function ( event , secret , secretType ) {
178
122
logger . info ( 'got config' , { category : 'tray-browser' , secretType} ) ;
@@ -209,13 +153,13 @@ function toggleInstallUpdate() {
209
153
}
210
154
}
211
155
212
- function updateWindow ( ) {
156
+ function updateWindow ( menu = 'status' ) {
213
157
logger . info ( 'updateWindow' , { category : 'tray-browser' } ) ;
214
158
215
159
//TODO pixtron - do we still need this?
216
160
$ ( '#tray-main' ) . html ( '' ) ;
217
161
toggleInstallUpdate ( ) ;
218
- loadMenu ( 'status' ) ;
162
+ loadMenu ( menu ) ;
219
163
}
220
164
221
165
function getOnLineState ( callback ) {
0 commit comments