新增:应用配置管理模块,优化文件系统功能
- 新增 ConfigAPI 和 ConfigService 实现配置管理 - 新增 SettingsPanel 和 UpdateNotification 组件 - 文件系统模块化重构,提升代码质量 - 提取公共函数,优化代码结构 - 版本号更新至 0.2.0
This commit is contained in:
17
internal/common/constants.go
Normal file
17
internal/common/constants.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package common
|
||||
|
||||
// Default visible tabs configuration
|
||||
const (
|
||||
// TabDatabase 数据库管理 Tab
|
||||
TabDatabase = "db-cli"
|
||||
// TabFileSystem 文件系统 Tab
|
||||
TabFileSystem = "file-system"
|
||||
// TabDevice 设备测试 Tab
|
||||
TabDevice = "device"
|
||||
)
|
||||
|
||||
// DefaultVisibleTabs 默认可见的 Tabs
|
||||
var DefaultVisibleTabs = []string{TabDatabase, TabFileSystem, TabDevice}
|
||||
|
||||
// DefaultTab 默认打开的 Tab
|
||||
const DefaultTab = TabDatabase
|
||||
45
internal/common/path.go
Normal file
45
internal/common/path.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
// AppName 应用名称
|
||||
AppName = "u-desk"
|
||||
)
|
||||
|
||||
// GetUserDataDir 获取用户数据目录
|
||||
// 跨平台支持:Windows、macOS、Linux
|
||||
func GetUserDataDir() string {
|
||||
var basePath string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
// Windows: %LOCALAPPDATA% 或 %APPDATA%
|
||||
basePath = os.Getenv("LOCALAPPDATA")
|
||||
if basePath == "" {
|
||||
basePath = os.Getenv("APPDATA")
|
||||
}
|
||||
case "darwin":
|
||||
// macOS: ~/Library/Application Support
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
basePath = filepath.Join(homeDir, "Library", "Application Support")
|
||||
}
|
||||
default:
|
||||
// Linux: ~/.config
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err == nil {
|
||||
basePath = filepath.Join(homeDir, ".config")
|
||||
}
|
||||
}
|
||||
|
||||
if basePath == "" {
|
||||
basePath = "."
|
||||
}
|
||||
|
||||
return filepath.Join(basePath, AppName)
|
||||
}
|
||||
@@ -4,6 +4,17 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// InterfaceSliceToStringSlice 将 []interface{} 安全转换为 []string
|
||||
func InterfaceSliceToStringSlice(slice []interface{}) []string {
|
||||
result := make([]string, 0, len(slice))
|
||||
for _, v := range slice {
|
||||
if str, ok := v.(string); ok && str != "" {
|
||||
result = append(result, str)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// FormatBytes 格式化字节大小为人类可读格式
|
||||
// 例如: 1024 → "1.00 KB", 1048576 → "1.00 MB"
|
||||
func FormatBytes(bytes uint64) string {
|
||||
@@ -18,3 +29,28 @@ func FormatBytes(bytes uint64) string {
|
||||
}
|
||||
return fmt.Sprintf("%.2f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
// Contains 检查切片是否包含元素
|
||||
func Contains[T comparable](slice []T, item T) bool {
|
||||
for _, s := range slice {
|
||||
if s == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Difference 返回在 a 中但不在 b 中的元素
|
||||
func Difference[T comparable](a, b []T) []T {
|
||||
mb := make(map[T]struct{}, len(b))
|
||||
for _, x := range b {
|
||||
mb[x] = struct{}{}
|
||||
}
|
||||
var diff []T
|
||||
for _, x := range a {
|
||||
if _, found := mb[x]; !found {
|
||||
diff = append(diff, x)
|
||||
}
|
||||
}
|
||||
return diff
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user