refactor: 重构 GUI 框架为 Wails
- 添加 Go 后端实现,包括配置管理、文件上传逻辑和 Wails 应用接口 - 实现前端 Vue 界面,提供服务器配置、目录选择、上传控制等功能 - 集成 Element Plus 组件库构建用户界面 - 添加文件上传进度显示和实时日志输出功能 - 实现后台文件监控和上传任务管理 - 配置 Wails 框架支持前后端交互 - 更新项目依赖,移除 Fyne 框架,集成 Wails v2 - 添加项目配置文件管理和自动保存功能
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"dypid-client/internal/config"
|
||||
"dypid-client/internal/uploader"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
logChan chan string
|
||||
uploaderCTX context.Context
|
||||
uploaderCancel context.CancelFunc
|
||||
}
|
||||
|
||||
var isRun = false
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
}
|
||||
|
||||
// startup 程序初始化
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
|
||||
// 后台 goroutine 持续推送日志
|
||||
a.logChan = make(chan string, 100)
|
||||
go func() {
|
||||
for log := range a.logChan {
|
||||
runtime.EventsEmit(a.ctx, "log", log)
|
||||
}
|
||||
}()
|
||||
|
||||
//在程序启动时运行上传程序
|
||||
a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
|
||||
if config.APPConfig.IsRunOnStart {
|
||||
time.Sleep(time.Second)
|
||||
isRun = true
|
||||
go uploader.StartLooking(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir)
|
||||
}
|
||||
}
|
||||
|
||||
// SelectPath 打开选择路径弹框
|
||||
func (a *App) SelectPath() string {
|
||||
dialog, _ := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{})
|
||||
fmt.Println("选择路径:", dialog)
|
||||
return dialog
|
||||
}
|
||||
|
||||
func (a *App) GetConfig() config.Config {
|
||||
return config.APPConfig
|
||||
}
|
||||
|
||||
func (a *App) WriteConfig(key string, value any) {
|
||||
fmt.Println(key, value)
|
||||
config.WriteConfig(key, value)
|
||||
}
|
||||
|
||||
func (a *App) StartUpload() {
|
||||
if isRun {
|
||||
return
|
||||
}
|
||||
go uploader.StartLooking(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir)
|
||||
}
|
||||
|
||||
func (a *App) StopUpload() {
|
||||
if isRun {
|
||||
a.uploaderCancel()
|
||||
a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user