Merge pull request #305344 from jlbribeiro/feishin-0.6.1-darwin

feishin: fix darwin builds
This commit is contained in:
Weijia Wang 2024-04-30 16:37:56 +02:00 committed by GitHub
commit 1bff3cee73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 79 additions and 42 deletions

View file

@ -9452,6 +9452,12 @@
fingerprint = "B768 6CD7 451A 650D 9C54 4204 6710 CF0C 1CBD 7762"; fingerprint = "B768 6CD7 451A 650D 9C54 4204 6710 CF0C 1CBD 7762";
}]; }];
}; };
jlbribeiro = {
email = "nix@jlbribeiro.com";
github = "jlbribeiro";
githubId = 1015816;
name = "José Ribeiro";
};
jleightcap = { jleightcap = {
email = "jack@leightcap.com"; email = "jack@leightcap.com";
github = "jleightcap"; github = "jleightcap";

View file

@ -1,8 +1,10 @@
{ {
lib, lib,
stdenv,
buildNpmPackage, buildNpmPackage,
fetchFromGitHub, fetchFromGitHub,
electron_27, electron_27,
darwin,
copyDesktopItems, copyDesktopItems,
makeDesktopItem, makeDesktopItem,
... ...
@ -21,8 +23,7 @@ let
electron = electron_27; electron = electron_27;
in in
buildNpmPackage { buildNpmPackage {
pname = "feishin"; inherit pname version;
inherit version;
inherit src; inherit src;
npmDepsHash = "sha256-+pr9fWg/9kxkYMmthtqhjgF6MOomSQxVCO5V8tHHRdE="; npmDepsHash = "sha256-+pr9fWg/9kxkYMmthtqhjgF6MOomSQxVCO5V8tHHRdE=";
@ -32,13 +33,21 @@ buildNpmPackage {
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
nativeBuildInputs = [ copyDesktopItems ]; nativeBuildInputs =
lib.optionals (stdenv.isLinux) [ copyDesktopItems ]
++ lib.optionals stdenv.isDarwin [ darwin.autoSignDarwinBinariesHook ];
postPatch = '' postPatch =
''
# release/app dependencies are installed on preConfigure # release/app dependencies are installed on preConfigure
substituteInPlace package.json \ substituteInPlace package.json \
--replace-fail "electron-builder install-app-deps &&" "" --replace-fail "electron-builder install-app-deps &&" ""
# Don't check for updates.
substituteInPlace src/main/main.ts \
--replace-fail "autoUpdater.checkForUpdatesAndNotify();" ""
''
+ lib.optionalString stdenv.isLinux ''
# https://github.com/electron/electron/issues/31121 # https://github.com/electron/electron/issues/31121
substituteInPlace src/main/main.ts \ substituteInPlace src/main/main.ts \
--replace-fail "process.resourcesPath" "'$out/share/feishin/resources'" --replace-fail "process.resourcesPath" "'$out/share/feishin/resources'"
@ -67,17 +76,35 @@ buildNpmPackage {
done done
''; '';
postBuild = '' postBuild =
lib.optionalString stdenv.isDarwin ''
# electron-builder appears to build directly on top of Electron.app, by overwriting the files in the bundle.
cp -r ${electron}/Applications/Electron.app ./
find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw
# Disable code signing during build on macOS.
# https://github.com/electron-userland/electron-builder/blob/fa6fc16/docs/code-signing.md#how-to-disable-code-signing-during-the-build-process-on-macos
export CSC_IDENTITY_AUTO_DISCOVERY=false
sed -i "/afterSign/d" package.json
''
+ ''
npm exec electron-builder -- \ npm exec electron-builder -- \
--dir \ --dir \
-c.electronDist=${electron}/libexec/electron \ -c.electronDist=${if stdenv.isDarwin then "./" else "${electron}/libexec/electron"} \
-c.electronVersion=${electron.version} \ -c.electronVersion=${electron.version} \
-c.npmRebuild=false -c.npmRebuild=false
''; '';
installPhase = '' installPhase =
''
runHook preInstall runHook preInstall
''
+ lib.optionalString stdenv.isDarwin ''
mkdir -p $out/{Applications,bin}
cp -r release/build/**/Feishin.app $out/Applications/
makeWrapper $out/Applications/Feishin.app/Contents/MacOS/Feishin $out/bin/feishin
''
+ lib.optionalString stdenv.isLinux ''
mkdir -p $out/share/feishin mkdir -p $out/share/feishin
pushd release/build/*/ pushd release/build/*/
cp -r locales resources{,.pak} $out/share/feishin cp -r locales resources{,.pak} $out/share/feishin
@ -98,7 +125,8 @@ buildNpmPackage {
$out/share/feishin/resources/assets/icons/"$size"x"$size".png \ $out/share/feishin/resources/assets/icons/"$size"x"$size".png \
$out/share/icons/hicolor/"$size"x"$size"/apps/${pname}.png $out/share/icons/hicolor/"$size"x"$size"/apps/${pname}.png
done done
''
+ ''
runHook postInstall runHook postInstall
''; '';
@ -125,6 +153,9 @@ buildNpmPackage {
license = licenses.gpl3Plus; license = licenses.gpl3Plus;
platforms = platforms.unix; platforms = platforms.unix;
mainProgram = "feishin"; mainProgram = "feishin";
maintainers = with maintainers; [ onny ]; maintainers = with maintainers; [
onny
jlbribeiro
];
}; };
} }