Skip to content

Commit 01b67b4

Browse files
authored
Merge pull request getlantern#36 from EssGeeEich/master
Forcefully delete the taskbar icon during quit on Windows
2 parents e79f9a4 + cb652ab commit 01b67b4

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

systray.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ import (
1010
)
1111

1212
var (
13-
systrayReady func()
14-
systrayExit func()
15-
menuItems = make(map[uint32]*MenuItem)
16-
menuItemsLock sync.RWMutex
13+
systrayReady func()
14+
systrayExit func()
15+
systrayExitCalled bool
16+
menuItems = make(map[uint32]*MenuItem)
17+
menuItemsLock sync.RWMutex
1718

1819
currentID = uint32(0)
1920
quitOnce sync.Once
2021
)
2122

23+
// This helper function allows us to call systrayExit only once,
24+
// without accidentally calling it twice in the same lifetime.
25+
func runSystrayExit() {
26+
if !systrayExitCalled {
27+
systrayExitCalled = true
28+
systrayExit()
29+
}
30+
}
31+
2232
func init() {
2333
runtime.LockOSThread()
2434
}
@@ -111,6 +121,7 @@ func Register(onReady func(), onExit func()) {
111121
onExit = func() {}
112122
}
113123
systrayExit = onExit
124+
systrayExitCalled = false
114125
registerSystray()
115126
}
116127

systray_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func systray_ready() {
144144

145145
//export systray_on_exit
146146
func systray_on_exit() {
147-
systrayExit()
147+
runSystrayExit()
148148
}
149149

150150
//export systray_menu_item_selected

systray_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func nativeLoop() int {
154154
}
155155

156156
func nativeEnd() {
157-
systrayExit()
157+
runSystrayExit()
158158
instance.conn.Close()
159159
}
160160

systray_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui
324324
t.nid.delete()
325325
}
326326
t.muNID.Unlock()
327-
systrayExit()
327+
runSystrayExit()
328328
case t.wmSystrayMessage:
329329
switch lParam {
330330
case WM_RBUTTONUP, WM_LBUTTONUP:
@@ -951,6 +951,13 @@ func quit() {
951951
0,
952952
0,
953953
)
954+
955+
wt.muNID.Lock()
956+
if wt.nid != nil {
957+
wt.nid.delete()
958+
}
959+
wt.muNID.Unlock()
960+
runSystrayExit()
954961
}
955962

956963
func setInternalLoop(bool) {

systray_windows_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const iconFilePath = "example/icon/iconwin.ico"
1818
func TestBaseWindowsTray(t *testing.T) {
1919
systrayReady = func() {}
2020
systrayExit = func() {}
21+
systrayExitCalled = false
2122

2223
runtime.LockOSThread()
2324

0 commit comments

Comments
 (0)