diff --git a/electron-builder.config.js b/electron-builder.config.js index b4527dffb..4dfda3f9b 100644 --- a/electron-builder.config.js +++ b/electron-builder.config.js @@ -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, }, diff --git a/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.test.ts b/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.test.ts deleted file mode 100644 index 34bedd37e..000000000 --- a/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { App } from "electron"; -import { describe, expect, it, vi } from "vitest"; -import { SingleInstanceLockModule } from "./SingleInstanceLockModule"; - -describe(SingleInstanceLockModule, () => { - it("should request single instance lock", () => { - const requestSingleInstanceLockMock = vi.fn().mockReturnValue(true); - const quickMock = vi.fn(); - - SingleInstanceLockModule.bootstrap({ - requestSingleInstanceLock: () => requestSingleInstanceLockMock(), - quit: () => quickMock(), - }); - - expect(requestSingleInstanceLockMock).toHaveBeenCalledOnce(); - expect(quickMock).not.toHaveBeenCalled(); - }); - - it("should quit the application if another instance is already running", () => { - const requestSingleInstanceLockMock = vi.fn().mockReturnValue(false); - - const quickMock = vi.fn(); - - SingleInstanceLockModule.bootstrap({ - requestSingleInstanceLock: () => requestSingleInstanceLockMock(), - quit: () => quickMock(), - }); - - expect(requestSingleInstanceLockMock).toHaveBeenCalledOnce(); - expect(quickMock).toHaveBeenCalledOnce(); - }); -}); diff --git a/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.ts b/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.ts deleted file mode 100644 index 93a45198a..000000000 --- a/src/main/Core/SingleInstanceLock/SingleInstanceLockModule.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { App } from "electron"; - -export class SingleInstanceLockModule { - public static bootstrap(app: App) { - if (!app.requestSingleInstanceLock()) { - console.log("Quitting application. Reason: another instance is already running"); - app.quit(); - } - } -} diff --git a/src/main/Core/SingleInstanceLock/index.ts b/src/main/Core/SingleInstanceLock/index.ts deleted file mode 100644 index 15e17538a..000000000 --- a/src/main/Core/SingleInstanceLock/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./SingleInstanceLockModule"; diff --git a/src/main/Core/index.ts b/src/main/Core/index.ts index 5b3ba89d7..7d10fdc79 100644 --- a/src/main/Core/index.ts +++ b/src/main/Core/index.ts @@ -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"; diff --git a/src/main/index.ts b/src/main/index.ts index b34f75668..071a34706 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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>()); - 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);