A local-first personal finance app
:electron: Fix "Unknown problem opening <local actual file>" on Electron (#3220)
Michael Clark6f3af7b609db
diff --git a/bin/package-electron b/bin/package-electronindex 4d0f317631..b827d0015a 100755--- a/bin/package-electron+++ b/bin/package-electron@@ -34,8 +34,6 @@ if [ "$OSTYPE" == "msys" ]; thenfifi-yarn rebuild-electron-yarn workspace loot-core build:nodeyarn workspace @actual-app/web build --mode=desktop@@ -50,10 +48,10 @@ yarn workspace desktop-electron update-clientif [ -f ../../.secret-tokens ]; thensource ../../.secret-tokensfi- yarn build --publish never --arm64 --x64+ yarn buildecho "\nCreated release"else- SKIP_NOTARIZATION=true yarn build --publish never --x64+ SKIP_NOTARIZATION=true yarn buildfi)diff --git a/packages/desktop-electron/beforePackHook.ts b/packages/desktop-electron/beforePackHook.tsnew file mode 100644index 0000000000..3446378e70--- /dev/null+++ b/packages/desktop-electron/beforePackHook.ts@@ -0,0 +1,36 @@+import { rebuild } from '@electron/rebuild';+import { Arch, AfterPackContext } from 'electron-builder';++/* The beforePackHook runs before packing the Electron app for an architecture+We hook in here to build anything architecture dependent - such as beter-sqlite3+To build, we call @electron/rebuild on the better-sqlite3 module */+const beforePackHook = async (context: AfterPackContext) => {+ const arch: string = Arch[context.arch];+ const buildPath = context.packager.projectDir;+ const projectRootPath = buildPath + '/../../';+ const electronVersion = context.packager.config.electronVersion;++ if (!electronVersion) {+ console.error('beforePackHook: Unable to find electron version.');+ process.exit(); // End the process - electron version is required+ }++ try {+ await rebuild({+ arch,+ buildPath,+ electronVersion,+ force: true,+ projectRootPath,+ onlyModules: ['better-sqlite3'],+ });++ console.info(`Rebuilt better-sqlite3 with ${arch}!`);+ } catch (err) {+ console.error('beforePackHook:', err);+ process.exit(); // End the process - unsuccessful build+ }+};++// eslint-disable-next-line import/no-unused-modules, import/no-default-export+export default beforePackHook;diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.jsonindex 851d28f42e..327f1990f8 100644--- a/packages/desktop-electron/package.json+++ b/packages/desktop-electron/package.json@@ -24,26 +24,22 @@"!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}","build"],- "publish": {- "provider": "github",- "repo": "actual",- "owner": "actualbudget",- "vPrefixedTagName": true- },+ "beforePack": "./build/beforePackHook.js","mac": {"category": "public.app-category.finance","icon": "icons/icon.icns","hardenedRuntime": true,"gatekeeperAssess": false,- "artifactName": "${productName}-mac.${ext}",+ "artifactName": "${productName}-mac-${arch}.${ext}","notarize": {"teamId": "79ANZ983YF"},"target": [{- "target": "default",+ "target": "dmg","arch": [- "universal"+ "x64",+ "arm64"]}]@@ -63,7 +59,8 @@"target": "nsis","icon": "icons/icon.ico","artifactName": "${productName}-windows.${ext}"- }+ },+ "npmRebuild": false},"dependencies": {"electron-is-dev": "2.0.0",diff --git a/upcoming-release-notes/3220.md b/upcoming-release-notes/3220.mdnew file mode 100644index 0000000000..4db0be806d--- /dev/null+++ b/upcoming-release-notes/3220.md@@ -0,0 +1,7 @@+---+category: Bugfix+authors: [MikesGlitch]+---++Fix electron builds throwing "We had an unknown problem opening file"+