mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 08:57:02 +02:00
fix(standalone): unable to switch themes
This commit is contained in:
@@ -245,8 +245,6 @@ function bootstrapRoute(): BootstrapDefinition {
|
||||
...getSharedBootstrapItems(assetPath, isDbInitialized),
|
||||
isDev: import.meta.env.DEV,
|
||||
isStandalone: true,
|
||||
themeCssUrl: false as const,
|
||||
themeUseNextAsBase: "next" as const,
|
||||
isMainWindow: true,
|
||||
isElectron: false,
|
||||
hasNativeTitleBar: false,
|
||||
|
||||
@@ -46,12 +46,10 @@ export function bootstrap(req: Request, res: Response) {
|
||||
hasBackgroundEffects: isElectron && (isWindows11 || isMac),
|
||||
isMainWindow: true,
|
||||
appCssNoteIds: [],
|
||||
themeCssUrl: false as const
|
||||
} satisfies BootstrapDefinition);
|
||||
return;
|
||||
}
|
||||
|
||||
const options = optionService.getOptionMap();
|
||||
|
||||
const csrfToken = generateCsrfToken(req, res, {
|
||||
overwrite: false,
|
||||
@@ -59,8 +57,7 @@ export function bootstrap(req: Request, res: Response) {
|
||||
});
|
||||
log.info(`CSRF token generation: ${csrfToken ? "Successful" : "Failed"}`);
|
||||
|
||||
const theme = options.theme;
|
||||
const themeNote = attributeService.getNoteWithLabel("appTheme", theme);
|
||||
const options = optionService.getOptionMap();
|
||||
const nativeTitleBarVisible = options.nativeTitleBarVisible === "true";
|
||||
const iconPacks = iconPackService.getIconPacks();
|
||||
|
||||
@@ -68,8 +65,6 @@ export function bootstrap(req: Request, res: Response) {
|
||||
...commonItems,
|
||||
dbInitialized: true,
|
||||
csrfToken,
|
||||
themeCssUrl: getThemeCssUrl(theme, themeNote),
|
||||
themeUseNextAsBase: themeNote?.getAttributeValue("label", "appThemeBase") as "next" | "next-light" | "next-dark",
|
||||
platform: process.platform,
|
||||
hasNativeTitleBar: isElectron && nativeTitleBarVisible,
|
||||
hasBackgroundEffects: options.backgroundEffects === "true"
|
||||
@@ -122,24 +117,3 @@ function getView(req: Request): View {
|
||||
|
||||
return "desktop";
|
||||
}
|
||||
|
||||
function getThemeCssUrl(theme: string, themeNote: BNote | null) {
|
||||
if (theme === "auto") {
|
||||
return `${assetPath}/stylesheets/theme.css`;
|
||||
} else if (theme === "light") {
|
||||
// light theme is always loaded as baseline
|
||||
return false;
|
||||
} else if (theme === "dark") {
|
||||
return `${assetPath}/stylesheets/theme-dark.css`;
|
||||
} else if (theme === "next") {
|
||||
return `${assetPath}/stylesheets/theme-next.css`;
|
||||
} else if (theme === "next-light") {
|
||||
return `${assetPath}/stylesheets/theme-next-light.css`;
|
||||
} else if (theme === "next-dark") {
|
||||
return `${assetPath}/stylesheets/theme-next-dark.css`;
|
||||
} else if (!process.env.TRILIUM_SAFE_MODE && themeNote) {
|
||||
return `api/notes/download/${themeNote.noteId}`;
|
||||
}
|
||||
// baseline light theme
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ import { BootstrapDefinition } from "@triliumnext/commons";
|
||||
import { getSql } from "./sql";
|
||||
import protected_session from "./protected_session";
|
||||
import { generateCss, generateIconRegistry, getIconPacks, MIME_TO_EXTENSION_MAPPINGS } from "./icon_packs";
|
||||
import options from "./options";
|
||||
import optionService from "./options";
|
||||
import { getCurrentLocale } from "./i18n";
|
||||
import attributes from "./attributes";
|
||||
import BNote from "../becca/entities/bnote";
|
||||
|
||||
export default function getSharedBootstrapItems(assetPath: string, dbInitialized: boolean) {
|
||||
const sql = getSql();
|
||||
@@ -23,6 +24,7 @@ export default function getSharedBootstrapItems(assetPath: string, dbInitialized
|
||||
...getIconConfig(assetPath)
|
||||
};
|
||||
|
||||
// Setup not yet finished.
|
||||
if (!dbInitialized) {
|
||||
return {
|
||||
...commonItems,
|
||||
@@ -31,13 +33,19 @@ export default function getSharedBootstrapItems(assetPath: string, dbInitialized
|
||||
};
|
||||
}
|
||||
|
||||
// Database initialized.
|
||||
const options = optionService.getOptionMap();
|
||||
const theme = options.theme;
|
||||
const themeNote = attributes.getNoteWithLabel("appTheme", theme);
|
||||
return {
|
||||
...commonItems,
|
||||
headingStyle: options.getOption("headingStyle") as "plain" | "underline" | "markdown",
|
||||
layoutOrientation: options.getOption("layoutOrientation") as "vertical" | "horizontal",
|
||||
headingStyle: options.headingStyle as "plain" | "underline" | "markdown",
|
||||
layoutOrientation: options.layoutOrientation as "vertical" | "horizontal",
|
||||
maxEntityChangeIdAtLoad: sql.getValue<number>("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
|
||||
maxEntityChangeSyncIdAtLoad: sql.getValue<number>("SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1"),
|
||||
isProtectedSessionAvailable: protected_session.isProtectedSessionAvailable(),
|
||||
themeCssUrl: getThemeCssUrl(theme, commonItems.assetPath, themeNote),
|
||||
themeUseNextAsBase: themeNote?.getAttributeValue("label", "appThemeBase") as "next" | "next-light" | "next-dark",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,3 +66,24 @@ export function getIconConfig(assetPath: string): Pick<BootstrapDefinition, "ico
|
||||
function getAppCssNoteIds() {
|
||||
return attributes.getNotesWithLabel("appCss").map((note) => note.noteId);
|
||||
}
|
||||
|
||||
function getThemeCssUrl(theme: string, assetPath: string, themeNote: BNote | null) {
|
||||
if (theme === "auto") {
|
||||
return `${assetPath}/stylesheets/theme.css`;
|
||||
} else if (theme === "light") {
|
||||
// light theme is always loaded as baseline
|
||||
return false;
|
||||
} else if (theme === "dark") {
|
||||
return `${assetPath}/stylesheets/theme-dark.css`;
|
||||
} else if (theme === "next") {
|
||||
return `${assetPath}/stylesheets/theme-next.css`;
|
||||
} else if (theme === "next-light") {
|
||||
return `${assetPath}/stylesheets/theme-next-light.css`;
|
||||
} else if (theme === "next-dark") {
|
||||
return `${assetPath}/stylesheets/theme-next-dark.css`;
|
||||
} else if (!process.env.TRILIUM_SAFE_MODE && themeNote) {
|
||||
return `api/notes/download/${themeNote.noteId}`;
|
||||
}
|
||||
// baseline light theme
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user