Browse Source

feat: Enhance language detection and process management in main.go

- Improved language detection logic to support multiple environment variables and system-specific checks for Windows and Unix systems.
- Added logging for the detected language to enhance user feedback.
- Refactored process management initialization to improve code organization and clarity.
- Updated the main function to include clearer steps for configuration loading and success messaging.

These changes enhance the application's usability by providing better language support and clearer process management.
pull/20/head
Xx 6 months ago
parent
commit
490edb4d83
  1. BIN
      bin/cursor_id_modifier_v2.0.0_darwin_amd64_intel
  2. BIN
      bin/cursor_id_modifier_v2.0.0_darwin_arm64_m1
  3. BIN
      bin/cursor_id_modifier_v2.0.0_linux_amd64
  4. BIN
      bin/cursor_id_modifier_v2.0.0_windows_amd64.exe
  5. 70
      main.go

BIN
bin/cursor_id_modifier_v2.0.0_darwin_amd64_intel

BIN
bin/cursor_id_modifier_v2.0.0_darwin_arm64_m1

BIN
bin/cursor_id_modifier_v2.0.0_linux_amd64

BIN
bin/cursor_id_modifier_v2.0.0_windows_amd64.exe

70
main.go

@ -505,14 +505,49 @@ func checkAdminPrivileges() (bool, error) {
// Utility functions // Utility functions
func detectLanguage() Language { func detectLanguage() Language {
lang := os.Getenv("LANG")
if lang == "" {
lang = os.Getenv("LANGUAGE")
// 1. 首先检查常用的语言环境变量
for _, envVar := range []string{"LANG", "LANGUAGE", "LC_ALL"} {
if lang := os.Getenv(envVar); lang != "" {
if strings.Contains(strings.ToLower(lang), "zh") {
return CN
}
}
} }
if strings.Contains(strings.ToLower(lang), "zh") {
// 2. Windows 特定的语言检查
if runtime.GOOS == "windows" {
// 检查 Windows 用户默认语言设置
cmd := exec.Command("powershell", "-Command",
"[System.Globalization.CultureInfo]::CurrentUICulture.Name")
output, err := cmd.Output()
if err == nil {
lang := strings.ToLower(strings.TrimSpace(string(output)))
if strings.HasPrefix(lang, "zh") {
return CN
}
}
// 检查 Windows 系统区域设置
cmd = exec.Command("wmic", "os", "get", "locale")
output, err = cmd.Output()
if err == nil {
// Windows 语言代码 2052 表示简体中文
if strings.Contains(string(output), "2052") {
return CN
}
}
}
// 3. 检查 Unix 系统的其他语言配置
if runtime.GOOS != "windows" {
cmd := exec.Command("locale")
output, err := cmd.Output()
if err == nil && strings.Contains(strings.ToLower(string(output)), "zh_cn") {
return CN return CN
} }
}
// 默认返回英文
return EN return EN
} }
@ -558,18 +593,12 @@ func main() {
// 初始化组件 // 初始化组件
ui := NewUI(&config.UI) ui := NewUI(&config.UI)
pm := &ProcessManager{
config: &SystemConfig{
RetryAttempts: 3,
RetryDelay: time.Second,
Timeout: 30 * time.Second,
},
}
// 权限检查 // 权限检查
os.Stdout.Sync() os.Stdout.Sync()
currentLanguage = detectLanguage() currentLanguage = detectLanguage()
log.Println("Current language: ", currentLanguage)
isAdmin, err := checkAdminPrivileges() isAdmin, err := checkAdminPrivileges()
if err != nil { if err != nil {
handleError(err) handleError(err)
@ -592,6 +621,14 @@ func main() {
return return
} }
// 进程管理
pm := &ProcessManager{
config: &SystemConfig{
RetryAttempts: 3,
RetryDelay: time.Second,
Timeout: 30 * time.Second,
},
}
if checkCursorRunning() { if checkCursorRunning() {
fmt.Println("\nDetected running Cursor instance(s). Closing... / 检测到正在运行的 Cursor 实例,正在关闭...") fmt.Println("\nDetected running Cursor instance(s). Closing... / 检测到正在运行的 Cursor 实例,正在关闭...")
if err := pm.killCursorProcesses(); err != nil { if err := pm.killCursorProcesses(); err != nil {
@ -608,14 +645,19 @@ func main() {
} }
} }
// 清屏并打印标题
clearScreen() clearScreen()
// 打印标题
printCyberpunkBanner() printCyberpunkBanner()
// 读取现有配置
oldConfig, err := readExistingConfig() oldConfig, err := readExistingConfig()
if err != nil { if err != nil {
oldConfig = nil oldConfig = nil
} }
// 加载并更新配置
storageConfig, err := loadAndUpdateConfig(ui) storageConfig, err := loadAndUpdateConfig(ui)
if err != nil { if err != nil {
handleError(err) handleError(err)
@ -623,14 +665,17 @@ func main() {
return return
} }
// 显示ID修改对比
showIdComparison(oldConfig, storageConfig) showIdComparison(oldConfig, storageConfig)
// 保存配置
if err := saveConfig(storageConfig); err != nil { if err := saveConfig(storageConfig); err != nil {
handleError(err) handleError(err)
waitExit() waitExit()
return return
} }
// 显示成功信息
showSuccess() showSuccess()
fmt.Println("\nOperation completed! / 操作完成!") fmt.Println("\nOperation completed! / 操作完成!")
waitExit() waitExit()
@ -749,4 +794,3 @@ func selfElevate() error {
} }
} }
Loading…
Cancel
Save