-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapp.go
More file actions
114 lines (96 loc) · 2.67 KB
/
Copy pathapp.go
File metadata and controls
114 lines (96 loc) · 2.67 KB
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
package main
import (
"bili-audio-downloader/backend/config"
"bili-audio-downloader/backend/constants"
"bili-audio-downloader/backend/ffmpeg"
"bili-audio-downloader/backend/services"
"context"
wails "github.com/wailsapp/wails/v2/pkg/runtime"
"os"
)
// App struct
type App struct {
ctx context.Context
}
// startup is called when the app starts
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// Initialize config
wails.LogDebug(a.ctx, "Start Initializing Config")
config.InitConfig(a.ctx)
// Create folder
wails.LogDebug(a.ctx, "Start Initializing Folder")
initFolder(a.ctx)
// Check ffmpeg
wails.LogDebug(a.ctx, "Start Check FFmpeg")
go checkFfmpegAndAlarm(a.ctx)
// Check software update
wails.LogDebug(a.ctx, "Start Check Update")
go checkUpdateAndAlarm(a.ctx)
}
// shutdown is called when the app shutdown
func (a *App) shutdown(ctx context.Context) {
// 清理缓存
if config.Cfg.DeleteCache {
os.RemoveAll(config.Cfg.GetCachePath())
}
}
// Check ffmpeg and alarm
func checkFfmpegAndAlarm(ctx context.Context) {
exists := ffmpeg.CheckExists()
if exists {
wails.LogInfo(ctx, "FFmpeg found in system PATH")
} else {
wails.LogWarning(ctx, "FFmpeg not found in system PATH")
}
}
// Check update and alarm
func checkUpdateAndAlarm(ctx context.Context) {
// Check update
version, err := services.CheckUpdate(constants.APP_VERSION)
if err != nil {
wails.LogErrorf(ctx, "Check update faild: %s", err)
}
switch version {
case "-1":
wails.LogInfo(ctx, "It is special release version, no need to update")
case "0":
wails.LogInfo(ctx, "No software update")
default:
wails.LogInfof(ctx, "Founded new version: %s", version)
// Show dialog to user
{
result, err := wails.MessageDialog(ctx, wails.MessageDialogOptions{
Type: wails.QuestionDialog,
Title: "找到新版本:" + version,
Message: "软件有新版本发布了,是否前往下载?",
DefaultButton: "Yes",
})
if err != nil {
wails.LogError(ctx, "Failed to show message dialog: "+err.Error())
}
wails.LogDebugf(ctx, "Dialog result:%s", result)
if result == "Yes" {
wails.BrowserOpenURL(ctx, "https://github.com/HIM049/BADownloaderUI/releases/tag/"+version)
}
}
}
}
// 初始化必备文件夹
func initFolder(ctx context.Context) {
downloadPath := config.Cfg.GetDownloadPath()
cachePath := config.Cfg.GetCachePath()
var paths = []string{
downloadPath,
cachePath,
cachePath + "/audio",
cachePath + "/cover",
}
for _, path := range paths {
err := os.MkdirAll(path, 0755)
if err != nil {
wails.LogFatalf(ctx, "Initialize Folder Failed: %s", err)
}
}
wails.LogInfo(ctx, "Initialize Folder Successful")
}