Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
electron: Fix asset path on forge build
Elian Dorane72eb5f27c33
diff --git a/forge.config.cjs b/forge.config.cjsindex 8d2db5da56..3d29c84f03 100644--- a/forge.config.cjs+++ b/forge.config.cjs@@ -15,7 +15,8 @@ module.exports = {...getExtraResourcesForPlatform(),// Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS)- "translations/"+ "translations/",+ "node_modules/@highlightjs/cdn-assets/styles"],afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => {const extraResources = getExtraResourcesForPlatform();diff --git a/src/services/code_block_theme.ts b/src/services/code_block_theme.tsindex 2b0757e238..ecf59d9b3a 100644--- a/src/services/code_block_theme.ts+++ b/src/services/code_block_theme.ts@@ -7,6 +7,8 @@import fs from "fs";import themeNames from "./code_block_theme_names.json" with { type: "json" }import { t } from "i18next";+import { join } from "path";+import { getResourceDir } from "./utils.js";/*** Represents a color scheme for the code block syntax highlight.@@ -28,7 +30,7 @@ interface ColorTheme {* @returns the supported themes, grouped.*/export function listSyntaxHighlightingThemes() {- const path = "node_modules/@highlightjs/cdn-assets/styles";+ const path = join(getResourceDir(), "styles");const systemThemes = readThemesFromFileSystem(path);return {diff --git a/src/services/i18n.ts b/src/services/i18n.tsindex 84a707b89c..b36e3738a3 100644--- a/src/services/i18n.ts+++ b/src/services/i18n.ts@@ -2,10 +2,8 @@ import i18next from "i18next";import Backend from "i18next-fs-backend";import options from "./options.js";import sql_init from "./sql_init.js";-import { fileURLToPath } from "url";-import { dirname, join } from "path";-import utils from "./utils.js";-import env from "./env.js";+import { join } from "path";+import { getResourceDir } from "./utils.js";export async function initializeTranslations() {const resourceDir = getResourceDir();@@ -21,14 +19,6 @@ export async function initializeTranslations() {});}-function getResourceDir() {- if (utils.isElectron() && !env.isDev()) {- return process.resourcesPath;- } else {- return join(dirname(fileURLToPath(import.meta.url)), "..", "..");- }-}-function getCurrentLanguage() {let language;if (sql_init.isDbInitialized()) {diff --git a/src/services/utils.ts b/src/services/utils.tsindex 990df5004a..6e2cdab666 100644--- a/src/services/utils.ts+++ b/src/services/utils.ts@@ -7,6 +7,9 @@ import escape from "escape-html";import sanitize from "sanitize-filename";import mimeTypes from "mime-types";import path from "path";+import { fileURLToPath } from "url";+import env from "./env.js";+import { dirname, join } from "path";const randtoken = generator({source: 'crypto'});@@ -315,6 +318,20 @@ function isString(x: any) {return Object.prototype.toString.call(x) === "[object String]";}+/**+ * Returns the directory for resources. On Electron builds this corresponds to the `resources` subdirectory inside the distributable package.+ * On development builds, this simply refers to the root directory of the application.+ *+ * @returns the resource dir.+ */+export function getResourceDir() {+ if (isElectron() && !env.isDev()) {+ return process.resourcesPath;+ } else {+ return join(dirname(fileURLToPath(import.meta.url)), "..", "..");+ }+}+export default {randomSecureToken,randomString,