Notes/src/public/app/desktop.js

83 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-12-01 13:07:23 +01:00
import appContext from "./components/app_context.js";
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";
import toastService from "./services/toast.js";
import noteAutocompleteService from './services/note_autocomplete.js';
import macInit from './services/mac_init.js';
import electronContextMenu from "./menus/electron_context_menu.js";
2020-04-12 14:22:51 +02:00
import glob from "./services/glob.js";
import { t } from "./services/i18n.js";
import options from "./services/options.js";
2020-04-12 14:22:51 +02:00
await appContext.earlyInit();
2024-08-11 08:12:01 +03:00
bundleService.getWidgetBundlesByParent().then(async widgetBundles => {
// A dynamic import is required for layouts since they initialize components which require translations.
const DesktopLayout = (await import("./layouts/desktop_layout.js")).default;
appContext.setLayout(new DesktopLayout(widgetBundles));
appContext.start()
.catch((e) => {
toastService.showPersistent({
title: t("toast.critical-error.title"),
icon: "alert",
message: t("toast.critical-error.message", { message: e.message }),
});
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
if (utils.isElectron()) {
initOnElectron();
}
2018-03-25 22:37:02 -04:00
2020-02-14 20:18:09 +01:00
macInit.init();
noteTooltipService.setupGlobalTooltip();
noteAutocompleteService.init();
if (utils.isElectron()) {
electronContextMenu.setupContextMenu();
}
function initOnElectron() {
const electron = utils.dynamicRequire('electron');
electron.ipcRenderer.on('globalShortcut', async (event, actionName) => appContext.triggerCommand(actionName));
if (options.get("nativeTitleBarVisible") !== "true") {
initTitleBarButtons();
}
}
function initTitleBarButtons() {
function applyTitleBarOverlaySettings() {
const electronRemote = utils.dynamicRequire("@electron/remote");
const currentWindow = electronRemote.getCurrentWindow();
const style = window.getComputedStyle(document.body);
const color = style.getPropertyValue("--native-titlebar-background");
const symbolColor = style.getPropertyValue("--native-titlebar-foreground");
if (color && symbolColor) {
// FIXME, do this only on windows
// currentWindow.setTitleBarOverlay({ color, symbolColor });
}
// FIXME: call only on 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 });
}
// Update the native title bar buttons.
applyTitleBarOverlaySettings();
// Register for changes to the native title bar colors.
window.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", applyTitleBarOverlaySettings);
}