106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"u-desk/internal/filesystem"
|
|
|
|
"github.com/wailsapp/wails/v2"
|
|
"github.com/wailsapp/wails/v2/pkg/options"
|
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
|
)
|
|
|
|
//go:embed all:web/dist
|
|
var assets embed.FS
|
|
|
|
func main() {
|
|
// 🔒 初始化文件系统安全功能
|
|
initFileSystemSecurity()
|
|
|
|
// 创建应用实例
|
|
app := NewApp()
|
|
|
|
// 创建应用配置(无边框窗口,自定义标题栏)
|
|
err := wails.Run(&options.App{
|
|
Title: "U-Desk",
|
|
Width: 1400,
|
|
Height: 900,
|
|
MinWidth: 1000,
|
|
MinHeight: 600,
|
|
Frameless: true, // 无边框窗口
|
|
AssetServer: &assetserver.Options{
|
|
Assets: assets,
|
|
Handler: filesystem.NewLocalFileHandler(),
|
|
},
|
|
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
|
|
OnStartup: app.Startup,
|
|
OnShutdown: app.shutdown,
|
|
Bind: []interface{}{
|
|
app,
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
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")
|
|
}
|