@@ -52,8 +52,6 @@ interface SquirrelUpdate {
5252
5353const SSO_ID_KEY = "element-desktop-ssoid" ;
5454
55- const isMac = navigator . platform . toUpperCase ( ) . includes ( "MAC" ) ;
56-
5755function platformFriendlyName ( ) : string {
5856 // used to use window.process but the same info is available here
5957 if ( navigator . userAgent . includes ( "Macintosh" ) ) {
@@ -73,13 +71,6 @@ function platformFriendlyName(): string {
7371 }
7472}
7573
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-
8374function getUpdateCheckStatus ( status : boolean | string ) : UpdateStatus {
8475 if ( status === true ) {
8576 return { status : UpdateCheckStatus . Downloading } ;
@@ -97,25 +88,27 @@ export default class ElectronPlatform extends BasePlatform {
9788 private readonly ipc = new IPCManager ( "ipcCall" , "ipcReply" ) ;
9889 private readonly eventIndexManager : BaseEventIndexManager = new SeshatIndexManager ( ) ;
9990 private readonly initialised : Promise < void > ;
91+ private readonly electron : Electron ;
10092 private protocol ! : string ;
10193 private sessionId ! : string ;
10294 private config ! : IConfigOptions ;
95+ private supportedSettings ?: Record < string , boolean > ;
10396
10497 public constructor ( ) {
10598 super ( ) ;
10699
107100 if ( ! window . electron ) {
108101 throw new Error ( "Cannot instantiate ElectronPlatform, window.electron is not set" ) ;
109102 }
103+ this . electron = window . electron ;
110104
111- dis . register ( onAction ) ;
112105 /*
113106 IPC Call `check_updates` returns:
114107 true if there is an update available
115108 false if there is not
116109 or the error if one is encountered
117110 */
118- window . electron . on ( "check_updates" , ( event , status ) => {
111+ this . electron . on ( "check_updates" , ( event , status ) => {
119112 dis . dispatch < CheckUpdatesPayload > ( {
120113 action : Action . CheckUpdates ,
121114 ...getUpdateCheckStatus ( status ) ,
@@ -124,44 +117,44 @@ export default class ElectronPlatform extends BasePlatform {
124117
125118 // `userAccessToken` (IPC) is requested by the main process when appending authentication
126119 // 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 ( ) ) ;
129122 } ) ;
130123
131124 // `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 ( ) ) ;
134127 } ) ;
135128
136129 // `serverSupportedVersions` is requested by the main process when it needs to know if the
137130 // server supports a particular version. This is primarily used to detect authenticated media
138131 // 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 ( ) ) ;
141134 } ) ;
142135
143136 // try to flush the rageshake logs to indexeddb before quit.
144- window . electron . on ( "before-quit" , function ( ) {
137+ this . electron . on ( "before-quit" , function ( ) {
145138 logger . log ( "element-desktop closing" ) ;
146139 rageshake . flush ( ) ;
147140 } ) ;
148141
149- window . electron . on ( "update-downloaded" , this . onUpdateDownloaded ) ;
142+ this . electron . on ( "update-downloaded" , this . onUpdateDownloaded ) ;
150143
151- window . electron . on ( "preferences" , ( ) => {
144+ this . electron . on ( "preferences" , ( ) => {
152145 dis . fire ( Action . ViewUserSettings ) ;
153146 } ) ;
154147
155- window . electron . on ( "userDownloadCompleted" , ( ev , { id, name } ) => {
148+ this . electron . on ( "userDownloadCompleted" , ( ev , { id, name } ) => {
156149 const key = `DOWNLOAD_TOAST_${ id } ` ;
157150
158151 const onAccept = ( ) : void => {
159- window . electron ! . send ( "userDownloadAction" , { id, open : true } ) ;
152+ this . electron . send ( "userDownloadAction" , { id, open : true } ) ;
160153 ToastStore . sharedInstance ( ) . dismissToast ( key ) ;
161154 } ;
162155
163156 const onDismiss = ( ) : void => {
164- window . electron ! . send ( "userDownloadAction" , { id } ) ;
157+ this . electron . send ( "userDownloadAction" , { id } ) ;
165158 } ;
166159
167160 ToastStore . sharedInstance ( ) . addOrReplaceToast ( {
@@ -180,7 +173,7 @@ export default class ElectronPlatform extends BasePlatform {
180173 } ) ;
181174 } ) ;
182175
183- window . electron . on ( "openDesktopCapturerSourcePicker" , async ( ) => {
176+ this . electron . on ( "openDesktopCapturerSourcePicker" , async ( ) => {
184177 const { finished } = Modal . createDialog ( DesktopCapturerSourcePicker ) ;
185178 const [ source ] = await finished ;
186179 // getDisplayMedia promise does not return if no dummy is passed here as source
@@ -192,11 +185,20 @@ export default class ElectronPlatform extends BasePlatform {
192185 this . initialised = this . initialise ( ) ;
193186 }
194187
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+
195196 private async initialise ( ) : Promise < void > {
196- const { protocol, sessionId, config } = await window . electron ! . initialise ( ) ;
197+ const { protocol, sessionId, config, supportedSettings } = await this . electron . initialise ( ) ;
197198 this . protocol = protocol ;
198199 this . sessionId = sessionId ;
199200 this . config = config ;
201+ this . supportedSettings = supportedSettings ;
200202 }
201203
202204 public async getConfig ( ) : Promise < IConfigOptions | undefined > {
@@ -248,7 +250,7 @@ export default class ElectronPlatform extends BasePlatform {
248250 if ( this . notificationCount === count ) return ;
249251 super . setNotificationCount ( count ) ;
250252
251- window . electron ! . send ( "setBadgeCount" , count ) ;
253+ this . electron . send ( "setBadgeCount" , count ) ;
252254 }
253255
254256 public supportsNotifications ( ) : boolean {
@@ -288,7 +290,7 @@ export default class ElectronPlatform extends BasePlatform {
288290 }
289291
290292 public loudNotification ( ev : MatrixEvent , room : Room ) : void {
291- window . electron ! . send ( "loudNotification" ) ;
293+ this . electron . send ( "loudNotification" ) ;
292294 }
293295
294296 public needsUrlTooltips ( ) : boolean {
@@ -300,21 +302,16 @@ export default class ElectronPlatform extends BasePlatform {
300302 }
301303
302304 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 ;
310307 }
311308
312309 public getSettingValue ( settingName : string ) : Promise < any > {
313- return this . ipc . call ( " getSettingValue" , settingName ) ;
310+ return this . electron . getSettingValue ( settingName ) ;
314311 }
315312
316313 public setSettingValue ( settingName : string , value : any ) : Promise < void > {
317- return this . ipc . call ( " setSettingValue" , settingName , value ) ;
314+ return this . electron . setSettingValue ( settingName , value ) ;
318315 }
319316
320317 public async canSelfUpdate ( ) : Promise < boolean > {
@@ -324,14 +321,14 @@ export default class ElectronPlatform extends BasePlatform {
324321
325322 public startUpdateCheck ( ) : void {
326323 super . startUpdateCheck ( ) ;
327- window . electron ! . send ( "check_updates" ) ;
324+ this . electron . send ( "check_updates" ) ;
328325 }
329326
330327 public installUpdate ( ) : void {
331328 // IPC to the main process to install the update, since quitAndInstall
332329 // doesn't fire the before-quit event so the main process needs to know
333330 // it should exit.
334- window . electron ! . send ( "install_update" ) ;
331+ this . electron . send ( "install_update" ) ;
335332 }
336333
337334 public getDefaultDeviceDisplayName ( ) : string {
0 commit comments