On windows, call on_exit at WM_QUERYENDSESSION

This commit is contained in:
Ox Cart
2017-08-25 21:35:55 -05:00
parent 351a4b6860
commit 8f8563c338
7 changed files with 16 additions and 19 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -9
View File
@@ -2,7 +2,8 @@ package main
import (
"fmt"
"os"
"io/ioutil"
"time"
"github.com/getlantern/systray"
"github.com/getlantern/systray/example/icon"
@@ -10,16 +11,10 @@ import (
)
func main() {
file, err := os.Create("out.txt")
if err != nil {
fmt.Println("Couldn't create out.txt")
return
}
defer file.Close()
onExit := func() {
fmt.Println("Starting onExit")
file.Write([]byte("On Exit...\n"))
file.Sync()
now := time.Now()
ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644)
fmt.Println("Finished onExit")
}
// Should be called at the very beginning of main().
+4 -2
View File
@@ -68,8 +68,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
break;
case WM_ENDSESSION:
printf("Session ended\n");
case WM_QUERYENDSESSION:
printf("Session ending\n");
// We call on_exit here so that the program has a chance to do cleanup
// before the final session ending sequence occurs.
systray_on_exit(0/*ignored*/);
Shell_NotifyIcon(NIM_DELETE, &nid);
break;
File diff suppressed because one or more lines are too long