Skip to content

Commit

Permalink
perf: improve launch performance (#1284)
Browse files Browse the repository at this point in the history
* Import modules dynamically

* Prettier fix

* refactor: import only needed electron modules

* Changed comment

---------

Co-authored-by: Oliver Schwendener <[email protected]>
Co-authored-by: Oliver Schwendener <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2024
1 parent 8149305 commit b4fb70b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 64 deletions.
2 changes: 1 addition & 1 deletion electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const baseConfig = {
output: "release",
buildResources: "build",
},
files: ["dist-main/index.js", "dist-preload/index.js", "dist-renderer/**/*", "assets/**/*"],
files: ["dist-main/**/*.js", "dist-preload/index.js", "dist-renderer/**/*", "assets/**/*"],
extraMetadata: {
version: process.env.VITE_APP_VERSION,
},
Expand Down
32 changes: 0 additions & 32 deletions src/main/Core/SingleInstanceLock/SingleInstanceLockModule.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/Core/SingleInstanceLock/SingleInstanceLockModule.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/main/Core/SingleInstanceLock/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/main/Core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export * from "./SettingsManager";
export * from "./SettingsReader";
export * from "./SettingsWriter";
export * from "./Shell";
export * from "./SingleInstanceLock";
export * from "./TaskScheduler";
export * from "./Terminal";
export * from "./Translator";
Expand Down
55 changes: 36 additions & 19 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
import * as Electron from "electron";
import mitt from "mitt";
import { platform } from "os";
import * as Core from "./Core";
import * as Extensions from "./Extensions";
import { app } from "electron";

if (!app.requestSingleInstanceLock()) {
console.log("Quitting application. Reason: another instance is already running");
app.exit();
}

(async () => {
await Electron.app.whenReady();
await app.whenReady();

const {
clipboard,
dialog,
globalShortcut,
ipcMain,
nativeTheme,
net,
safeStorage,
screen,
shell,
systemPreferences,
} = await import("electron");

Core.SingleInstanceLockModule.bootstrap(Electron.app);
const { default: mitt } = await import("mitt");
const { platform } = await import("os");
const Core = await import("./Core");
const Extensions = await import("./Extensions");

const dependencyRegistry = Core.DependencyRegistryModule.bootstrap();

// Electron Modules
dependencyRegistry.register("App", Electron.app);
dependencyRegistry.register("Clipboard", Electron.clipboard);
dependencyRegistry.register("Dialog", Electron.dialog);
// Electron and Node Modules
dependencyRegistry.register("App", app);
dependencyRegistry.register("Clipboard", clipboard);
dependencyRegistry.register("Dialog", dialog);
dependencyRegistry.register("Emitter", mitt<Record<string, unknown>>());
dependencyRegistry.register("GlobalShortcut", Electron.globalShortcut);
dependencyRegistry.register("IpcMain", Electron.ipcMain);
dependencyRegistry.register("NativeTheme", Electron.nativeTheme);
dependencyRegistry.register("Net", Electron.net);
dependencyRegistry.register("GlobalShortcut", globalShortcut);
dependencyRegistry.register("IpcMain", ipcMain);
dependencyRegistry.register("NativeTheme", nativeTheme);
dependencyRegistry.register("Net", net);
dependencyRegistry.register("Platform", platform());
dependencyRegistry.register("SafeStorage", Electron.safeStorage);
dependencyRegistry.register("Screen", Electron.screen);
dependencyRegistry.register("Shell", Electron.shell);
dependencyRegistry.register("SystemPreferences", Electron.systemPreferences);
dependencyRegistry.register("SafeStorage", safeStorage);
dependencyRegistry.register("Screen", screen);
dependencyRegistry.register("Shell", shell);
dependencyRegistry.register("SystemPreferences", systemPreferences);

// Core Modules
Core.OperatingSystemModule.bootstrap(dependencyRegistry);
Expand Down

0 comments on commit b4fb70b

Please sign in to comment.