package main import ( "log" "os" "path/filepath" "github.com/getlantern/systray" "golang.org/x/sys/windows" ) func main() { log.SetFlags(log.Ltime | log.Lmicroseconds) mutexName, _ := windows.UTF16PtrFromString("Global\\u-desktop-single-instance") mutex, err := windows.CreateMutex(nil, false, mutexName) if err != nil { log.Fatal("创建互斥锁失败:", err) } if windows.GetLastError() == windows.ERROR_ALREADY_EXISTS { log.Println("已有实例运行,退出") windows.CloseHandle(mutex) return } defer windows.CloseHandle(mutex) exePath, _ := os.Executable() cfgDir := filepath.Join(filepath.Dir(exePath), "config") os.MkdirAll(cfgDir, 0755) configPath = filepath.Join(cfgDir, "settings.json") procSetProcessDPIAware.Call() systray.Run(onSystrayReady, nil) }