electron: Fix asset path on forge build

This commit is contained in:
Elian Doran 2024-11-02 11:49:33 +02:00
parent d1404492a7
commit e72eb5f27c
No known key found for this signature in database
4 changed files with 24 additions and 14 deletions

View File

@ -15,7 +15,8 @@ module.exports = {
...getExtraResourcesForPlatform(), ...getExtraResourcesForPlatform(),
// Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS) // Moved to resources (TriliumNext Notes.app/Contents/Resources on macOS)
"translations/" "translations/",
"node_modules/@highlightjs/cdn-assets/styles"
], ],
afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => { afterComplete: [(buildPath, _electronVersion, platform, _arch, callback) => {
const extraResources = getExtraResourcesForPlatform(); const extraResources = getExtraResourcesForPlatform();

View File

@ -7,6 +7,8 @@
import fs from "fs"; import fs from "fs";
import themeNames from "./code_block_theme_names.json" with { type: "json" } import themeNames from "./code_block_theme_names.json" with { type: "json" }
import { t } from "i18next"; import { t } from "i18next";
import { join } from "path";
import { getResourceDir } from "./utils.js";
/** /**
* Represents a color scheme for the code block syntax highlight. * Represents a color scheme for the code block syntax highlight.
@ -28,7 +30,7 @@ interface ColorTheme {
* @returns the supported themes, grouped. * @returns the supported themes, grouped.
*/ */
export function listSyntaxHighlightingThemes() { export function listSyntaxHighlightingThemes() {
const path = "node_modules/@highlightjs/cdn-assets/styles"; const path = join(getResourceDir(), "styles");
const systemThemes = readThemesFromFileSystem(path); const systemThemes = readThemesFromFileSystem(path);
return { return {

View File

@ -2,10 +2,8 @@ import i18next from "i18next";
import Backend from "i18next-fs-backend"; import Backend from "i18next-fs-backend";
import options from "./options.js"; import options from "./options.js";
import sql_init from "./sql_init.js"; import sql_init from "./sql_init.js";
import { fileURLToPath } from "url"; import { join } from "path";
import { dirname, join } from "path"; import { getResourceDir } from "./utils.js";
import utils from "./utils.js";
import env from "./env.js";
export async function initializeTranslations() { export async function initializeTranslations() {
const resourceDir = getResourceDir(); 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() { function getCurrentLanguage() {
let language; let language;
if (sql_init.isDbInitialized()) { if (sql_init.isDbInitialized()) {

View File

@ -7,6 +7,9 @@ import escape from "escape-html";
import sanitize from "sanitize-filename"; import sanitize from "sanitize-filename";
import mimeTypes from "mime-types"; import mimeTypes from "mime-types";
import path from "path"; import path from "path";
import { fileURLToPath } from "url";
import env from "./env.js";
import { dirname, join } from "path";
const randtoken = generator({source: 'crypto'}); const randtoken = generator({source: 'crypto'});
@ -315,6 +318,20 @@ function isString(x: any) {
return Object.prototype.toString.call(x) === "[object String]"; 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 { export default {
randomSecureToken, randomSecureToken,
randomString, randomString,