优化:代码质量提升,修复重复逻辑和语法高亮支持
- 简化计算属性,删除重复代码 - 优化文件扩展名获取逻辑 - 新增文件工具函数库 fileHelpers.js - 增强 CodeEditor 语法高亮(支持 30+ 语言) - 修复 Office 文档文件服务器访问权限 - 添加特殊文件名支持(Dockerfile、Makefile 等)
This commit is contained in:
@@ -3,43 +3,24 @@ package common
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
// AppName 应用名称
|
||||
AppName = "u-desk"
|
||||
|
||||
// AppDataDir 应用数据目录名称(带点号,表示隐藏目录)
|
||||
AppDataDir = ".u-desk"
|
||||
)
|
||||
|
||||
// GetUserDataDir 获取用户数据目录
|
||||
// 跨平台支持:Windows、macOS、Linux
|
||||
// 所有平台统一使用: ~/.u-desk
|
||||
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")
|
||||
}
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "."
|
||||
}
|
||||
|
||||
if basePath == "" {
|
||||
basePath = "."
|
||||
}
|
||||
|
||||
return filepath.Join(basePath, AppName)
|
||||
return filepath.Join(homeDir, AppDataDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user