2022-12-01 13:07:23 +01:00
|
|
|
|
import appContext from "./components/app_context.js";
|
2025-01-09 18:07:02 +02:00
|
|
|
|
import utils from "./services/utils.js";
|
|
|
|
|
import noteTooltipService from "./services/note_tooltip.js";
|
2020-04-12 14:22:51 +02:00
|
|
|
|
import bundleService from "./services/bundle.js";
|
2024-07-27 12:05:24 +03:00
|
|
|
|
import toastService from "./services/toast.js";
|
2025-01-09 18:07:02 +02:00
|
|
|
|
import noteAutocompleteService from "./services/note_autocomplete.js";
|
2023-05-07 10:43:51 +02:00
|
|
|
|
import electronContextMenu from "./menus/electron_context_menu.js";
|
2020-04-12 14:22:51 +02:00
|
|
|
|
import glob from "./services/glob.js";
|
2024-07-27 12:10:59 +03:00
|
|
|
|
import { t } from "./services/i18n.js";
|
2024-12-01 18:18:53 +02:00
|
|
|
|
import options from "./services/options.js";
|
2025-01-28 07:23:57 +01:00
|
|
|
|
import type ElectronRemote from "@electron/remote";
|
|
|
|
|
import type Electron from "electron";
|
2020-04-12 14:22:51 +02:00
|
|
|
|
|
2024-10-24 20:55:21 +03:00
|
|
|
|
await appContext.earlyInit();
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
|
bundleService.getWidgetBundlesByParent().then(async (widgetBundles) => {
|
2024-08-11 08:12:01 +03:00
|
|
|
|
// A dynamic import is required for layouts since they initialize components which require translations.
|
|
|
|
|
const DesktopLayout = (await import("./layouts/desktop_layout.js")).default;
|
|
|
|
|
|
2024-12-22 15:42:15 +02:00
|
|
|
|
appContext.setLayout(new DesktopLayout(widgetBundles));
|
2025-01-09 18:07:02 +02:00
|
|
|
|
appContext.start().catch((e) => {
|
|
|
|
|
toastService.showPersistent({
|
|
|
|
|
title: t("toast.critical-error.title"),
|
|
|
|
|
icon: "alert",
|
|
|
|
|
message: t("toast.critical-error.message", { message: e.message })
|
2024-07-27 12:05:24 +03:00
|
|
|
|
});
|
2025-01-09 18:07:02 +02:00
|
|
|
|
console.error("Critical error occured", e);
|
|
|
|
|
});
|
2022-11-22 23:53:08 +01:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-12 14:22:51 +02:00
|
|
|
|
glob.setupGlobs();
|
2018-03-24 11:18:46 -04:00
|
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
|
if (utils.isElectron()) {
|
2024-12-01 02:18:35 +02:00
|
|
|
|
initOnElectron();
|
2018-03-26 22:29:14 -04:00
|
|
|
|
}
|
2018-03-25 22:37:02 -04:00
|
|
|
|
|
2018-12-22 20:57:09 +01:00
|
|
|
|
noteTooltipService.setupGlobalTooltip();
|
2018-03-26 22:29:14 -04:00
|
|
|
|
|
2020-02-28 22:07:08 +01:00
|
|
|
|
noteAutocompleteService.init();
|
|
|
|
|
|
|
|
|
|
if (utils.isElectron()) {
|
2023-05-07 10:43:51 +02:00
|
|
|
|
electronContextMenu.setupContextMenu();
|
2020-05-11 20:08:55 +02:00
|
|
|
|
}
|
2024-12-01 02:18:35 +02:00
|
|
|
|
|
|
|
|
|
function initOnElectron() {
|
2025-01-28 07:23:57 +01:00
|
|
|
|
const electron: typeof Electron = utils.dynamicRequire("electron");
|
2025-01-09 18:07:02 +02:00
|
|
|
|
electron.ipcRenderer.on("globalShortcut", async (event, actionName) => appContext.triggerCommand(actionName));
|
2025-02-01 02:18:10 +02:00
|
|
|
|
electron.ipcRenderer.on("openInSameTab", async (event, noteId) => appContext.tabManager.openInSameTab(noteId));
|
2025-01-28 07:23:57 +01:00
|
|
|
|
const electronRemote: typeof ElectronRemote = utils.dynamicRequire("@electron/remote");
|
2024-12-22 15:42:15 +02:00
|
|
|
|
const currentWindow = electronRemote.getCurrentWindow();
|
2024-12-07 10:02:56 +02:00
|
|
|
|
const style = window.getComputedStyle(document.body);
|
2024-12-07 03:15:39 +02:00
|
|
|
|
|
2025-02-17 18:07:36 +02:00
|
|
|
|
initDarkOrLightMode(style);
|
2024-12-07 10:02:56 +02:00
|
|
|
|
initTransparencyEffects(style, currentWindow);
|
2024-12-07 03:15:39 +02:00
|
|
|
|
|
2024-12-01 18:18:53 +02:00
|
|
|
|
if (options.get("nativeTitleBarVisible") !== "true") {
|
2024-12-07 10:02:56 +02:00
|
|
|
|
initTitleBarButtons(style, currentWindow);
|
2024-12-22 15:42:15 +02:00
|
|
|
|
}
|
2024-12-01 18:18:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-28 07:23:57 +01:00
|
|
|
|
function initTitleBarButtons(style: CSSStyleDeclaration, currentWindow: Electron.BrowserWindow) {
|
2024-12-07 00:41:17 +02:00
|
|
|
|
if (window.glob.platform === "win32") {
|
|
|
|
|
const applyWindowsOverlay = () => {
|
|
|
|
|
const color = style.getPropertyValue("--native-titlebar-background");
|
|
|
|
|
const symbolColor = style.getPropertyValue("--native-titlebar-foreground");
|
|
|
|
|
if (color && symbolColor) {
|
|
|
|
|
currentWindow.setTitleBarOverlay({ color, symbolColor });
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-12-22 15:42:15 +02:00
|
|
|
|
|
2024-12-07 00:41:17 +02:00
|
|
|
|
applyWindowsOverlay();
|
2024-12-04 23:44:26 +02:00
|
|
|
|
|
2024-12-07 00:41:17 +02:00
|
|
|
|
// Register for changes to the native title bar colors.
|
2025-01-09 18:07:02 +02:00
|
|
|
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", applyWindowsOverlay);
|
2024-12-01 18:18:53 +02:00
|
|
|
|
}
|
2024-12-07 00:41:17 +02:00
|
|
|
|
|
|
|
|
|
if (window.glob.platform === "darwin") {
|
|
|
|
|
const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10);
|
|
|
|
|
const yOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-y-offset"), 10);
|
|
|
|
|
currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset });
|
2024-12-22 15:42:15 +02:00
|
|
|
|
}
|
2024-12-01 17:59:55 +02:00
|
|
|
|
}
|
2024-12-07 03:15:39 +02:00
|
|
|
|
|
2025-01-28 07:23:57 +01:00
|
|
|
|
function initTransparencyEffects(style: CSSStyleDeclaration, currentWindow: Electron.BrowserWindow) {
|
2024-12-07 03:15:39 +02:00
|
|
|
|
if (window.glob.platform === "win32") {
|
2024-12-07 10:02:56 +02:00
|
|
|
|
const material = style.getPropertyValue("--background-material");
|
2025-01-28 07:23:57 +01:00
|
|
|
|
// TriliumNextTODO: find a nicer way to make TypeScript happy – unfortunately TS did not like Array.includes here
|
|
|
|
|
const bgMaterialOptions = ["auto", "none", "mica", "acrylic", "tabbed"] as const;
|
|
|
|
|
const foundBgMaterialOption = bgMaterialOptions.find((bgMaterialOption) => material === bgMaterialOption);
|
|
|
|
|
if (foundBgMaterialOption) {
|
|
|
|
|
currentWindow.setBackgroundMaterial(foundBgMaterialOption);
|
|
|
|
|
}
|
2024-12-07 03:15:39 +02:00
|
|
|
|
}
|
2024-12-22 15:42:15 +02:00
|
|
|
|
}
|
2025-02-17 18:07:36 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Informs Electron that we prefer a dark or light theme. Apart from changing prefers-color-scheme at CSS level which is a side effect,
|
|
|
|
|
* this fixes color issues with background effects or native title bars.
|
|
|
|
|
*
|
|
|
|
|
* @param style the root CSS element to read variables from.
|
|
|
|
|
*/
|
|
|
|
|
function initDarkOrLightMode(style: CSSStyleDeclaration) {
|
|
|
|
|
let themeSource: typeof nativeTheme.themeSource = "system";
|
|
|
|
|
|
|
|
|
|
const themeStyle = style.getPropertyValue("--theme-style");
|
|
|
|
|
if (style.getPropertyValue("--theme-style-auto") !== "true" && (themeStyle === "light" || themeStyle === "dark")) {
|
|
|
|
|
themeSource = themeStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { nativeTheme } = utils.dynamicRequire("@electron/remote") as typeof ElectronRemote;
|
|
|
|
|
nativeTheme.themeSource = themeSource;
|
|
|
|
|
}
|