Skip to content

Commit

Permalink
gui-for-clash: 1.8.9 -> 1.9.0 (#368129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ck3d authored Dec 30, 2024
2 parents 1d0dac5 + 45ab4bd commit 850cb52
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
39 changes: 39 additions & 0 deletions pkgs/by-name/gu/gui-for-clash/bridge.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- a/bridge/bridge.go 2024-12-25 20:53:45.504021585 +0000
+++ b/bridge/bridge.go 2024-12-25 21:02:20.318422528 +0000
@@ -38,11 +38,6 @@

func InitBridge(fs embed.FS) {
// step1: Set Env
- exePath, err := os.Executable()
- if err != nil {
- panic(err)
- }
-
for _, v := range os.Args {
if v == "tasksch" {
Env.FromTaskSch = true
@@ -50,8 +45,13 @@
}
}

- Env.BasePath = filepath.Dir(exePath)
- Env.AppName = filepath.Base(exePath)
+ Env.AppName = "GUI.for.Clash"
+ xdgDataHome := os.Getenv("XDG_DATA_HOME")
+ if xdgDataHome == "" {
+ homeDir, _ := os.UserHomeDir()
+ xdgDataHome = filepath.Join(homeDir, ".local", "share")
+ }
+ Env.BasePath = filepath.Join(xdgDataHome, Env.AppName)

// step2: Create a persistent data symlink
if Env.OS == "darwin" {
@@ -128,7 +128,7 @@
}

func (a *App) RestartApp() FlagResult {
- exePath := Env.BasePath + "/" + Env.AppName
+ exePath := "@basepath@/bin" + "/" + Env.AppName

cmd := exec.Command(exePath)
HideExecWindow(cmd)
48 changes: 22 additions & 26 deletions pkgs/by-name/gu/gui-for-clash/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@
webkitgtk_4_0,
pkg-config,
libsoup_3,
wrapGAppsHook3,
autoPatchelfHook,
makeDesktopItem,
copyDesktopItems,
replaceVars,
}:
let
pname = "gui-for-clash";
version = "1.8.9";
version = "1.9.0";

src = fetchFromGitHub {
owner = "GUI-for-Cores";
repo = "GUI.for.Clash";
rev = "v${version}";
hash = "sha256-jNYMv3gPbZV2JlTV0v0NQ06HkXDzgHXuEdJrBgQ+p2g=";
tag = "v${version}";
hash = "sha256-0PNFiOZ+POp1P/HDJmAIMKNGIjft6bfwPiRDLswY2ns=";
};

frontend = stdenv.mkDerivation (finalAttrs: {
inherit pname version src;

Expand All @@ -34,24 +36,23 @@ let
pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname version src;
sourceRoot = "${finalAttrs.src.name}/frontend";
hash = "sha256-RQtU61H1YklCgJrlyHALxUZp8OvVs2MgFThWBsYk2cs=";
hash = "sha256-mG8b16PP876EyaX3Sc4WM41Yc/oDGZDiilZPaxPvvuQ=";
};

sourceRoot = "${finalAttrs.src.name}/frontend";

buildPhase = ''
runHook preBuild
pnpm run build
pnpm run build-only
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir $out/
cp -r ./dist/* $out/
cp -r ./dist $out
runHook postInstall
'';
Expand All @@ -67,12 +68,17 @@ in
buildGoModule {
inherit pname version src;

vendorHash = "sha256-rDbJOj8t/qu04Rd8J0LnXiBoIDmdzBQ9avAhImK7dFg=";
patches = [
(replaceVars ./bridge.patch {
basepath = placeholder "out";
})
];

vendorHash = "sha256-OrysyJF+lUMf+0vWmOZHjxUdE6fQCKArmpV4alXxtYs=";

nativeBuildInputs = [
wails
pkg-config
wrapGAppsHook3
autoPatchelfHook
copyDesktopItems
];
Expand All @@ -84,9 +90,9 @@ buildGoModule {

desktopItems = [
(makeDesktopItem {
name = "GUI.for.Clash";
name = "gui-for-clash";
exec = "GUI.for.Clash";
icon = "GUI.for.Clash";
icon = "gui-for-clash";
genericName = "GUI.for.Clash";
desktopName = "GUI.for.Clash";
categories = [
Expand All @@ -98,17 +104,8 @@ buildGoModule {
})
];

postUnpack = ''
cp -r ${frontend} $sourceRoot/frontend/dist
'';

postPatch = ''
sed -i '/exePath, err := os.Executable()/,+3d' bridge/bridge.go
substituteInPlace bridge/bridge.go \
--replace-fail "Env.BasePath = filepath.Dir(exePath)" "" \
--replace-fail "Env.AppName = filepath.Base(exePath)" "Env.AppName = \"GUI.for.Clash\"
Env.BasePath = filepath.Join(os.Getenv(\"HOME\"), \".config\", Env.AppName)" \
--replace-fail 'exePath := Env.BasePath' 'exePath := "${placeholder "out"}/bin"'
preBuild = ''
cp -r ${frontend} ./frontend/dist
'';

buildPhase = ''
Expand All @@ -122,9 +119,8 @@ buildGoModule {
installPhase = ''
runHook preInstall
mkdir -p $out/share/pixmaps
cp -r ./build/bin $out/bin
cp build/appicon.png $out/share/pixmaps/GUI.for.Clash.png
install -Dm 0755 ./build/bin/GUI.for.Clash $out/bin/GUI.for.Clash
install -Dm 0644 build/appicon.png $out/share/pixmaps/gui-for-clash.png
runHook postInstall
'';
Expand Down

0 comments on commit 850cb52

Please sign in to comment.