diff --git a/apps/desktop/.swcrc b/apps/desktop/.swcrc new file mode 100644 index 000000000..a2d5b04f4 --- /dev/null +++ b/apps/desktop/.swcrc @@ -0,0 +1,8 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "es2016" + } +} diff --git a/apps/desktop/src/electron-main.ts b/apps/desktop/src/electron-main.ts index 1ec06794a..1ded01e95 100644 --- a/apps/desktop/src/electron-main.ts +++ b/apps/desktop/src/electron-main.ts @@ -1,8 +1,71 @@ import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js"; +import electron from "electron"; +import sqlInit from "@triliumnext/server/src/services/sql_init.js"; +import windowService from "@triliumnext/server/src/services/window.js"; +import tray from "@triliumnext/server/src/services/tray.js"; +import options from "@triliumnext/server/src/services/options.js"; +import electronDebug from "electron-debug"; +import electronDl from "electron-dl"; + async function main() { + // Prevent Trilium starting twice on first install and on uninstall for the Windows installer. + if ((require("electron-squirrel-startup")).default) { + process.exit(0); + } + + // Adds debug features like hotkeys for triggering dev tools and reload + electronDebug(); + electronDl({ saveAs: true }); + + // needed for excalidraw export https://github.com/zadam/trilium/issues/4271 + electron.app.commandLine.appendSwitch("enable-experimental-web-platform-features"); + electron.app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en"); + + // Quit when all windows are closed, except on macOS. There, it's common + // for applications and their menu bar to stay active until the user quits + // explicitly with Cmd + Q. + electron.app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + electron.app.quit(); + } + }); + + electron.app.on("ready", async () => { + // electron.app.setAppUserModelId('com.github.zadam.trilium'); + + // if db is not initialized -> setup process + // if db is initialized, then we need to wait until the migration process is finished + if (sqlInit.isDbInitialized()) { + await sqlInit.dbReady; + + await windowService.createMainWindow(electron.app); + + if (process.platform === "darwin") { + electron.app.on("activate", async () => { + if (electron.BrowserWindow.getAllWindows().length === 0) { + await windowService.createMainWindow(electron.app); + } + }); + } + + tray.createTray(); + } else { + await windowService.createSetupWindow(); + } + + await windowService.registerGlobalShortcuts(); + }); + + electron.app.on("will-quit", () => { + electron.globalShortcut.unregisterAll(); + }); + + // this is to disable electron warning spam in the dev console (local development only) + process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true"; + await initializeTranslations(); - (await import("./electron.js")).default(); + await import("@triliumnext/server/src/main.js"); } main(); diff --git a/apps/desktop/src/electron.ts b/apps/desktop/src/electron.ts deleted file mode 100644 index 39d509bd3..000000000 --- a/apps/desktop/src/electron.ts +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; - -import electron from "electron"; -import sqlInit from "@triliumnext/server/src/services/sql_init.js"; -import windowService from "@triliumnext/server/src/services/window.js"; -import tray from "@triliumnext/server/src/services/tray.js"; -import options from "@triliumnext/server/src/services/options.js"; - -export default async function start() { - // Prevent Trilium starting twice on first install and on uninstall for the Windows installer. - if ((await import("electron-squirrel-startup")).default) { - process.exit(0); - } - - // Adds debug features like hotkeys for triggering dev tools and reload - (await import("electron-debug")).default(); - (await import("electron-dl")).default({ saveAs: true }); - - // needed for excalidraw export https://github.com/zadam/trilium/issues/4271 - electron.app.commandLine.appendSwitch("enable-experimental-web-platform-features"); - electron.app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en"); - - // Quit when all windows are closed, except on macOS. There, it's common - // for applications and their menu bar to stay active until the user quits - // explicitly with Cmd + Q. - electron.app.on("window-all-closed", () => { - if (process.platform !== "darwin") { - electron.app.quit(); - } - }); - - electron.app.on("ready", async () => { - // electron.app.setAppUserModelId('com.github.zadam.trilium'); - - // if db is not initialized -> setup process - // if db is initialized, then we need to wait until the migration process is finished - if (sqlInit.isDbInitialized()) { - await sqlInit.dbReady; - - await windowService.createMainWindow(electron.app); - - if (process.platform === "darwin") { - electron.app.on("activate", async () => { - if (electron.BrowserWindow.getAllWindows().length === 0) { - await windowService.createMainWindow(electron.app); - } - }); - } - - tray.createTray(); - } else { - await windowService.createSetupWindow(); - } - - await windowService.registerGlobalShortcuts(); - }); - - electron.app.on("will-quit", () => { - electron.globalShortcut.unregisterAll(); - }); - - // this is to disable electron warning spam in the dev console (local development only) - process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true"; - - await import("@triliumnext/server/src/main.js"); -} diff --git a/apps/desktop/webpack.config.js b/apps/desktop/webpack.config.cjs similarity index 79% rename from apps/desktop/webpack.config.js rename to apps/desktop/webpack.config.cjs index 86b67ccfc..de4f922d2 100644 --- a/apps/desktop/webpack.config.js +++ b/apps/desktop/webpack.config.cjs @@ -6,8 +6,9 @@ const outputDir = join(__dirname, 'dist'); module.exports = { output: { - path: outputDir, + path: outputDir }, + target: [ "node" ], plugins: [ new NxAppWebpackPlugin({ target: 'node', @@ -21,18 +22,15 @@ module.exports = { externalDependencies: [ "electron/main", "electron", - "@electron/remote" + "@electron/remote", + "better-sqlite3" ], assets: [ ] }), new CopyPlugin({ - patterns: [ - { - from: "node_modules/better-sqlite3/build/Release", - to: join(outputDir, "Release") - }, + patterns: [ { from: "../client/dist", to: join(outputDir, "public") @@ -44,8 +42,12 @@ module.exports = { { from: "../server/dist/assets", to: join(outputDir, "assets") - } + }, + { + from: "node_modules/better-sqlite3", + to: join(outputDir, "node_modules/better-sqlite3") + }, ] }) - ], + ] }; diff --git a/apps/server/tsconfig.app.json b/apps/server/tsconfig.app.json index bfdaf3cbf..a468dfc28 100644 --- a/apps/server/tsconfig.app.json +++ b/apps/server/tsconfig.app.json @@ -1,8 +1,9 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "NodeNext", + "module": "ESNext", "moduleResolution": "nodenext", + "target": "ES2020", "outDir": "dist", "types": [ "node",