Browse Source

feat: Enhance main.go with new process management features and multilingual support

- Added new messages for process management, including checking and closing Cursor instances, to improve user feedback.
- Introduced new fields in the TextResource struct for better multilingual support, enhancing user experience across different languages.
- Updated the ensureCursorClosed function to provide clearer status messages during the process of closing instances.
- Improved the overall structure and readability of the code related to process management.

These changes collectively enhance the application's usability and provide clearer communication to users during operation.
pull/20/head
dacrab 6 months ago
parent
commit
20b2eb74b7
  1. 1
      .gitignore
  2. 54
      main.go

1
.gitignore

@ -6,6 +6,7 @@
# Build directories # Build directories
releases/ releases/
cursor-id-modifier
# Go specific # Go specific

54
main.go

@ -56,6 +56,10 @@ type (
RunWithSudo string RunWithSudo string
SudoExample string SudoExample string
ConfigLocation string ConfigLocation string
CheckingProcesses string
ClosingProcesses string
ProcessesClosed string
PleaseWait string
} }
// StorageConfig optimized storage configuration / 优化的存储配置 // StorageConfig optimized storage configuration / 优化的存储配置
@ -126,6 +130,10 @@ var (
RunWithSudo: "请使用 sudo 命令运行此程序", RunWithSudo: "请使用 sudo 命令运行此程序",
SudoExample: "示例: sudo %s", SudoExample: "示例: sudo %s",
ConfigLocation: "配置文件位置:", ConfigLocation: "配置文件位置:",
CheckingProcesses: "正在检查运行中的 Cursor 实例...",
ClosingProcesses: "正在关闭 Cursor 实例...",
ProcessesClosed: "所有 Cursor 实例已关闭",
PleaseWait: "请稍候...",
}, },
EN: { EN: {
SuccessMessage: "[√] Configuration file updated successfully!", SuccessMessage: "[√] Configuration file updated successfully!",
@ -139,6 +147,10 @@ var (
RunWithSudo: "Please run this program with sudo", RunWithSudo: "Please run this program with sudo",
SudoExample: "Example: sudo %s", SudoExample: "Example: sudo %s",
ConfigLocation: "Config file location:", ConfigLocation: "Config file location:",
CheckingProcesses: "Checking for running Cursor instances...",
ClosingProcesses: "Closing Cursor instances...",
ProcessesClosed: "All Cursor instances have been closed",
PleaseWait: "Please wait...",
}, },
} }
) )
@ -470,7 +482,7 @@ func showSuccess() {
successColor.Printf("%s\n", text.SuccessMessage) successColor.Printf("%s\n", text.SuccessMessage)
fmt.Println() fmt.Println()
warningColor.Printf("%s\n", text.RestartMessage) warningColor.Printf("%s\n", text.RestartMessage)
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
successColor.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━���━━━")
} }
// Add spacing before config location // Add spacing before config location
@ -649,18 +661,23 @@ func waitExit() {
// Add this new function near the other process management functions // Add this new function near the other process management functions
func ensureCursorClosed() error { func ensureCursorClosed() error {
maxAttempts := 3 maxAttempts := 3
text := texts[currentLanguage]
showProcessStatus(text.CheckingProcesses)
for attempt := 1; attempt <= maxAttempts; attempt++ { for attempt := 1; attempt <= maxAttempts; attempt++ {
if !checkCursorRunning() { if !checkCursorRunning() {
showProcessStatus(text.ProcessesClosed)
fmt.Println() // New line after status
return nil return nil
} }
if currentLanguage == EN { if currentLanguage == EN {
fmt.Printf("\nPlease close Cursor before continuing. Attempt %d/%d\n", attempt, maxAttempts)
fmt.Println("Waiting 5 seconds...")
showProcessStatus(fmt.Sprintf("Please close Cursor before continuing. Attempt %d/%d\n%s",
attempt, maxAttempts, text.PleaseWait))
} else { } else {
fmt.Printf("\n请在继续之前关闭 Cursor。尝试 %d/%d\n", attempt, maxAttempts)
fmt.Println("等待 5 秒...")
showProcessStatus(fmt.Sprintf("请在继续之前关闭 Cursor。尝试 %d/%d\n%s",
attempt, maxAttempts, text.PleaseWait))
} }
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -729,7 +746,7 @@ func main() {
return return
} }
// Add this block after the privilege check
// Ensure all Cursor instances are closed
if err := ensureCursorClosed(); err != nil { if err := ensureCursorClosed(); err != nil {
if currentLanguage == EN { if currentLanguage == EN {
fmt.Println("\nError: Please close Cursor manually before running this program.") fmt.Println("\nError: Please close Cursor manually before running this program.")
@ -749,13 +766,11 @@ func main() {
}, },
} }
if checkCursorRunning() { if checkCursorRunning() {
if currentLanguage == EN {
fmt.Println("\nDetected running Cursor instance(s). Closing...")
} else {
fmt.Println("\n检测到正在运行的 Cursor 实例,正在关闭...")
}
text := texts[currentLanguage]
showProcessStatus(text.ClosingProcesses)
if err := pm.killCursorProcesses(); err != nil { if err := pm.killCursorProcesses(); err != nil {
fmt.Println() // New line after status
if currentLanguage == EN { if currentLanguage == EN {
fmt.Println("Warning: Could not close all Cursor instances. Please close them manually.") fmt.Println("Warning: Could not close all Cursor instances. Please close them manually.")
} else { } else {
@ -767,6 +782,7 @@ func main() {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
if checkCursorRunning() { if checkCursorRunning() {
fmt.Println() // New line after status
if currentLanguage == EN { if currentLanguage == EN {
fmt.Println("\nWarning: Cursor is still running. Please close it manually.") fmt.Println("\nWarning: Cursor is still running. Please close it manually.")
} else { } else {
@ -775,6 +791,9 @@ func main() {
waitExit() waitExit()
return return
} }
showProcessStatus(text.ProcessesClosed)
fmt.Println() // New line after status
} }
// Clear screen and show banner // Clear screen and show banner
@ -861,11 +880,11 @@ func printCyberpunkBanner() {
banner := ` banner := `
` `
cyan.Println(banner) cyan.Println(banner)
yellow.Println("\t\t>> Cursor ID Modifier v1.0 <<") yellow.Println("\t\t>> Cursor ID Modifier v1.0 <<")
@ -924,3 +943,10 @@ func loadAndUpdateConfig(ui *UI, username string) (*StorageConfig, error) { // a
ui.showProgress(text.GeneratingIds) ui.showProgress(text.GeneratingIds)
return NewStorageConfig(oldConfig), nil return NewStorageConfig(oldConfig), nil
} }
// Add a new function to show process status
func showProcessStatus(message string) {
cyan := color.New(color.FgCyan)
fmt.Printf("\r%s", strings.Repeat(" ", 80)) // Clear line
fmt.Printf("\r%s", cyan.Sprint("⚡ "+message))
}
Loading…
Cancel
Save