Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove console-window code #300

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ documentation support. This project succeeds because of them. Thank you!
[![Docker Cloud](https://docs.golift.io/integrations/docker.png "Docker Cloud")](https://cloud.docker.com)
[![Homebrew](https://docs.golift.io/integrations/homebrew.png "Homebrew")](https://brew.sh)
[![Go Lift](https://docs.golift.io/integrations/golift.png "Go Lift")](https://golift.io)
[![CloudFlare](https://docs.golift.io/integrations/cloudflare.png "CloudFlare")](https://cloudflare.com)

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion examples/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ AUTHOR

LOCATION
---
* [github.com/Unpackerr/unpackerr](https://github.com/Unpackerr/unpackerr)
* [unpackerr.zip](https://unpackerr.zip)
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d
github.com/getlantern/systray v1.2.2
github.com/gonutz/w32 v1.0.0
github.com/gonutz/w32/v2 v2.9.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/julienschmidt/httprouter v1.3.0
github.com/lestrrat-go/apache-logformat/v2 v2.0.6
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/gonutz/w32 v1.0.0 h1:3t1z6ZfkFvirjFYBx9pHeHBuKoN/VBVk9yHb/m2Ll/k=
github.com/gonutz/w32 v1.0.0/go.mod h1:Rc/YP5K9gv0FW4p6X9qL3E7Y56lfMflEol1fLElfMW4=
github.com/gonutz/w32/v2 v2.9.0/go.mod h1:MgtHx0AScDVNKyB+kjyPder4xIi3XAcHS6LDDU2DmdE=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -183,8 +180,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c h1:zqmyTlQyufRC65JnImJ6H1Sf7BDj8bG31EV919NVEQc=
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import (

// Keep it simple.
func main() {
ui.HideConsoleWindow()

defer func() {
if r := recover(); r != nil {
ui.ShowConsoleWindow()
log.Printf("[PANIC] %v\n%s", r, string(debug.Stack()))
}
}()
Expand Down
6 changes: 0 additions & 6 deletions pkg/ui/ui_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ func HasGUI() bool {
return hasGUI
}

// HideConsoleWindow does nothing on OSes besides Windows.
func HideConsoleWindow() {}

// ShowConsoleWindow does nothing on OSes besides Windows.
func ShowConsoleWindow() {}

// StartCmd starts a command.
func StartCmd(c string, v ...string) error {
cmd := exec.Command(c, v...)
Expand Down
6 changes: 0 additions & 6 deletions pkg/ui/ui_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ func HasGUI() bool {
return false
}

// HideConsoleWindow does nothing on OSes besides Windows.
func HideConsoleWindow() {}

// ShowConsoleWindow does nothing on OSes besides Windows.
func ShowConsoleWindow() {}

// StartCmd starts a command.
func StartCmd(c string, v ...string) error {
cmd := exec.Command(c, v...)
Expand Down
22 changes: 0 additions & 22 deletions pkg/ui/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"os/exec"
"strings"
"syscall"

"github.com/gonutz/w32"
)

// SystrayIcon is the icon in the system tray or task bar.
Expand All @@ -20,26 +18,6 @@ func HasGUI() bool {
return hasGUI
}

// HideConsoleWindow hides the windows console window.
func HideConsoleWindow() {
if console := w32.GetConsoleWindow(); console != 0 {
_, consoleProcID := w32.GetWindowThreadProcessId(console)
if w32.GetCurrentProcessId() == consoleProcID {
w32.ShowWindowAsync(console, w32.SW_HIDE)
}
}
}

// ShowConsoleWindow does nothing on OSes besides Windows.
func ShowConsoleWindow() {
if console := w32.GetConsoleWindow(); console != 0 {
_, consoleProcID := w32.GetWindowThreadProcessId(console)
if w32.GetCurrentProcessId() == consoleProcID {
w32.ShowWindowAsync(console, w32.SW_SHOW)
}
}
}

// StartCmd starts a command.
func StartCmd(c string, v ...string) error {
cmd := exec.Command(c, v...)
Expand Down
16 changes: 14 additions & 2 deletions pkg/unpackerr/cnfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@ const (
func (u *Unpackerr) unmarshalConfig() (uint64, uint64, string, error) {
var f, msg string

// Load up the default file path and a list of alternate paths.
def, cfl := configFileLocactions()
// Search for one, starting with the default.
for _, f = range append([]string{u.Flags.ConfigFile}, cfl...) {
d, err := homedir.Expand(f)
if err == nil {
f = d
}

if _, err := os.Stat(f); err == nil {
break
break // found one, bail out.
} // else { u.Print("rip:", err) }

f = ""
}

// it's possible to get here with or without a file found.
msg = msgNoConfigFile

if f != "" {
Expand Down Expand Up @@ -93,6 +96,7 @@ func configFileLocactions() (string, []string) {
case "android", "dragonfly", "linux", "nacl", "plan9", "solaris":
fallthrough
default:
// Adding a default here, or to freebsd changes the behavior of createConfigFile, so don't.
return "", []string{
"/etc/unpackerr/unpackerr.conf",
"/config/unpackerr.conf",
Expand Down Expand Up @@ -161,8 +165,16 @@ func (u *Unpackerr) validateConfig() (uint64, uint64) { //nolint:cyclop
return fm, dm
}

// createConfigFile attempts to avoid creating a config file on linux or freebsd.
// It used to avoid it when running on macos from homebrew, but not anymore.
func (u *Unpackerr) createConfigFile(file string) (string, error) {
if !ui.HasGUI() {
if isRunningInDocker() {
if stat, err := os.Stat("/config"); err == nil && stat.IsDir() {
file = "/config/unpackerr.conf"
}
}

if file == "" {
return "", nil
}

Expand Down