Refactor.
This commit is contained in:
parent
1c43756a6c
commit
e6b85bb427
9 changed files with 18 additions and 13 deletions
|
@ -450,9 +450,9 @@ func loadFlags() []zenity.Option {
|
||||||
}
|
}
|
||||||
|
|
||||||
if attach != "" {
|
if attach != "" {
|
||||||
opts = append(opts, zenity.Attach(zenutil.ParseWindowId(attach)))
|
opts = append(opts, zenity.Attach(zencmd.ParseWindowId(attach)))
|
||||||
} else if modal {
|
} 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))
|
opts = append(opts, zenity.Attach(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ncruces/zenity"
|
"github.com/ncruces/zenity"
|
||||||
|
"github.com/ncruces/zenity/internal/zencmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func progress(opts ...zenity.Option) (err error) {
|
func progress(opts ...zenity.Option) (err error) {
|
||||||
|
@ -21,7 +22,7 @@ func progress(opts ...zenity.Option) (err error) {
|
||||||
if autoKill {
|
if autoKill {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == zenity.ErrCanceled {
|
if err == zenity.ErrCanceled {
|
||||||
killParent()
|
zencmd.KillParent()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
func killParent() {}
|
|
|
@ -1,12 +1,13 @@
|
||||||
//go:build darwin || dev
|
//go:build darwin || dev
|
||||||
|
|
||||||
package main
|
package zencmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func killParent() {
|
// KillParent is internal.
|
||||||
|
func KillParent() {
|
||||||
syscall.Kill(os.Getppid(), syscall.SIGHUP)
|
syscall.Kill(os.Getppid(), syscall.SIGHUP)
|
||||||
}
|
}
|
4
internal/zencmd/process_windows.go
Normal file
4
internal/zencmd/process_windows.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package zencmd
|
||||||
|
|
||||||
|
// KillParent is internal.
|
||||||
|
func KillParent() {}
|
|
@ -1,4 +1,4 @@
|
||||||
package zenutil
|
package zencmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -6,6 +6,8 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type any = interface{}
|
||||||
|
|
||||||
// ParseWindowId is internal.
|
// ParseWindowId is internal.
|
||||||
func ParseWindowId(id string) any {
|
func ParseWindowId(id string) any {
|
||||||
if pid, err := strconv.ParseUint(id, 0, 64); err == nil {
|
if pid, err := strconv.ParseUint(id, 0, 64); err == nil {
|
|
@ -1,6 +1,6 @@
|
||||||
//go:build !windows && !darwin
|
//go:build !windows && !darwin
|
||||||
|
|
||||||
package zenutil
|
package zencmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package zenutil
|
package zencmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ncruces/zenity/internal/zenutil"
|
"github.com/ncruces/zenity/internal/zencmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_applyOptions(t *testing.T) {
|
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(ErrorIcon), want: options{icon: ErrorIcon}},
|
||||||
{name: "Icon", args: Icon("error"), want: options{icon: "error"}},
|
{name: "Icon", args: Icon("error"), want: options{icon: "error"}},
|
||||||
{name: "Modal", args: Modal(), want: options{modal: true}},
|
{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
|
// Message options
|
||||||
{name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},
|
{name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},
|
||||||
|
|
Loading…
Reference in a new issue