electron: Fix code block theme loading in dev mode

This commit is contained in:
Elian Doran 2024-11-07 20:36:33 +02:00
parent 930b8e0ce2
commit f5205fdd30
No known key found for this signature in database

View File

@ -9,6 +9,7 @@ import themeNames from "./code_block_theme_names.json" with { type: "json" }
import { t } from "i18next"; import { t } from "i18next";
import { join } from "path"; import { join } from "path";
import utils from "./utils.js"; import utils from "./utils.js";
import env from "./env.js";
/** /**
* Represents a color scheme for the code block syntax highlight. * Represents a color scheme for the code block syntax highlight.
@ -30,8 +31,7 @@ interface ColorTheme {
* @returns the supported themes, grouped. * @returns the supported themes, grouped.
*/ */
export function listSyntaxHighlightingThemes() { export function listSyntaxHighlightingThemes() {
const stylesDir = (!utils.isElectron() ? "node_modules/@highlightjs/cdn-assets/styles" : "styles"); const path = join(utils.getResourceDir(), getStylesDirectory());
const path = join(utils.getResourceDir(), stylesDir);
const systemThemes = readThemesFromFileSystem(path); const systemThemes = readThemesFromFileSystem(path);
return { return {
@ -45,6 +45,14 @@ export function listSyntaxHighlightingThemes() {
} }
} }
function getStylesDirectory() {
if (utils.isElectron() && !env.isDev()) {
return "styles";
}
return "node_modules/@highlightjs/cdn-assets/styles";
}
/** /**
* Reads all the predefined themes by listing all minified CSSes from a given directory. * Reads all the predefined themes by listing all minified CSSes from a given directory.
* *