mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	refactor(server); electron imports causing issues in bundle
This commit is contained in:
		| @@ -137,7 +137,7 @@ export default async function buildApp() { | ||||
|     startScheduledCleanup(); | ||||
|  | ||||
|     if (utils.isElectron) { | ||||
|         (await import("@electron/remote/main")).initialize(); | ||||
|         (await import("@electron/remote/main/index.js")).initialize(); | ||||
|     } | ||||
|  | ||||
|     return app; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { ipcMain } from "electron"; | ||||
| import electron from "electron"; | ||||
|  | ||||
| interface Response { | ||||
|     statusCode: number; | ||||
| @@ -10,7 +10,7 @@ interface Response { | ||||
| } | ||||
|  | ||||
| function init(app: Express.Application) { | ||||
|     ipcMain.on("server-request", (event, arg) => { | ||||
|     electron.ipcMain.on("server-request", (event, arg) => { | ||||
|         const req = { | ||||
|             url: arg.url, | ||||
|             method: arg.method, | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| import { BrowserWindow, Menu, Tray, ipcMain, nativeTheme } from "electron"; | ||||
| import electron from "electron"; | ||||
| import type { BrowserWindow, Tray } from "electron"; | ||||
| import { default as i18next, t } from "i18next"; | ||||
| import path from "path"; | ||||
| import { fileURLToPath } from "url"; | ||||
|  | ||||
| import becca from "../becca/becca.js"; | ||||
| import becca_service from "../becca/becca_service.js"; | ||||
| @@ -33,7 +33,7 @@ function getTrayIconPath() { | ||||
| } | ||||
|  | ||||
| function getIconPath(name: string) { | ||||
|     const suffix = !isMac && nativeTheme.shouldUseDarkColors ? "-inverted" : ""; | ||||
|     const suffix = !isMac && electron.nativeTheme.shouldUseDarkColors ? "-inverted" : ""; | ||||
|     return path.resolve(path.join(getResourceDir(), "assets", "images", "tray", `${name}Template${suffix}.png`)); | ||||
| } | ||||
|  | ||||
| @@ -216,7 +216,7 @@ function updateTrayMenu() { | ||||
|     } | ||||
|  | ||||
|  | ||||
|     const contextMenu = Menu.buildFromTemplate([ | ||||
|     const contextMenu = electron.Menu.buildFromTemplate([ | ||||
|         ...windowVisibilityMenuItems, | ||||
|         { type: "separator" }, | ||||
|         { | ||||
| @@ -255,7 +255,7 @@ function updateTrayMenu() { | ||||
|             type: "normal", | ||||
|             icon: getIconPath("close"), | ||||
|             click: () => { | ||||
|                 const windows = BrowserWindow.getAllWindows(); | ||||
|                 const windows = electron.BrowserWindow.getAllWindows(); | ||||
|                 windows.forEach(window => { | ||||
|                     window.close(); | ||||
|                 }); | ||||
| @@ -287,7 +287,7 @@ function createTray() { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     tray = new Tray(getTrayIconPath()); | ||||
|     tray = new electron.Tray(getTrayIconPath()); | ||||
|     tray.setToolTip(t("tray.tooltip")); | ||||
|     // Restore focus | ||||
|     tray.on("click", changeVisibility); | ||||
| @@ -295,9 +295,9 @@ function createTray() { | ||||
|  | ||||
|     if (!isMac) { | ||||
|         // macOS uses template icons which work great on dark & light themes. | ||||
|         nativeTheme.on("updated", updateTrayMenu); | ||||
|         electron.nativeTheme.on("updated", updateTrayMenu); | ||||
|     } | ||||
|     ipcMain.on("reload-tray", updateTrayMenu); | ||||
|     electron.ipcMain.on("reload-tray", updateTrayMenu); | ||||
|     i18next.on("languageChanged", updateTrayMenu); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -7,9 +7,9 @@ import log from "./log.js"; | ||||
| import sqlInit from "./sql_init.js"; | ||||
| import cls from "./cls.js"; | ||||
| import keyboardActionsService from "./keyboard_actions.js"; | ||||
| import * as remoteMain from "@electron/remote/main"; | ||||
| import { BrowserWindow, shell, type App, type BrowserWindowConstructorOptions, type WebContents } from "electron"; | ||||
| import { dialog, ipcMain } from "electron"; | ||||
| import * as remoteMain from "@electron/remote/main/index.js"; | ||||
| import electron from "electron"; | ||||
| import type { App, BrowserWindowConstructorOptions, BrowserWindow, WebContents } from "electron"; | ||||
| import { formatDownloadTitle, isDev, isMac, isWindows } from "./utils.js"; | ||||
|  | ||||
| import { fileURLToPath } from "url"; | ||||
| @@ -28,14 +28,14 @@ function trackWindowFocus(win: BrowserWindow) { | ||||
|         allWindows = allWindows.filter(w => !w.isDestroyed() && w !== win); | ||||
|         allWindows.push(win); | ||||
|         if (!optionService.getOptionBool("disableTray")) { | ||||
|             ipcMain.emit("reload-tray"); | ||||
|             electron.ipcMain.emit("reload-tray"); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     win.on("closed", () => { | ||||
|         allWindows = allWindows.filter(w => !w.isDestroyed()); | ||||
|         if (!optionService.getOptionBool("disableTray")) { | ||||
|             ipcMain.emit("reload-tray"); | ||||
|             electron.ipcMain.emit("reload-tray"); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| @@ -66,7 +66,7 @@ async function createExtraWindow(extraWindowHash: string) { | ||||
|     trackWindowFocus(win); | ||||
| } | ||||
|  | ||||
| ipcMain.on("create-extra-window", (event, arg) => { | ||||
| electron.ipcMain.on("create-extra-window", (event, arg) => { | ||||
|     createExtraWindow(arg.extraWindowHash); | ||||
| }); | ||||
|  | ||||
| @@ -76,13 +76,13 @@ interface ExportAsPdfOpts { | ||||
|     pageSize: "A0" | "A1" | "A2" | "A3" | "A4" | "A5" | "A6" | "Legal" | "Letter" | "Tabloid" | "Ledger"; | ||||
| } | ||||
|  | ||||
| ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => { | ||||
|     const browserWindow = BrowserWindow.fromWebContents(e.sender); | ||||
| electron.ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => { | ||||
|     const browserWindow = electron.BrowserWindow.fromWebContents(e.sender); | ||||
|     if (!browserWindow) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     const filePath = dialog.showSaveDialogSync(browserWindow, { | ||||
|     const filePath = electron.dialog.showSaveDialogSync(browserWindow, { | ||||
|         defaultPath: formatDownloadTitle(opts.title, "file", "application/pdf"), | ||||
|         filters: [ | ||||
|             { | ||||
| @@ -111,18 +111,18 @@ ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => { | ||||
|             ` | ||||
|         }); | ||||
|     } catch (e) { | ||||
|         dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-export-message")); | ||||
|         electron.dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-export-message")); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     try { | ||||
|         await fs.writeFile(filePath, buffer); | ||||
|     } catch (e) { | ||||
|         dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-save-message")); | ||||
|         electron.dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-save-message")); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     shell.openPath(filePath); | ||||
|     electron.shell.openPath(filePath); | ||||
| }); | ||||
|  | ||||
| async function createMainWindow(app: App) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user