Skip to content

Commit

Permalink
:electron: Fix "Unknown problem opening <local actual file>" on Electron (#3220)
Browse files Browse the repository at this point in the history
* add electron logging to main browser process console

* add logging

* removing old way

* release notes

* adding some logs in to test mac build

* repent satan

* i caste yeee oooott sinner

* derp

* hmmm<

* forcing nodegyprebuild

* not like this.... Not like this... 😢

* hmm

* dunno

* will it recognise it if i link it manually.. 👀

* give up

* rebuild

* merge asars fasle

* update package

* manually do it ffs work damnit

* remove the cmd

* dont rebuild cause i build it manually

* dafuq is this, two bettersqlite modules installed huhhhhh

* test

* does this work?

* bloody hell

* couple more logs

* test this out

* arch in name

* adding the rebuild step back into first build

* try rebuild before pack - so we know what arch we need

* having a laugh

* tidying up

* release notes

* move package up a bit

* exit process if no electron verison
  • Loading branch information
MikesGlitch authored Aug 12, 2024
1 parent 43ff1c0 commit 6f3af7b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
6 changes: 2 additions & 4 deletions bin/package-electron
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ if [ "$OSTYPE" == "msys" ]; then
fi
fi

yarn rebuild-electron

yarn workspace loot-core build:node

yarn workspace @actual-app/web build --mode=desktop
Expand All @@ -50,10 +48,10 @@ yarn workspace desktop-electron update-client
if [ -f ../../.secret-tokens ]; then
source ../../.secret-tokens
fi
yarn build --publish never --arm64 --x64
yarn build

echo "\nCreated release"
else
SKIP_NOTARIZATION=true yarn build --publish never --x64
SKIP_NOTARIZATION=true yarn build
fi
)
36 changes: 36 additions & 0 deletions packages/desktop-electron/beforePackHook.ts
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 7 additions & 10 deletions packages/desktop-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand All @@ -63,7 +59,8 @@
"target": "nsis",
"icon": "icons/icon.ico",
"artifactName": "${productName}-windows.${ext}"
}
},
"npmRebuild": false
},
"dependencies": {
"electron-is-dev": "2.0.0",
Expand Down
7 changes: 7 additions & 0 deletions upcoming-release-notes/3220.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
category: Bugfix
authors: [MikesGlitch]
---

Fix electron builds throwing "We had an unknown problem opening file"

0 comments on commit 6f3af7b

Please sign in to comment.