mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
feat: implement system tray interface and manage OS thread locking for cross-platform stability
This commit is contained in:
Binary file not shown.
@@ -5,6 +5,7 @@ package tray
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"wis-free-v3/internal/config"
|
"wis-free-v3/internal/config"
|
||||||
@@ -40,6 +41,12 @@ var statusMenuItem *systray.MenuItem
|
|||||||
// Start initializes and runs the system tray.
|
// Start initializes and runs the system tray.
|
||||||
// This function blocks until the tray is terminated.
|
// This function blocks until the tray is terminated.
|
||||||
func Start(app App) {
|
func Start(app App) {
|
||||||
|
// Pin this goroutine to one OS thread for the whole lifetime of systray.Run.
|
||||||
|
// getlantern/systray creates the notify icon and runs the Win32 message pump on
|
||||||
|
// whichever thread calls Run; if the goroutine migrates between threads, callbacks
|
||||||
|
// and the tray context menu break until restart (often seen after sleep/resume).
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
systray.Run(
|
systray.Run(
|
||||||
func() { onReady(app) },
|
func() { onReady(app) },
|
||||||
onExit,
|
onExit,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"wis-free-v3/internal/logger"
|
"wis-free-v3/internal/logger"
|
||||||
@@ -40,6 +41,11 @@ var instanceLock *os.File
|
|||||||
var AppVersion = "dev"
|
var AppVersion = "dev"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// systray's package init calls runtime.LockOSThread() on the program's startup
|
||||||
|
// thread. Undo that so the main goroutine is not permanently bound; the tray
|
||||||
|
// goroutine locks itself in tray.Start instead (see internal/ui/tray/tray.go).
|
||||||
|
runtime.UnlockOSThread()
|
||||||
|
|
||||||
// Ensure only one instance of the application is running
|
// Ensure only one instance of the application is running
|
||||||
if !acquireInstanceLock() {
|
if !acquireInstanceLock() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user