Private
Public Access
1
0

修复: OSS收藏打开+连接指示器根目录+字段映射+侧边栏重构+文件监听+首屏优化

This commit is contained in:
2026-05-16 17:55:59 +08:00
parent 316e517989
commit d17c20c579
37 changed files with 1667 additions and 1566 deletions

57
app.go
View File

@@ -5,6 +5,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@@ -16,6 +17,7 @@ import (
"u-desk/internal/api"
"u-desk/internal/common"
"u-desk/internal/filewatch"
"u-desk/internal/filesystem"
"u-desk/internal/hotkey"
osssvc "u-desk/internal/ossdrv"
@@ -44,6 +46,7 @@ type App struct {
sftpService *sftp.Service
ossService *osssvc.Service
profileSvc *service.ProfileService
fileWatcher *filewatch.Watcher
isAlwaysOnTop bool
mu sync.Mutex
unregisterHotkey func()
@@ -61,6 +64,11 @@ func NewApp() *App {
// SetMainWindow 设置主窗口引用(由 main.go 在创建窗口后调用)
func (a *App) SetMainWindow(w *application.WebviewWindow) {
a.mainWindow = w
a.fileWatcher = filewatch.NewWatcher(func(name string, data ...any) {
if a.mainWindow != nil {
a.mainWindow.EmitEvent(name, data...)
}
})
}
// RegisterGlobalHotkey 注册 Ctrl+Shift+B 全局热键(需在窗口创建后调用)
@@ -69,11 +77,10 @@ func (a *App) RegisterGlobalHotkey() {
return
}
a.mu.Lock()
defer a.mu.Unlock()
if a.unregisterHotkey != nil {
a.mu.Unlock()
return
}
a.mu.Unlock()
hwnd := uintptr(a.mainWindow.NativeWindow())
if hwnd == 0 {
fmt.Println("[全局热键] HWND 为 0注册跳过")
@@ -85,9 +92,7 @@ func (a *App) RegisterGlobalHotkey() {
return
}
fmt.Println("[全局热键] Ctrl+Shift+B 已注册")
a.mu.Lock()
a.unregisterHotkey = func() { hotkey.Unregister(hwnd, id) }
a.mu.Unlock()
}
// HandleHotkey 处理全局热键回调:切换 BgmBar 显示/隐藏
@@ -102,6 +107,9 @@ func (a *App) HandleHotkey() {
func (a *App) ServiceStartup(ctx context.Context, _ application.ServiceOptions) error {
a.ctx = ctx
// dev 模式打开 DevTools
openDevTools(a.mainWindow)
// 1. 核心初始化SQLite必须同步很快
if _, err := storage.InitFast(); err != nil {
return fmt.Errorf("SQLite 初始化失败,应用无法启动: %w", err)
@@ -310,6 +318,21 @@ func (a *App) ReadFile(path string) (string, error) {
return a.filesystem.ReadFile(path)
}
// WatchFile 开始监听指定文件的变化,变化时发送 file-changed 事件
func (a *App) WatchFile(path string) error {
if a.fileWatcher == nil {
return fmt.Errorf("文件监听器未初始化")
}
return a.fileWatcher.WatchFile(path)
}
// UnwatchFile 停止监听文件变化
func (a *App) UnwatchFile() {
if a.fileWatcher != nil {
a.fileWatcher.UnwatchFile()
}
}
// WriteFileRequest 写入文件请求结构体
type WriteFileRequest struct {
Path string `json:"path"`
@@ -435,6 +458,7 @@ func (a *App) ResolveShortcut(lnkPath string) (map[string]interface{}, error) {
}, nil
}
// getWindowsSpecialFolder 从注册表读取 Windows 特殊文件夹的真实路径
func getWindowsSpecialFolder(guid string, fallbackName string) string {
key, err := registry.OpenKey(registry.CURRENT_USER,
@@ -1194,28 +1218,9 @@ func (a *App) LoadConnectionProfiles() ([]map[string]interface{}, error) {
if err != nil {
return nil, err
}
result := make([]map[string]interface{}, len(list))
for i, p := range list {
result[i] = map[string]interface{}{
"id": float64(p.ID),
"name": p.Name,
"host": p.Host,
"port": p.Port,
"username": p.Username,
"password": p.Password,
"keyPath": p.KeyPath,
"type": p.Type,
"provider": p.Provider,
"token": p.Token,
"accessKey": p.AccessKey,
"secretKey": p.SecretKey,
"bucket": p.Bucket,
"region": p.Region,
"endpoint": p.Endpoint,
"lastConnected": p.LastConnected,
"sortOrder": float64(p.SortOrder),
}
}
var result []map[string]interface{}
data, _ := json.Marshal(list)
json.Unmarshal(data, &result)
return result, nil
}