@@ -52,8 +52,6 @@ interface SquirrelUpdate {
52
52
53
53
const SSO_ID_KEY = "element-desktop-ssoid" ;
54
54
55
- const isMac = navigator . platform . toUpperCase ( ) . includes ( "MAC" ) ;
56
-
57
55
function platformFriendlyName ( ) : string {
58
56
// used to use window.process but the same info is available here
59
57
if ( navigator . userAgent . includes ( "Macintosh" ) ) {
@@ -73,13 +71,6 @@ function platformFriendlyName(): string {
73
71
}
74
72
}
75
73
76
- function onAction ( payload : ActionPayload ) : void {
77
- // Whitelist payload actions, no point sending most across
78
- if ( [ "call_state" ] . includes ( payload . action ) ) {
79
- window . electron ! . send ( "app_onAction" , payload ) ;
80
- }
81
- }
82
-
83
74
function getUpdateCheckStatus ( status : boolean | string ) : UpdateStatus {
84
75
if ( status === true ) {
85
76
return { status : UpdateCheckStatus . Downloading } ;
@@ -97,25 +88,27 @@ export default class ElectronPlatform extends BasePlatform {
97
88
private readonly ipc = new IPCManager ( "ipcCall" , "ipcReply" ) ;
98
89
private readonly eventIndexManager : BaseEventIndexManager = new SeshatIndexManager ( ) ;
99
90
private readonly initialised : Promise < void > ;
91
+ private readonly electron : Electron ;
100
92
private protocol ! : string ;
101
93
private sessionId ! : string ;
102
94
private config ! : IConfigOptions ;
95
+ private supportedSettings ?: Record < string , boolean > ;
103
96
104
97
public constructor ( ) {
105
98
super ( ) ;
106
99
107
100
if ( ! window . electron ) {
108
101
throw new Error ( "Cannot instantiate ElectronPlatform, window.electron is not set" ) ;
109
102
}
103
+ this . electron = window . electron ;
110
104
111
- dis . register ( onAction ) ;
112
105
/*
113
106
IPC Call `check_updates` returns:
114
107
true if there is an update available
115
108
false if there is not
116
109
or the error if one is encountered
117
110
*/
118
- window . electron . on ( "check_updates" , ( event , status ) => {
111
+ this . electron . on ( "check_updates" , ( event , status ) => {
119
112
dis . dispatch < CheckUpdatesPayload > ( {
120
113
action : Action . CheckUpdates ,
121
114
...getUpdateCheckStatus ( status ) ,
@@ -124,44 +117,44 @@ export default class ElectronPlatform extends BasePlatform {
124
117
125
118
// `userAccessToken` (IPC) is requested by the main process when appending authentication
126
119
// to media downloads. A reply is sent over the same channel.
127
- window . electron . on ( "userAccessToken" , ( ) => {
128
- window . electron ! . send ( "userAccessToken" , MatrixClientPeg . get ( ) ?. getAccessToken ( ) ) ;
120
+ this . electron . on ( "userAccessToken" , ( ) => {
121
+ this . electron . send ( "userAccessToken" , MatrixClientPeg . get ( ) ?. getAccessToken ( ) ) ;
129
122
} ) ;
130
123
131
124
// `homeserverUrl` (IPC) is requested by the main process. A reply is sent over the same channel.
132
- window . electron . on ( "homeserverUrl" , ( ) => {
133
- window . electron ! . send ( "homeserverUrl" , MatrixClientPeg . get ( ) ?. getHomeserverUrl ( ) ) ;
125
+ this . electron . on ( "homeserverUrl" , ( ) => {
126
+ this . electron . send ( "homeserverUrl" , MatrixClientPeg . get ( ) ?. getHomeserverUrl ( ) ) ;
134
127
} ) ;
135
128
136
129
// `serverSupportedVersions` is requested by the main process when it needs to know if the
137
130
// server supports a particular version. This is primarily used to detect authenticated media
138
131
// support. A reply is sent over the same channel.
139
- window . electron . on ( "serverSupportedVersions" , async ( ) => {
140
- window . electron ! . send ( "serverSupportedVersions" , await MatrixClientPeg . get ( ) ?. getVersions ( ) ) ;
132
+ this . electron . on ( "serverSupportedVersions" , async ( ) => {
133
+ this . electron . send ( "serverSupportedVersions" , await MatrixClientPeg . get ( ) ?. getVersions ( ) ) ;
141
134
} ) ;
142
135
143
136
// try to flush the rageshake logs to indexeddb before quit.
144
- window . electron . on ( "before-quit" , function ( ) {
137
+ this . electron . on ( "before-quit" , function ( ) {
145
138
logger . log ( "element-desktop closing" ) ;
146
139
rageshake . flush ( ) ;
147
140
} ) ;
148
141
149
- window . electron . on ( "update-downloaded" , this . onUpdateDownloaded ) ;
142
+ this . electron . on ( "update-downloaded" , this . onUpdateDownloaded ) ;
150
143
151
- window . electron . on ( "preferences" , ( ) => {
144
+ this . electron . on ( "preferences" , ( ) => {
152
145
dis . fire ( Action . ViewUserSettings ) ;
153
146
} ) ;
154
147
155
- window . electron . on ( "userDownloadCompleted" , ( ev , { id, name } ) => {
148
+ this . electron . on ( "userDownloadCompleted" , ( ev , { id, name } ) => {
156
149
const key = `DOWNLOAD_TOAST_${ id } ` ;
157
150
158
151
const onAccept = ( ) : void => {
159
- window . electron ! . send ( "userDownloadAction" , { id, open : true } ) ;
152
+ this . electron . send ( "userDownloadAction" , { id, open : true } ) ;
160
153
ToastStore . sharedInstance ( ) . dismissToast ( key ) ;
161
154
} ;
162
155
163
156
const onDismiss = ( ) : void => {
164
- window . electron ! . send ( "userDownloadAction" , { id } ) ;
157
+ this . electron . send ( "userDownloadAction" , { id } ) ;
165
158
} ;
166
159
167
160
ToastStore . sharedInstance ( ) . addOrReplaceToast ( {
@@ -180,7 +173,7 @@ export default class ElectronPlatform extends BasePlatform {
180
173
} ) ;
181
174
} ) ;
182
175
183
- window . electron . on ( "openDesktopCapturerSourcePicker" , async ( ) => {
176
+ this . electron . on ( "openDesktopCapturerSourcePicker" , async ( ) => {
184
177
const { finished } = Modal . createDialog ( DesktopCapturerSourcePicker ) ;
185
178
const [ source ] = await finished ;
186
179
// getDisplayMedia promise does not return if no dummy is passed here as source
@@ -192,11 +185,20 @@ export default class ElectronPlatform extends BasePlatform {
192
185
this . initialised = this . initialise ( ) ;
193
186
}
194
187
188
+ protected onAction ( payload : ActionPayload ) : void {
189
+ super . onAction ( payload ) ;
190
+ // Whitelist payload actions, no point sending most across
191
+ if ( [ "call_state" ] . includes ( payload . action ) ) {
192
+ this . electron . send ( "app_onAction" , payload ) ;
193
+ }
194
+ }
195
+
195
196
private async initialise ( ) : Promise < void > {
196
- const { protocol, sessionId, config } = await window . electron ! . initialise ( ) ;
197
+ const { protocol, sessionId, config, supportedSettings } = await this . electron . initialise ( ) ;
197
198
this . protocol = protocol ;
198
199
this . sessionId = sessionId ;
199
200
this . config = config ;
201
+ this . supportedSettings = supportedSettings ;
200
202
}
201
203
202
204
public async getConfig ( ) : Promise < IConfigOptions | undefined > {
@@ -248,7 +250,7 @@ export default class ElectronPlatform extends BasePlatform {
248
250
if ( this . notificationCount === count ) return ;
249
251
super . setNotificationCount ( count ) ;
250
252
251
- window . electron ! . send ( "setBadgeCount" , count ) ;
253
+ this . electron . send ( "setBadgeCount" , count ) ;
252
254
}
253
255
254
256
public supportsNotifications ( ) : boolean {
@@ -288,7 +290,7 @@ export default class ElectronPlatform extends BasePlatform {
288
290
}
289
291
290
292
public loudNotification ( ev : MatrixEvent , room : Room ) : void {
291
- window . electron ! . send ( "loudNotification" ) ;
293
+ this . electron . send ( "loudNotification" ) ;
292
294
}
293
295
294
296
public needsUrlTooltips ( ) : boolean {
@@ -300,21 +302,16 @@ export default class ElectronPlatform extends BasePlatform {
300
302
}
301
303
302
304
public supportsSetting ( settingName ?: string ) : boolean {
303
- switch ( settingName ) {
304
- case "Electron.showTrayIcon" : // Things other than Mac support tray icons
305
- case "Electron.alwaysShowMenuBar" : // This isn't relevant on Mac as Menu bars don't live in the app window
306
- return ! isMac ;
307
- default :
308
- return true ;
309
- }
305
+ if ( settingName === undefined ) return true ;
306
+ return this . supportedSettings ?. [ settingName ] === true ;
310
307
}
311
308
312
309
public getSettingValue ( settingName : string ) : Promise < any > {
313
- return this . ipc . call ( " getSettingValue" , settingName ) ;
310
+ return this . electron . getSettingValue ( settingName ) ;
314
311
}
315
312
316
313
public setSettingValue ( settingName : string , value : any ) : Promise < void > {
317
- return this . ipc . call ( " setSettingValue" , settingName , value ) ;
314
+ return this . electron . setSettingValue ( settingName , value ) ;
318
315
}
319
316
320
317
public async canSelfUpdate ( ) : Promise < boolean > {
@@ -324,14 +321,14 @@ export default class ElectronPlatform extends BasePlatform {
324
321
325
322
public startUpdateCheck ( ) : void {
326
323
super . startUpdateCheck ( ) ;
327
- window . electron ! . send ( "check_updates" ) ;
324
+ this . electron . send ( "check_updates" ) ;
328
325
}
329
326
330
327
public installUpdate ( ) : void {
331
328
// IPC to the main process to install the update, since quitAndInstall
332
329
// doesn't fire the before-quit event so the main process needs to know
333
330
// it should exit.
334
- window . electron ! . send ( "install_update" ) ;
331
+ this . electron . send ( "install_update" ) ;
335
332
}
336
333
337
334
public getDefaultDeviceDisplayName ( ) : string {
0 commit comments