@@ -26,7 +26,7 @@ import {
2626import * as Sentry from "@sentry/electron/main" ;
2727import path , { dirname } from "node:path" ;
2828import windowStateKeeper from "electron-window-state" ;
29- import fs , { promises as afs } from "node:fs" ;
29+ import fs from "node:fs" ;
3030import { URL , fileURLToPath } from "node:url" ;
3131import minimist from "minimist" ;
3232
@@ -45,7 +45,9 @@ import { setDisplayMediaCallback } from "./displayMediaCallback.js";
4545import { setupMacosTitleBar } from "./macos-titlebar.js" ;
4646import { type Json , loadJsonFile } from "./utils.js" ;
4747import { setupMediaAuth } from "./media-auth.js" ;
48- import { readBuildConfig } from "./build-config.js" ;
48+ import { getBuildConfig } from "./build-config.js" ;
49+ import { getAsarPath } from "./asar.js" ;
50+ import { getIconPath } from "./icon.js" ;
4951
5052const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
5153
@@ -84,7 +86,7 @@ function isRealUserDataDir(d: string): boolean {
8486 return fs . existsSync ( path . join ( d , "IndexedDB" ) ) ;
8587}
8688
87- const buildConfig = readBuildConfig ( ) ;
89+ const buildConfig = getBuildConfig ( ) ;
8890const protocolHandler = new ProtocolHandler ( buildConfig . protocol ) ;
8991
9092// check if we are passed a profile in the SSO callback url
@@ -118,45 +120,8 @@ if (userDataPathInProtocol) {
118120}
119121app . setPath ( "userData" , userDataPath ) ;
120122
121- async function tryPaths ( name : string , root : string , rawPaths : string [ ] ) : Promise < string > {
122- // Make everything relative to root
123- const paths = rawPaths . map ( ( p ) => path . join ( root , p ) ) ;
124-
125- for ( const p of paths ) {
126- try {
127- await afs . stat ( p ) ;
128- return p + "/" ;
129- } catch { }
130- }
131- console . log ( `Couldn't find ${ name } files in any of: ` ) ;
132- for ( const p of paths ) {
133- console . log ( "\t" + path . resolve ( p ) ) ;
134- }
135- throw new Error ( `Failed to find ${ name } files` ) ;
136- }
137-
138123const homeserverProps = [ "default_is_url" , "default_hs_url" , "default_server_name" , "default_server_config" ] as const ;
139124
140- let asarPathPromise : Promise < string > | undefined ;
141- // Get the webapp resource file path, memoizes result
142- function getAsarPath ( ) : Promise < string > {
143- if ( ! asarPathPromise ) {
144- asarPathPromise = tryPaths ( "webapp" , __dirname , [
145- // If run from the source checkout, this will be in the directory above
146- "../webapp.asar" ,
147- // but if run from a packaged application, electron-main.js will be in
148- // a different asar file, so it will be two levels above
149- "../../webapp.asar" ,
150- // also try without the 'asar' suffix to allow symlinking in a directory
151- "../webapp" ,
152- // from a packaged application
153- "../../webapp" ,
154- ] ) ;
155- }
156-
157- return asarPathPromise ;
158- }
159-
160125function loadLocalConfigFile ( ) : Json {
161126 if ( LocalConfigLocation ) {
162127 console . log ( "Loading local config: " + LocalConfigLocation ) ;
@@ -254,19 +219,6 @@ async function configureSentry(): Promise<void> {
254219 }
255220}
256221
257- // Set up globals for Tray
258- async function setupGlobals ( ) : Promise < void > {
259- const asarPath = await getAsarPath ( ) ;
260- await loadConfig ( ) ;
261-
262- // Figure out the tray icon path & brand name
263- const iconFile = `icon.${ process . platform === "win32" ? "ico" : "png" } ` ;
264- global . trayConfig = {
265- icon_path : path . join ( path . dirname ( asarPath ) , "build" , iconFile ) ,
266- brand : global . vectorConfig . brand || "Element" ,
267- } ;
268- }
269-
270222global . appQuitting = false ;
271223
272224const exitShortcuts : Array < ( input : Input , platform : string ) => boolean > = [
@@ -347,7 +299,7 @@ app.on("ready", async () => {
347299
348300 try {
349301 asarPath = await getAsarPath ( ) ;
350- await setupGlobals ( ) ;
302+ await loadConfig ( ) ;
351303 } catch ( e ) {
352304 console . log ( "App setup failed: exiting" , e ) ;
353305 process . exit ( 1 ) ;
@@ -451,7 +403,7 @@ app.on("ready", async () => {
451403 titleBarStyle : process . platform === "darwin" ? "hidden" : "default" ,
452404 trafficLightPosition : { x : 9 , y : 8 } ,
453405
454- icon : global . trayConfig . icon_path ,
406+ icon : await getIconPath ( ) ,
455407 show : false ,
456408 autoHideMenuBar : store . get ( "autoHideMenuBar" ) ,
457409
@@ -489,7 +441,7 @@ app.on("ready", async () => {
489441 global . mainWindow . webContents . session . setSpellCheckerEnabled ( store . get ( "spellCheckerEnabled" , true ) ) ;
490442
491443 // Create trayIcon icon
492- if ( store . get ( "minimizeToTray" ) ) tray . create ( global . trayConfig ) ;
444+ if ( store . get ( "minimizeToTray" ) ) await tray . create ( ) ;
493445
494446 global . mainWindow . once ( "ready-to-show" , ( ) => {
495447 if ( ! global . mainWindow ) return ;
0 commit comments