diff --git a/cmd/cursor-id-modifier/main.go b/cmd/cursor-id-modifier/main.go index 856a816..860b444 100644 --- a/cmd/cursor-id-modifier/main.go +++ b/cmd/cursor-id-modifier/main.go @@ -272,7 +272,6 @@ func showCompletionMessages(display *ui.Display) { message = "操作完成!" } display.ShowInfo(message) - fmt.Println() } func waitExit() { diff --git a/internal/lang/lang.go b/internal/lang/lang.go index 5b6ddde..973fc24 100644 --- a/internal/lang/lang.go +++ b/internal/lang/lang.go @@ -13,7 +13,7 @@ type Language string const ( // CN represents Chinese language CN Language = "cn" - // EN represents English language + // EN represents English language EN Language = "en" ) @@ -151,7 +151,7 @@ var texts = map[Language]TextResource{ RunAsAdmin: "请右键点击程序,选择「以管理员身份运行」", RunWithSudo: "请使用 sudo 命令运行此程序", SudoExample: "示例: sudo %s", - PressEnterToExit: "按回车键退出程序...", + PressEnterToExit: "\n按回车键退出程序...", SetReadOnlyMessage: "设置 storage.json 为只读模式, 这将导致 workspace 记录信息丢失等问题", // Info messages @@ -178,7 +178,7 @@ var texts = map[Language]TextResource{ RunAsAdmin: "Please right-click and select 'Run as Administrator'", RunWithSudo: "Please run this program with sudo", SudoExample: "Example: sudo %s", - PressEnterToExit: "Press Enter to exit...", + PressEnterToExit: "\nPress Enter to exit...", SetReadOnlyMessage: "Set storage.json to read-only mode, which will cause issues such as lost workspace records", // Info messages diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 18e6cb9..b411308 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1,9 +1,18 @@ # Auto-elevate to admin rights if not already running as admin -if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - Write-Host "Requesting administrator privileges..." - $arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -ExecutionFromElevated" - Start-Process powershell.exe -ArgumentList $arguments -Verb RunAs - Exit +$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") +if (-NOT $isAdmin) { + try { + Write-Host "Requesting administrator privileges..." -ForegroundColor Cyan + $argList = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" + Start-Process powershell.exe -Verb RunAs -ArgumentList $argList -Wait + exit + } + catch { + Write-Host "Failed to get admin rights. Please run as Administrator." -ForegroundColor Red + Write-Host "Press any key to exit..." + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') + exit 1 + } } # Set TLS to 1.2 @@ -24,6 +33,8 @@ function Cleanup { trap { Write-Host "Error: $_" -ForegroundColor Red Cleanup + Write-Host "Press any key to exit..." + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') exit 1 } @@ -75,18 +86,31 @@ function Install-CursorModifier { $latestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/dacrab/go-cursor-help/releases/latest" Write-Host "Found latest release: $($latestRelease.tag_name)" -ForegroundColor Cyan - # Updated binary name format to match actual assets - $binaryName = "cursor-id-modifier_windows_$arch.exe" - Write-Host "Looking for asset: $binaryName" -ForegroundColor Cyan + # Look for Windows binary with our architecture + $possibleNames = @( + "cursor-id-modifier_windows_$($arch).exe", + "cursor-id-modifier_windows_$($arch).exe.exe", + "cursor-id-modifier_Windows_$($arch).exe", + "cursor-id-modifier_Windows_$($arch).exe.exe" + ) - $asset = $latestRelease.assets | Where-Object { $_.name -eq $binaryName } - $downloadUrl = $asset.browser_download_url - - if (!$downloadUrl) { - Write-Host "Available assets:" -ForegroundColor Yellow - $latestRelease.assets | ForEach-Object { Write-Host $_.name } - throw "Could not find download URL for $binaryName" + $asset = $null + foreach ($name in $possibleNames) { + Write-Host "Checking for asset: $name" -ForegroundColor Cyan + $asset = $latestRelease.assets | Where-Object { $_.name -eq $name } + if ($asset) { + Write-Host "Found matching asset: $($asset.name)" -ForegroundColor Green + break + } } + + if (!$asset) { + Write-Host "`nAvailable assets:" -ForegroundColor Yellow + $latestRelease.assets | ForEach-Object { Write-Host "- $($_.name)" } + throw "Could not find appropriate Windows binary for $arch architecture" + } + + $downloadUrl = $asset.browser_download_url } catch { Write-Host "Failed to get latest release: $_" -ForegroundColor Red @@ -94,7 +118,7 @@ function Install-CursorModifier { } # Download binary - Write-Host "Downloading latest release from $downloadUrl..." -ForegroundColor Cyan + Write-Host "`nDownloading latest release..." -ForegroundColor Cyan $binaryPath = Join-Path $TmpDir "cursor-id-modifier.exe" if (!(Get-FileWithProgress -Url $downloadUrl -OutputFile $binaryPath)) { @@ -138,8 +162,15 @@ function Install-CursorModifier { try { Install-CursorModifier } +catch { + Write-Host "Installation failed: $_" -ForegroundColor Red + Cleanup + Write-Host "Press any key to exit..." + $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') + exit 1 +} finally { Cleanup - Write-Host "Press any key to continue..." + Write-Host "Press any key to exit..." -ForegroundColor Green $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') } \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh index 75ee94a..3b49765 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -20,7 +20,7 @@ detect_system() { case "$(uname -s)" in Linux*) os="linux";; Darwin*) os="darwin";; - *) echo "Unsupported OS"; exit 1;; + *) echo -e "${RED}Unsupported OS${NC}"; exit 1;; esac case "$(uname -m)" in @@ -32,7 +32,11 @@ detect_system() { arch="arm64" [ "$os" = "darwin" ] && suffix="_apple_silicon" ;; - *) echo "Unsupported architecture"; exit 1;; + i386|i686) + arch="x86" + [ "$os" = "darwin" ] && { echo -e "${RED}32-bit not supported on macOS${NC}"; exit 1; } + ;; + *) echo -e "${RED}Unsupported architecture${NC}"; exit 1;; esac echo "$os $arch $suffix" @@ -48,7 +52,7 @@ download() { elif command -v wget >/dev/null 2>&1; then wget --show-progress -q "$url" -O "$output" else - echo "Error: curl or wget is required" + echo -e "${RED}Error: curl or wget is required${NC}" exit 1 fi } @@ -59,12 +63,42 @@ setup_install_dir() { if [ ! -d "$install_dir" ]; then mkdir -p "$install_dir" || { - echo "Failed to create installation directory" + echo -e "${RED}Failed to create installation directory${NC}" exit 1 } fi } +# Find matching asset from release +find_asset() { + local json="$1" + local os="$2" + local arch="$3" + local suffix="$4" + + # Try possible binary names + local binary_names=( + "cursor-id-modifier_${os}_${arch}${suffix}" # lowercase os + "cursor-id-modifier_$(tr '[:lower:]' '[:upper:]' <<< ${os:0:1})${os:1}_${arch}${suffix}" # capitalized os + ) + + local url="" + for name in "${binary_names[@]}"; do + echo -e "${BLUE}Looking for asset: $name${NC}" + url=$(echo "$json" | grep -o "\"browser_download_url\": \"[^\"]*${name}\"" | cut -d'"' -f4) + if [ -n "$url" ]; then + echo -e "${GREEN}Found matching asset: $name${NC}" + echo "$url" + return 0 + fi + done + + # If no match found, show available assets + echo -e "${YELLOW}Available assets:${NC}" + echo "$json" | grep "\"name\":" | cut -d'"' -f4 + return 1 +} + # Main installation function main() { echo -e "${BLUE}Starting installation...${NC}" @@ -80,13 +114,16 @@ main() { # Setup installation directory setup_install_dir "$INSTALL_DIR" - # Download latest release + # Get latest release info + echo -e "${BLUE}Fetching latest release information...${NC}" LATEST_URL="https://api.github.com/repos/dacrab/go-cursor-help/releases/latest" - BINARY_NAME="cursor-id-modifier_${OS}_${ARCH}${SUFFIX}" - DOWNLOAD_URL=$(curl -s "$LATEST_URL" | grep "browser_download_url.*${BINARY_NAME}" | cut -d '"' -f 4) + RELEASE_JSON=$(curl -s "$LATEST_URL") + + # Find matching asset + DOWNLOAD_URL=$(find_asset "$RELEASE_JSON" "$OS" "$ARCH" "$SUFFIX") if [ -z "$DOWNLOAD_URL" ]; then - echo -e "${RED}Error: Could not find download URL for $OS $ARCH${NC}" + echo -e "${RED}Error: Could not find appropriate binary for $OS $ARCH${NC}" exit 1 fi