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
refactor(flatpak): share the Electron fuse hardening with the forge config
Elian Doran64b8b29b3d90
diff --git a/apps/desktop/electron-forge/flip-fuses.ts b/apps/desktop/electron-forge/flip-fuses.tsnew file mode 100644index 0000000000..6ea6dab4a9--- /dev/null+++ b/apps/desktop/electron-forge/flip-fuses.ts@@ -0,0 +1,34 @@+/**+ * The Electron fuse hardening shared by every packaged build. electron-forge+ * burns {@link FUSES} in through its fuses plugin, layering the two asar+ * fuses on top in forge.config.ts; the Flathub build, which loads the app+ * from a plain directory the asar fuses would forbid, runs this file as a+ * script, with tsx, to flip the set on its unpacked Electron binary.+ */++import type { FuseConfig } from "@electron/fuses";+import { flipFuses, FuseV1Options, FuseVersion } from "@electron/fuses";++export const FUSES: FuseConfig = {+ version: FuseVersion.V1,+ [FuseV1Options.RunAsNode]: false,+ [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,+ [FuseV1Options.EnableNodeCliInspectArguments]: false,+ [FuseV1Options.EnableCookieEncryption]: true,+ [FuseV1Options.GrantFileProtocolExtraPrivileges]: false+};++// Only when run as a script — the Flathub build passes its unpacked Electron binary.+if (process.argv[1] === import.meta.filename) {+ const binaryPath = process.argv[2];+ if (!binaryPath) {+ throw new Error("Pass the Electron binary to flip fuses on.");+ }+ flipFuses(binaryPath, FUSES).then(+ () => console.log(`Flipped fuses on ${binaryPath}`),+ (err) => {+ console.error(err);+ process.exit(1);+ }+ );+}diff --git a/apps/desktop/electron-forge/forge.config.ts b/apps/desktop/electron-forge/forge.config.tsindex 94feb2044d..393228d783 100644--- a/apps/desktop/electron-forge/forge.config.ts+++ b/apps/desktop/electron-forge/forge.config.ts@@ -1,5 +1,6 @@import type { ForgeConfig } from "@electron-forge/shared-types";-import { FuseV1Options, FuseVersion } from "@electron/fuses";+import { FuseV1Options } from "@electron/fuses";+import { FUSES } from "./flip-fuses.js";import { trimElectronLocales } from "./trim-locales.js";import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync } from "fs";import path, { join } from "path";@@ -189,13 +190,9 @@ const config: ForgeConfig = {{name: "@electron-forge/plugin-fuses",config: {- version: FuseVersion.V1,- [FuseV1Options.RunAsNode]: false,- [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,- [FuseV1Options.EnableNodeCliInspectArguments]: false,- [FuseV1Options.EnableCookieEncryption]: true,+ ...FUSES,+ // The forge builds package the app into an asar archive; the Flathub build has none.[FuseV1Options.OnlyLoadAppFromAsar]: true,- [FuseV1Options.GrantFileProtocolExtraPrivileges]: false,[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true}}