Refactor.

This commit is contained in:
Nuno Cruces 2022-06-28 14:25:19 +01:00
parent 1c43756a6c
commit e6b85bb427
9 changed files with 18 additions and 13 deletions

View File

@ -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))
}
}

View File

@ -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()
}
}()
}

View File

@ -1,3 +0,0 @@
package main
func killParent() {}

View File

@ -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)
}

View File

@ -0,0 +1,4 @@
package zencmd
// KillParent is internal.
func KillParent() {}

View File

@ -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 {

View File

@ -1,6 +1,6 @@
//go:build !windows && !darwin
package zenutil
package zencmd
import (
"bytes"

View File

@ -1,4 +1,4 @@
package zenutil
package zencmd
import (
"strconv"

View File

@ -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}},