-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
80 lines (77 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"runtime/debug"
)
func main() {
var level string
flag.StringVar(&level, "debug", "0", "调试级别")
flag.Parse()
defer func() {
if r := recover(); r != nil {
logger.Errorf("%s", debug.Stack())
logger.Errorf("This is error message: %v", r)
}
}()
ap := app.New()
//icon, _ := fyne.LoadResourceFromPath("./assets/img/chrome.ico")
ap.SetIcon(resourceAssetsImgChromePng)
//t.SetFonts("./assets/font/MiSans-Regular.ttf", "")
InitLogger(level)
//初始化绑定数据
data := initData()
logger.Debug("Init data success:")
initBundle(*data)
logger.Debug("Set lang success.")
ap.Settings().SetTheme(&MyTheme{data.themeSettings, data.langSettings})
logger.Debug("Set theme success.")
meta := ap.Metadata()
win := ap.NewWindow(LoadString("TitleLabel") + " v" + meta.Version + " by Libs")
chromeAutoUpdate(ap, win, data)
tabs := container.NewAppTabs(
container.NewTabItem(LoadString("TabMainLabel"), baseScreen(win, data)),
container.NewTabItem("Chrome++", chromePlusScreen(win, data)),
container.NewTabItem(LoadString("TabSettingLabel"), settingsScreen(ap, win, data)),
)
tabs.Refresh()
tabs.OnSelected = func(t *container.TabItem) {
fyne.CurrentApp().Settings().SetTheme(fyne.CurrentApp().Settings().Theme())
}
win.SetContent(
tabs,
)
//win.SetMainMenu(makeMenu(ap, win))
win.CenterOnScreen()
win.Resize(fyne.NewSize(500, 400))
//win.SetFixedSize(true)
win.SetOnClosed(func() {
//保存配置数据
clearOldUpdater()
err := saveConfig(data)
handlerErr(err, "配置保存失败,请检查目录权限", win)
})
ap.Lifecycle().SetOnStopped(func() {
clearOldUpdater()
err := saveConfig(data)
handlerErr(err, "配置保存失败,请检查目录权限", win)
})
win.SetCloseIntercept(func() {
if !getBool(data.autoUpdate) {
ap.Quit()
} else {
win.Hide()
}
})
win.ShowAndRun()
}
func initBundle(data SettingsData) {
lang := getString(data.langSettings)
if lang == "System" || lang == "" {
DelayInitializeLocale()
} else {
SetLocale(lang)
}
}