Initial GoWallpaper implementation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/lxn/walk"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mutex, alreadyRunning, err := acquireSingleInstance()
|
||||
if err != nil {
|
||||
showNativeMessage(appName, "无法检查程序运行状态:"+err.Error())
|
||||
return
|
||||
}
|
||||
defer windows.CloseHandle(mutex)
|
||||
if alreadyRunning {
|
||||
showNativeMessage(appName, "GoWallpaper 已经运行,请使用右下角托盘图标。")
|
||||
return
|
||||
}
|
||||
|
||||
appDir, err := appDirectory()
|
||||
if err != nil {
|
||||
showNativeMessage(appName, err.Error())
|
||||
return
|
||||
}
|
||||
cfg, firstRun, err := loadOrCreateConfig(filepath.Join(appDir, configFileName))
|
||||
if err != nil {
|
||||
showNativeMessage(appName, err.Error())
|
||||
return
|
||||
}
|
||||
cache, err := loadCacheIndex(filepath.Join(appDir, "cache"))
|
||||
if err != nil {
|
||||
showNativeMessage(appName, err.Error())
|
||||
return
|
||||
}
|
||||
if cfg.StartWithWindows {
|
||||
if err := setStartWithWindows(true); err != nil {
|
||||
showNativeMessage(appName, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
mw, err := walk.NewMainWindow()
|
||||
if err != nil {
|
||||
log.Printf("创建消息窗口失败: %v", err)
|
||||
showNativeMessage(appName, fmt.Sprintf("程序启动失败:%v", err))
|
||||
return
|
||||
}
|
||||
defer mw.Dispose()
|
||||
app, err := newApp(mw, appDir, cfg, cache)
|
||||
if err != nil {
|
||||
showNativeMessage(appName, fmt.Sprintf("创建托盘图标失败:%v", err))
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if !app.closing.Load() {
|
||||
app.close()
|
||||
}
|
||||
}()
|
||||
app.start(firstRun)
|
||||
mw.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user