Skip to content

Commit

Permalink
Remove Windows console window (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall authored May 26, 2024
2 parents d708eab + 5dbad6c commit 401a1c9
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 61 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ VERSION_LDFLAGS:= -X \"golift.io/version.Branch=$(BRANCH) ($(COMMIT))\" \
-X \"golift.io/version.Revision=$(ITERATION)\" \
-X \"golift.io/version.Version=$(VERSION)\"

WINDOWS_LDFLAGS:= -H=windowsgui

# Makefile targets follow.

all: notifiarr
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d
github.com/go-ping/ping v1.1.0
github.com/go-sql-driver/mysql v1.8.1
github.com/gonutz/w32/v2 v2.11.1
github.com/gorilla/mux v1.8.1
github.com/gorilla/schema v1.3.0
github.com/gorilla/securecookie v1.1.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/gonutz/w32/v2 v2.11.1 h1:plG738ZY7VIkPGf3adZ6lFeAf2evCKrULKyZT5GrPoc=
github.com/gonutz/w32/v2 v2.11.1/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
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import (
// @in header
// @name X-API-Key
func main() {
ui.HideConsoleWindow()
// setup log package in case we throw an error in main.go before logging is setup.
log.SetFlags(log.LstdFlags)
log.SetPrefix("[ERROR] ")

defer func() {
if r := recover(); r != nil {
ui.ShowConsoleWindow()
log.Printf("Go Panic! %s\n%v\n%s", mnd.BugIssue, r, string(debug.Stack()))
}
}()
Expand Down
13 changes: 7 additions & 6 deletions pkg/bindata/templates/tunnel.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1><i class="fas fa-satellite"></i> Site Tunnel</h1>
<p>
This client keeps a persistent websocket connection to a notifiarr.com
<a href="https://github.com/golift/mulery">Mulery</a> tunnel.
<a href="https://github.com/golift/mulery" target="_new">Mulery</a> tunnel.
This tunnel allows the website to make requests to your client without the need
for opening a port, or having a static IP. This page allows you to select your
primary tunnel and which tunnel you wish to use as backup in case the primary
Expand All @@ -12,7 +12,7 @@ <h1><i class="fas fa-satellite"></i> Site Tunnel</h1>
Select another fast tunnel as backup.
</p>
<p> {{$activeTunnel := (cache "activeTunnel")}}
<li><i class="fas fa-star text-dgrey"></i> Active Tunnel: <b>{{if $activeTunnel}}{{$activeTunnel.Data}}{{else}}unknown{{end}}</b></li>
<li><b><i class="fas fa-star text-primary"></i> Active Tunnel: {{if $activeTunnel}}{{$activeTunnel.Data}}{{else}}unknown{{end}}</b></li>
</p>

<p></p>
Expand All @@ -33,10 +33,11 @@ <h1><i class="fas fa-satellite"></i> Site Tunnel</h1>
{{- range $idx, $mule := .ClientInfo.User.Mulery}}
{{$primary := and (gt (len $.ClientInfo.User.Tunnels) 0) (eq (index $.ClientInfo.User.Tunnels 0) $mule.Socket)}}
<tr>
<td style="width:80px;"><span class="text-warning text-center" id="tunnel-ping{{$idx}}"></span></td>
<td style="width:30px; max-width:30px;">
<td style="width:30px;">
<input type="radio" value="{{$mule.Socket}}" class="tunnel-param" name="primaryTunnel"{{if $primary}} checked{{end}}>
</td>
<td style="width:200px;">{{$mule.Location}}</td>
<td style="width:60px;"><span class="text-warning text-center" id="tunnel-ping{{$idx}}"></span></td>
<td>{{$mule.Socket}}</td>
</tr>
{{- end}}
Expand All @@ -48,7 +49,7 @@ <h1><i class="fas fa-satellite"></i> Site Tunnel</h1>
{{- range $mule := .ClientInfo.User.Mulery}}
{{$backup := and (gt (len $.ClientInfo.User.Tunnels) 1) (eq (index $.ClientInfo.User.Tunnels 1) $mule.Socket)}}
<option value="{{$mule.Socket}}"{{if $backup}} selected{{end}}>
{{$mule.Socket}}
{{$mule.Location}} &nbsp; {{$mule.Socket}}
</option>
{{- end}}
</select>
Expand All @@ -62,7 +63,7 @@ <h4>Tunnel Stats</h4>
{{- if .Tunnel }}
{{- range $socket, $stats := .Tunnel.PoolStats }}
<tr>
<td><strong>Socket URL</strong> ({{if $stats.Active}}active{{else}}inactive{{end}})</td>
<td style="width:230px;"><strong>Socket URL</strong> ({{if $stats.Active}}active{{else}}inactive{{end}})</td>
<td><strong>{{$socket}}</strong></td>
</tr>
<tr><td>Disconnects</td><td>{{$stats.Disconnects}}</td></tr>
Expand Down
11 changes: 0 additions & 11 deletions pkg/client/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,6 @@ func (c *Client) debugMenu() {
c.Config.Services.RunChecks("log")
})

menu["console"] = debug.AddSubMenuItem("Console", "toggle the console window")
menu["console"].Click(func() {
if menu["console"].Checked() {
menu["console"].Uncheck()
ui.HideConsoleWindow()
} else {
menu["console"].Check()
ui.ShowConsoleWindow()
}
})

if runtime.GOOS != mnd.Windows {
menu["console"].Hide()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ func (c *Client) roundRobinConfig(ci *clientinfo.ClientInfo) *mulery.RoundRobinC
return &mulery.RoundRobinConfig{
RetryInterval: interval,
Callback: func(_ context.Context, socket string) {
data.Save("activeTunnel", socket)
defer data.Save("activeTunnel", socket)
// Tell the website we connected to a new tunnel, so it knows how to reach us.
c.website.SendData(&website.Request{
Route: website.TunnelRoute,
Event: website.EventSignal,
Payload: map[string]string{"socket": socket},
Payload: map[string]interface{}{"socket": socket, "previous": data.Get("activeTunnel")},
LogMsg: fmt.Sprintf("Update Tunnel Target (%s)", socket),
LogPayload: true,
})
Expand Down
2 changes: 0 additions & 2 deletions pkg/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/Notifiarr/notifiarr/pkg/logs/share"
"github.com/Notifiarr/notifiarr/pkg/mnd"
"github.com/Notifiarr/notifiarr/pkg/ui"
homedir "github.com/mitchellh/go-homedir"
"golift.io/rotatorr"
"golift.io/rotatorr/timerotator"
Expand Down Expand Up @@ -168,7 +167,6 @@ func (l *Logger) Close() (errors []error) {
// CapturePanic can be deferred in any go routine to log any panic that occurs.
func (l *Logger) CapturePanic() {
if r := recover(); r != nil {
ui.ShowConsoleWindow()
l.ErrorLog.Output(callDepth, //nolint:errcheck
fmt.Sprintf("Go Panic! %s\n%s-%s %s %v\n%s", mnd.BugIssue,
version.Version, version.Revision, version.Branch, 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 @@ -22,12 +22,6 @@ func HasGUI() bool {
return hasGUI
}

// HideConsoleWindow doesn't work on maacOS.
func HideConsoleWindow() {}

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

func Notify(msg string, vars ...interface{}) error {
if !hasGUI {
return nil
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 @@ -25,12 +25,6 @@ func Notify(_ string, _ ...interface{}) error {
return nil
}

// HideConsoleWindow doesn't work on most OSes.
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
21 changes: 0 additions & 21 deletions pkg/ui/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/Notifiarr/notifiarr/pkg/bindata"
"github.com/Notifiarr/notifiarr/pkg/mnd"
"github.com/gen2brain/beeep"
"github.com/gonutz/w32/v2"
"github.com/kardianos/osext"
)

Expand Down Expand Up @@ -68,26 +67,6 @@ func getPNG() string {
return pngPath
}

// HideConsoleWindow makes the console window vanish on startup.
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
5 changes: 3 additions & 2 deletions pkg/website/clientinfo/clientinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type ClientInfo struct {

// MuleryServer is data from the website. It's a tunnel's https and wss urls.
type MuleryServer struct {
Tunnel string `json:"tunnel"` // ex: "https://africa.notifiarr.com/"
Socket string `json:"socket"` // ex: "wss://africa.notifiarr.com/register"
Tunnel string `json:"tunnel"` // ex: "https://africa.notifiarr.com/"
Socket string `json:"socket"` // ex: "wss://africa.notifiarr.com/register"
Location string `json:"location"` // ex: "Nairobi, Kenya, Africa"
}

// CronConfig defines a custom GET timer from the website.
Expand Down

0 comments on commit 401a1c9

Please sign in to comment.