mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
refactor(desktop): use shorter imports
This commit is contained in:
parent
f607c9793d
commit
0fcff6639f
@ -1,7 +1,7 @@
|
|||||||
import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js";
|
import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
|
|
||||||
import electron from "electron";
|
import { app, globalShortcut, BrowserWindow } from "electron";
|
||||||
import sqlInit from "@triliumnext/server/src/services/sql_init.js";
|
import sqlInit from "@triliumnext/server/src/services/sql_init.js";
|
||||||
import windowService from "@triliumnext/server/src/services/window.js";
|
import windowService from "@triliumnext/server/src/services/window.js";
|
||||||
import tray from "@triliumnext/server/src/services/tray.js";
|
import tray from "@triliumnext/server/src/services/tray.js";
|
||||||
@ -24,48 +24,46 @@ async function main() {
|
|||||||
electronDl({ saveAs: true });
|
electronDl({ saveAs: true });
|
||||||
|
|
||||||
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
||||||
electron.app.commandLine.appendSwitch("enable-experimental-web-platform-features");
|
app.commandLine.appendSwitch("enable-experimental-web-platform-features");
|
||||||
electron.app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en");
|
app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en");
|
||||||
|
|
||||||
// Disable smooth scroll if the option is set
|
// Disable smooth scroll if the option is set
|
||||||
const smoothScrollEnabled = options.getOptionOrNull("smoothScrollEnabled");
|
const smoothScrollEnabled = options.getOptionOrNull("smoothScrollEnabled");
|
||||||
if (smoothScrollEnabled === "false") {
|
if (smoothScrollEnabled === "false") {
|
||||||
electron.app.commandLine.appendSwitch("disable-smooth-scrolling");
|
app.commandLine.appendSwitch("disable-smooth-scrolling");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Electron 36 crashes with "Using GTK 2/3 and GTK 4 in the same process is not supported" on some distributions.
|
// Electron 36 crashes with "Using GTK 2/3 and GTK 4 in the same process is not supported" on some distributions.
|
||||||
// See https://github.com/electron/electron/issues/46538 for more info.
|
// See https://github.com/electron/electron/issues/46538 for more info.
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
electron.app.setName(PRODUCT_NAME);
|
app.setName(PRODUCT_NAME);
|
||||||
electron.app.commandLine.appendSwitch("gtk-version", "3");
|
app.commandLine.appendSwitch("gtk-version", "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// 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
|
// for applications and their menu bar to stay active until the user quits
|
||||||
// explicitly with Cmd + Q.
|
// explicitly with Cmd + Q.
|
||||||
electron.app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
if (process.platform !== "darwin") {
|
if (process.platform !== "darwin") {
|
||||||
electron.app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on("ready", async () => {
|
app.on("ready", async () => {
|
||||||
await serverInitializedPromise;
|
await serverInitializedPromise;
|
||||||
console.log("Starting Electron...");
|
console.log("Starting Electron...");
|
||||||
await onReady();
|
await onReady();
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on("will-quit", () => {
|
app.on("will-quit", () => {
|
||||||
electron.globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.app.on("second-instance", (event, commandLine) => {
|
app.on("second-instance", (event, commandLine) => {
|
||||||
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
||||||
if (commandLine.includes("--new-window")) {
|
if (commandLine.includes("--new-window")) {
|
||||||
windowService.createExtraWindow("");
|
windowService.createExtraWindow("");
|
||||||
} else if (lastFocusedWindow) {
|
} else if (lastFocusedWindow) {
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
|
||||||
// see www.ts "requestSingleInstanceLock" for the rest of this logic with explanation
|
|
||||||
if (lastFocusedWindow.isMinimized()) {
|
if (lastFocusedWindow.isMinimized()) {
|
||||||
lastFocusedWindow.restore();
|
lastFocusedWindow.restore();
|
||||||
}
|
}
|
||||||
@ -92,19 +90,19 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onReady() {
|
async function onReady() {
|
||||||
// electron.app.setAppUserModelId('com.github.zadam.trilium');
|
// app.setAppUserModelId('com.github.zadam.trilium');
|
||||||
|
|
||||||
// if db is not initialized -> setup process
|
// if db is not initialized -> setup process
|
||||||
// if db is initialized, then we need to wait until the migration process is finished
|
// if db is initialized, then we need to wait until the migration process is finished
|
||||||
if (sqlInit.isDbInitialized()) {
|
if (sqlInit.isDbInitialized()) {
|
||||||
await sqlInit.dbReady;
|
await sqlInit.dbReady;
|
||||||
|
|
||||||
await windowService.createMainWindow(electron.app);
|
await windowService.createMainWindow(app);
|
||||||
|
|
||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
electron.app.on("activate", async () => {
|
app.on("activate", async () => {
|
||||||
if (electron.BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
await windowService.createMainWindow(electron.app);
|
await windowService.createMainWindow(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user