From f5205fdd30685b36db90d947a77875bf51dd7a09 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 7 Nov 2024 20:36:33 +0200 Subject: [PATCH] electron: Fix code block theme loading in dev mode --- src/services/code_block_theme.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/code_block_theme.ts b/src/services/code_block_theme.ts index 037df7be5..e92199e74 100644 --- a/src/services/code_block_theme.ts +++ b/src/services/code_block_theme.ts @@ -9,6 +9,7 @@ import themeNames from "./code_block_theme_names.json" with { type: "json" } import { t } from "i18next"; import { join } from "path"; import utils from "./utils.js"; +import env from "./env.js"; /** * Represents a color scheme for the code block syntax highlight. @@ -30,8 +31,7 @@ interface ColorTheme { * @returns the supported themes, grouped. */ export function listSyntaxHighlightingThemes() { - const stylesDir = (!utils.isElectron() ? "node_modules/@highlightjs/cdn-assets/styles" : "styles"); - const path = join(utils.getResourceDir(), stylesDir); + const path = join(utils.getResourceDir(), getStylesDirectory()); const systemThemes = readThemesFromFileSystem(path); 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. *