Private
Public Access
1
0

新增:应用配置管理模块,优化文件系统功能

- 新增 ConfigAPI 和 ConfigService 实现配置管理
- 新增 SettingsPanel 和 UpdateNotification 组件
- 文件系统模块化重构,提升代码质量
- 提取公共函数,优化代码结构
- 版本号更新至 0.2.0
This commit is contained in:
2026-01-28 22:48:10 +08:00
parent 7e79a53dae
commit b849e6cc46
31 changed files with 3024 additions and 917 deletions

64
main.go
View File

@@ -2,9 +2,6 @@ package main
import (
"embed"
"os"
"path/filepath"
"runtime"
"u-desk/internal/filesystem"
@@ -17,9 +14,6 @@ import (
var assets embed.FS
func main() {
// 🔒 初始化文件系统安全功能
initFileSystemSecurity()
// 创建应用实例
app := NewApp()
@@ -37,7 +31,7 @@ func main() {
},
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
OnStartup: app.Startup,
OnShutdown: app.shutdown,
OnShutdown: app.Shutdown,
Bind: []interface{}{
app,
},
@@ -47,59 +41,3 @@ func main() {
println("Error:", err.Error())
}
}
// initFileSystemSecurity 初始化文件系统安全功能
// 优化:并发执行初始化操作,不阻塞启动
func initFileSystemSecurity() {
// 获取用户数据目录
userDataDir := getUserDataDir()
// 使用并发初始化文件系统安全功能
go func() {
// 初始化审计日志(记录到 logs 子目录)
logDir := filepath.Join(userDataDir, "logs")
if err := filesystem.InitAudit(logDir); err != nil {
println("Warning: Failed to initialize audit log:", err.Error())
}
// 初始化回收站
recycleBinPath := filepath.Join(userDataDir, "recycle_bin")
if err := filesystem.InitRecycleBin(recycleBinPath); err != nil {
println("Warning: Failed to initialize recycle bin:", err.Error())
}
// 初始化文件锁检查器
filesystem.InitFileLockChecker()
}()
}
// getUserDataDir 获取用户数据目录
func getUserDataDir() string {
var basePath string
// 根据操作系统选择不同的基础路径
switch runtime.GOOS {
case "windows":
// Windows: %APPDATA% 或 %LOCALAPPDATA%
basePath = os.Getenv("LOCALAPPDATA")
if basePath == "" {
basePath = os.Getenv("APPDATA")
}
case "darwin":
// macOS: ~/Library/Application Support
homeDir, _ := os.UserHomeDir()
basePath = filepath.Join(homeDir, "Library", "Application Support")
default:
// Linux: ~/.config
homeDir, _ := os.UserHomeDir()
basePath = filepath.Join(homeDir, ".config")
}
// 确保基础路径存在
if basePath == "" {
basePath = "."
}
// 返回应用特定的数据目录
return filepath.Join(basePath, "u-desk")
}