-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
122 lines (105 loc) · 2.48 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"embed"
"log"
"os"
"time"
"appconsole/config"
"appconsole/module"
"appconsole/view"
mainmenu "appconsole/view/main_menu"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/driver/desktop"
)
//go:embed resources
var resource embed.FS
//go:embed env.yaml
var env embed.FS
var (
BuildDate string = time.Now().Format("2006-01-02")
Title = "demo"
)
var myApp fyne.App
func init() {
// 字型要最早讀取, 必須比 app.New() 早, 否則會讀取不到字型
module.LoadFont()
/*
- 必須早執行 NewWithID()
- 才能讀取得到系統資訊, ex: 儲存 log 的位置, metadata 等資訊
- 因為這邊的 conf, 有儲存系統資訊
*/
myApp = app.NewWithID("app.console.demo")
// 讀取自定義環境變數
b, err := env.ReadFile("env.yaml")
if err != nil {
panic(err)
}
//
conf := config.NewConfig(b, &resource)
module.SetLog(conf)
conf.Show()
}
func main() {
//
makeTray(myApp)
logLifecycle(myApp)
//
myApp.Preferences().SetString("version", myApp.Metadata().Version)
//
myWindow := myApp.NewWindow(Title)
myWindow.SetMainMenu(mainmenu.MakeMenu(myApp, myWindow))
myWindow.Resize(fyne.NewSize(1200, 750))
myWindow.CenterOnScreen()
myWindow.SetContent(view.MainContainer(myWindow))
myWindow.SetMaster()
myWindow.Hide()
//
loginWindow := myApp.NewWindow("login")
loginWindow.Resize(fyne.NewSize(400, 150))
loginWindow.CenterOnScreen()
loginWindow.SetContent(view.LoginContent(loginWindow))
loginWindow.SetMaster()
loginWindow.Hide()
if myApp.Preferences().Bool("remember_me") {
myWindow.Show()
} else {
loginWindow.Show()
}
//
myApp.Run()
//
os.Unsetenv("FYNE_FONT")
}
func logLifecycle(a fyne.App) {
a.Lifecycle().SetOnStarted(func() {
log.Println("Lifecycle: Started")
})
a.Lifecycle().SetOnStopped(func() {
log.Println("Lifecycle: Stopped")
})
a.Lifecycle().SetOnEnteredForeground(func() {
log.Println("Lifecycle: Entered Foreground")
})
a.Lifecycle().SetOnExitedForeground(func() {
log.Println("Lifecycle: Exited Foreground")
})
}
/*
- osx 右上角的小圖示
- window 右下角的小圖示
- 點選後, 會有選單
*/
func makeTray(a fyne.App) {
if desk, ok := a.(desktop.App); ok {
h := fyne.NewMenuItem("Hello", func() {})
menu := fyne.NewMenu("Hello World", h)
h.Action = func() {
log.Println("System tray menu tapped")
h.Label = "Welcome"
myApp.SendNotification(fyne.NewNotification("notification", "hello world"))
menu.Refresh()
}
desk.SetSystemTrayMenu(menu)
}
}