-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.go
91 lines (77 loc) · 2.21 KB
/
app.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
package main
import (
"bili-audio-downloader/services"
"context"
"os"
wails "github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// startup is called when the app starts. The context is saved
// so we can call the wails methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// 程序初始化
cfg := new(Config)
if cfg.Get() != nil {
wails.LogFatal(a.ctx, "Initialize Config Faild")
} else {
wails.LogInfo(a.ctx, "Initialize Config Successful")
}
downloadPath := cfg.FileConfig.DownloadPath
cachePath := cfg.FileConfig.CachePath
err2 := os.MkdirAll(downloadPath, 0755)
err3 := os.MkdirAll(cachePath, 0755)
err4 := os.MkdirAll(cachePath+"/music", 0755)
err5 := os.MkdirAll(cachePath+"/cover", 0755)
err6 := os.MkdirAll(cachePath+"/single/cover", 0755)
err7 := os.MkdirAll(cachePath+"/single/music", 0755)
if err2 != nil ||
err3 != nil ||
err4 != nil ||
err5 != nil ||
err6 != nil ||
err7 != nil {
wails.LogFatal(a.ctx, "Initialize Folder Faild")
} else {
wails.LogInfo(a.ctx, "Initialize Folder Successful")
}
// 检查版本更新
version, err := services.CheckUpdate(APP_VERSION)
if err != nil {
wails.LogErrorf(a.ctx, "Check for update Faild: %s", err)
} else if version == "0" {
wails.LogInfo(a.ctx, "No software update")
} else {
wails.LogInfof(a.ctx, "Found new version: %s", version)
result, err := wails.MessageDialog(a.ctx, wails.MessageDialogOptions{
Type: wails.QuestionDialog,
Title: "找到新版本:" + version,
Message: "软件有新版本发布了,是否前往下载?",
DefaultButton: "Yes",
})
if err != nil {
wails.LogError(a.ctx, "弹出更新提示失败")
}
wails.LogDebugf(a.ctx, "选择结果:%s", result)
if result == "Yes" {
wails.BrowserOpenURL(a.ctx, "https://github.com/HIM049/BADownloaderUI/releases/tag/"+version)
}
}
}
// 程序关闭时
func (a *App) shutdown(ctx context.Context) {
// 清理缓存
cfg := new(Config)
cfg.Get()
if cfg.DeleteCache {
os.RemoveAll(cfg.FileConfig.CachePath)
}
}
type DownloadOption struct {
SongName bool `json:"song_name"`
SongCover bool `json:"song_cover"`
SongAuthor bool `json:"song_author"`
}