From e6b85bb427fc0b4dcc70e8f19579982c3f28452b Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Tue, 28 Jun 2022 14:25:19 +0100 Subject: [PATCH] Refactor. --- cmd/zenity/main.go | 4 ++-- cmd/zenity/progress.go | 3 ++- cmd/zenity/progress_windows.go | 3 --- .../progress_unix.go => internal/zencmd/process_unix.go | 5 +++-- internal/zencmd/process_windows.go | 4 ++++ internal/{zenutil => zencmd}/window_darwin.go | 4 +++- internal/{zenutil => zencmd}/window_unix.go | 2 +- internal/{zenutil => zencmd}/window_windows.go | 2 +- zenity_test.go | 4 ++-- 9 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 cmd/zenity/progress_windows.go rename cmd/zenity/progress_unix.go => internal/zencmd/process_unix.go (62%) create mode 100644 internal/zencmd/process_windows.go rename internal/{zenutil => zencmd}/window_darwin.go (92%) rename internal/{zenutil => zencmd}/window_unix.go (99%) rename internal/{zenutil => zencmd}/window_windows.go (94%) diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index 60473ad..31aae19 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -450,9 +450,9 @@ func loadFlags() []zenity.Option { } if attach != "" { - opts = append(opts, zenity.Attach(zenutil.ParseWindowId(attach))) + opts = append(opts, zenity.Attach(zencmd.ParseWindowId(attach))) } else if modal { - if id := zenutil.GetParentWindowId(os.Getppid()); id != 0 { + if id := zencmd.GetParentWindowId(os.Getppid()); id != 0 { opts = append(opts, zenity.Attach(id)) } } diff --git a/cmd/zenity/progress.go b/cmd/zenity/progress.go index d545b56..a2f2d59 100644 --- a/cmd/zenity/progress.go +++ b/cmd/zenity/progress.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/ncruces/zenity" + "github.com/ncruces/zenity/internal/zencmd" ) func progress(opts ...zenity.Option) (err error) { @@ -21,7 +22,7 @@ func progress(opts ...zenity.Option) (err error) { if autoKill { defer func() { if err == zenity.ErrCanceled { - killParent() + zencmd.KillParent() } }() } diff --git a/cmd/zenity/progress_windows.go b/cmd/zenity/progress_windows.go deleted file mode 100644 index 6563f08..0000000 --- a/cmd/zenity/progress_windows.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -func killParent() {} diff --git a/cmd/zenity/progress_unix.go b/internal/zencmd/process_unix.go similarity index 62% rename from cmd/zenity/progress_unix.go rename to internal/zencmd/process_unix.go index b6769ba..adb43d3 100644 --- a/cmd/zenity/progress_unix.go +++ b/internal/zencmd/process_unix.go @@ -1,12 +1,13 @@ //go:build darwin || dev -package main +package zencmd import ( "os" "syscall" ) -func killParent() { +// KillParent is internal. +func KillParent() { syscall.Kill(os.Getppid(), syscall.SIGHUP) } diff --git a/internal/zencmd/process_windows.go b/internal/zencmd/process_windows.go new file mode 100644 index 0000000..f279430 --- /dev/null +++ b/internal/zencmd/process_windows.go @@ -0,0 +1,4 @@ +package zencmd + +// KillParent is internal. +func KillParent() {} diff --git a/internal/zenutil/window_darwin.go b/internal/zencmd/window_darwin.go similarity index 92% rename from internal/zenutil/window_darwin.go rename to internal/zencmd/window_darwin.go index acdbcee..70ab603 100644 --- a/internal/zenutil/window_darwin.go +++ b/internal/zencmd/window_darwin.go @@ -1,4 +1,4 @@ -package zenutil +package zencmd import ( "strconv" @@ -6,6 +6,8 @@ import ( "golang.org/x/sys/unix" ) +type any = interface{} + // ParseWindowId is internal. func ParseWindowId(id string) any { if pid, err := strconv.ParseUint(id, 0, 64); err == nil { diff --git a/internal/zenutil/window_unix.go b/internal/zencmd/window_unix.go similarity index 99% rename from internal/zenutil/window_unix.go rename to internal/zencmd/window_unix.go index a95cd3c..c20fe3b 100644 --- a/internal/zenutil/window_unix.go +++ b/internal/zencmd/window_unix.go @@ -1,6 +1,6 @@ //go:build !windows && !darwin -package zenutil +package zencmd import ( "bytes" diff --git a/internal/zenutil/window_windows.go b/internal/zencmd/window_windows.go similarity index 94% rename from internal/zenutil/window_windows.go rename to internal/zencmd/window_windows.go index b92d98d..24ff5fe 100644 --- a/internal/zenutil/window_windows.go +++ b/internal/zencmd/window_windows.go @@ -1,4 +1,4 @@ -package zenutil +package zencmd import ( "strconv" diff --git a/zenity_test.go b/zenity_test.go index 5b57d47..9ca6c85 100644 --- a/zenity_test.go +++ b/zenity_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/ncruces/zenity/internal/zenutil" + "github.com/ncruces/zenity/internal/zencmd" ) func Test_applyOptions(t *testing.T) { @@ -30,7 +30,7 @@ func Test_applyOptions(t *testing.T) { {name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}}, {name: "Icon", args: Icon("error"), want: options{icon: "error"}}, {name: "Modal", args: Modal(), want: options{modal: true}}, - {name: "Attach", args: Attach(zenutil.ParseWindowId("12345")), want: options{attach: zenutil.ParseWindowId("12345")}}, + {name: "Attach", args: Attach(zencmd.ParseWindowId("12345")), want: options{attach: zencmd.ParseWindowId("12345")}}, // Message options {name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},