Skip to content

Commit 6c275e8

Browse files
committed
fix: move app init into fn, dynamic load app after logger is ready
1 parent e336663 commit 6c275e8

File tree

2 files changed

+239
-226
lines changed

2 files changed

+239
-226
lines changed

electron/main/index.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
import { app } from 'electron';
12
import { config as initializeDotenv } from 'dotenv-flow';
23
import { initializeLogging } from './logger/initialize-logging.js';
34
import { initializeSentry } from './sentry/initialize-sentry.js';
45

6+
// Unfortunately in development mode, the app name is 'Electron'.
7+
// The paths to logs, user data, etc is based on the app name.
8+
// To ensure a consistent app name for all environments, we set it first.
9+
// Otherwise, packages like electron-log will use the wrong paths.
10+
app.setName('Phoenix');
11+
app.setAppUserModelId('com.github.dragonrealms-phoenix.phoenix');
12+
513
initializeDotenv();
614
initializeLogging();
715
initializeSentry();
816

9-
import './app.js';
17+
// Once electron-log is initialized then it's safe for us to
18+
// import and use other modules that depend on logging.
19+
// Otherwise, those modules prematurely create logger instances.
20+
// To ensure no imported module (or their dependencies) loads prematurely,
21+
// then we dynamically import the app initialization module at the right time.
22+
const { initializeApp } = await import('./initialize-app.js');
23+
await initializeApp();

0 commit comments

Comments
 (0)