From 9cec58ca28f76d96b37602531e4535d796d84de7 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 15:25:09 +0800 Subject: [PATCH 01/18] =?UTF-8?q?README=20=E9=80=82=E9=85=8D=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf06392..9732dbb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rime Mate (Rime 配置助手) -**让 macOS/Linux 上的 Rime (鼠须管/中州韻) 输入法配置变得简单、直观、可视化。** +**让 macOS/Linux/Windows 上的 Rime (中州韻) 输入法配置变得简单、直观、可视化。** ![Rime Mate 截图](./rime-mate.jpg) @@ -37,6 +37,10 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了 1. 打开 Rime 配置文件夹(iBus: `~/.config/ibus/rime`, Fcitx5: `~/.local/share/fcitx5/rime`)。 2. 你会看到一个名为 **`Rime配置助手.desktop`** 的文件,**双击运行**它。 3. 在弹出的窗口中,使用键盘 `↑` `↓` 选择功能,按 `Enter` 确认即可。 +- Windows: + 1. 打开 Rime 配置文件夹(`%APPDATA%\Rime`)。 + 2. 你会看到一个名为 **`Rime配置助手.bat`** 的文件,**双击运行**它。 + 3. 在弹出的窗口中,使用键盘 `↑` `↓` 选择功能,按 `Enter` 确认即可。 ### 3. 更新 @@ -47,6 +51,7 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了 在 Rime 的配置文件夹中: - macOS:删除`Rime配置助手.command`文件和`rime-mate-config`文件夹。 - Linux:删除`Rime配置助手.desktop`文件和`rime-mate-config`文件夹。 +- Windows:删除`Rime配置助手.bat`文件和`rime-mate-config`文件夹。 ## ❓ 常见问题 From 80eff60c90ff5f37d2c4880e933e87edab49badb Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 15:25:53 +0800 Subject: [PATCH 02/18] =?UTF-8?q?Windows=20=E7=BC=96=E8=AF=91=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 88 +++++++--------- build.sh | 13 +++ module/ohMyRime/lang_model.go | 21 +++- setup.sh | 193 +++++++++++++++++----------------- 4 files changed, 164 insertions(+), 151 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f89bf8..7d41dd9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,61 +3,49 @@ name: Build and Release on: push: tags: - - "v*" + - "v*" workflow_dispatch: + permissions: contents: write jobs: build-and-release: runs-on: ubuntu-latest + steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - cache: true - - - name: Vendor dependencies - run: go mod vendor - - - name: Cross compile - run: | - mkdir -p output - declare -a targets=( - "linux amd64" - "linux arm64" - "darwin amd64" - "darwin arm64" - ) - for target in "${targets[@]}"; do - GOOS=$(echo $target | cut -d' ' -f1) - GOARCH=$(echo $target | cut -d' ' -f2) - BIN_NAME="rime-mate-${GOOS}-${GOARCH}" - echo "🔨 Compiling ${BIN_NAME} (GOOS=${GOOS}, GOARCH=${GOARCH})" - CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o output/${BIN_NAME} . - if [ ! -f "output/${BIN_NAME}" ]; then - echo "❌ Compilation of ${BIN_NAME} failed" - exit 1 - fi - chmod +x output/${BIN_NAME} - done - - - name: Copy setup.sh to output - run: cp setup.sh output/ - - - name: Create Draft Release - uses: softprops/action-gh-release@v1 - with: - draft: true - files: | - output/rime-mate-linux-amd64 - output/rime-mate-linux-arm64 - output/rime-mate-darwin-amd64 - output/rime-mate-darwin-arm64 - output/setup.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Vendor dependencies + run: go mod vendor + + - name: Make build.sh executable + run: chmod +x build.sh + + - name: Run build script + run: ./build.sh + + - name: Copy setup.sh to output + run: cp setup.sh output/ + + - name: Create Draft Release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: | + output/rime-mate-darwin-amd64 + output/rime-mate-darwin-arm64 + output/rime-mate-linux-amd64 + output/rime-mate-linux-arm64 + output/rime-mate-windows-amd64.exe + output/rime-mate-windows-arm64.exe + output/setup.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.sh b/build.sh index ee21b06..e40474b 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +export CGO_ENABLED=0 + # Build script - Compile for macOS executable + Linux executable echo "Building rime-mate..." @@ -29,6 +31,15 @@ GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/ echo "Building for Linux ARM64 (aarch64)..." GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-linux-arm64" . +# Build for Windows executable +# GOOS=windows GOARCH=amd64 - for x86_64 Windows +# GOOS=windows GOARCH=arm64 - for ARM64 Windows (arm64) + +echo "Building for Windows x86_64..." +GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-windows-amd64.exe" . + +echo "Building for Windows ARM64 (arm64)..." +GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-windows-arm64.exe" . if [ $? -eq 0 ]; then @@ -38,6 +49,8 @@ if [ $? -eq 0 ]; then echo " ./output/${OUTPUT}-darwin-arm64" echo " ./output/${OUTPUT}-linux-amd64" echo " ./output/${OUTPUT}-linux-arm64" + echo " ./output/${OUTPUT}-windows-amd64.exe" + echo " ./output/${OUTPUT}-windows-arm64.exe" else echo "✗ Build failed" exit 1 diff --git a/module/ohMyRime/lang_model.go b/module/ohMyRime/lang_model.go index 33ea7b3..4f41459 100644 --- a/module/ohMyRime/lang_model.go +++ b/module/ohMyRime/lang_model.go @@ -2,19 +2,20 @@ package ohMyRime import ( "fmt" - "github.com/goccy/go-yaml" "os" "path/filepath" "rime-mate/util" "runtime" "slices" + + "github.com/goccy/go-yaml" ) func loadResourceURLs() (string, string) { rimeDir, err := getCrossPlatformRimeDir() if err != nil { - util.Error("获取RIME配置目录失败: " + err.Error()) - rimeDir = util.TransformPath("~/Library/Rime/") + util.Error("获取 Rime 配置目录失败: " + err.Error()) + os.Exit(1) } langModelPath := filepath.Join(rimeDir, "wanxiang-lts-zh-hans.gram") @@ -31,7 +32,11 @@ func getCrossPlatformRimeDir() (string, error) { switch runtime.GOOS { case "darwin": - return filepath.Join(home, "Library/Rime"), nil + path := filepath.Join(home, "Library/Rime") + if _, err := os.Stat(path); err == nil { + return path, nil + } + return "", fmt.Errorf("未找到 macOS 下的 Rime 配置目录") case "linux": paths := []string{ filepath.Join(home, ".config/ibus/rime"), @@ -42,7 +47,13 @@ func getCrossPlatformRimeDir() (string, error) { return p, nil } } - return "", fmt.Errorf("未找到Linux下的RIME配置目录,请检查是否安装IBus-RIME/Fcitx5-RIME") + return "", fmt.Errorf("未找到 Linux 下的 Rime 配置目录,请检查是否安装 iBus-Rime/Fcitx5-Rime") + case "windows": + path := filepath.Join(home, "AppData/Roaming/Rime") + if _, err := os.Stat(path); err == nil { + return path, nil + } + return "", fmt.Errorf("未找到 Windows 下的 Rime 配置目录") default: return "", fmt.Errorf("不支持的系统: %s", runtime.GOOS) } diff --git a/setup.sh b/setup.sh index e868e4a..ffaa935 100644 --- a/setup.sh +++ b/setup.sh @@ -1,13 +1,30 @@ -#!/bin/sh +#!/bin/bash # ================= 配置区 ================= REPO="hunter-ji/rime-mate" BASE_URL="https://github.com/$REPO/releases/latest/download" TOOL_NAME="rime-mate" +detect_system() { + case "$(uname -s)" in + Darwin) + echo "Darwin" + ;; + Linux) + echo "Linux" + ;; + MINGW*|MSYS*|CYGWIN*) + echo "Windows" + ;; + *) + echo "UNKNOWN" + ;; + esac +} + detect_rime_dir() { home="$HOME" - system="$(uname -s)" + system="$(detect_system)" case "$system" in Darwin) @@ -15,7 +32,7 @@ detect_rime_dir() { ;; Linux) rime_dir="" - echo "🔍 正在检查Linux下的RIME配置路径:" + echo "🔍 正在检查 Linux 下的 Rime 配置路径:" if [ -d "$home/.config/ibus/rime" ]; then echo " - $home/.config/ibus/rime (存在? 是)" rime_dir="$home/.config/ibus/rime" @@ -31,48 +48,81 @@ detect_rime_dir() { fi fi if [ -z "$rime_dir" ]; then - echo "❌ Linux 下未找到 RIME 配置目录,请先安装 IBus-RIME/Fcitx5-RIME" + echo "❌ Linux 下未找到 Rime 配置目录,请先安装 IBus-Rime/Fcitx5-Rime" + exit 1 + fi + ;; + Windows) + rime_dir="" + echo "🔍 正在检查Windows下的小狼毫(Rime)配置:" + + uninstall_reg_path="HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Weasel" + if reg query "$uninstall_reg_path" >/dev/null 2>&1; then + echo " - 小狼毫是否安装? 是" + else + echo " - 小狼毫是否安装? 否" + echo "❌ Windows 下未检测到小狼毫输入法,请先安装" + exit 1 + fi + + user_reg_path="HKCU\\Software\\Rime\\Weasel" + reg_value=$(reg query "$user_reg_path" /v "RimeUserDir" 2>/dev/null \ + | grep -i "RimeUserDir" | awk '{print $NF}') + + if [ -n "$reg_value" ] && [ -d "$reg_value" ]; then + echo " - 注册表 RimeUserDir: $reg_value (存在? 是)" + rime_dir="$reg_value" + elif [ -n "$reg_value" ]; then + echo " - 注册表 RimeUserDir: $reg_value (存在? 否,路径无效)" + exit 1 + else + echo "❌ 请使用小狼毫配置工具选择自定义配置目录" exit 1 fi ;; *) - echo "❌ 不支持的操作系统: $(uname -s)" + echo "❌ 不支持的操作系统" exit 1 ;; esac - if [ ! -d "$rime_dir" ]; then - echo "❌ 未检测到 Rime 配置目录: $rime_dir" - echo "请先安装对应系统的 Rime 输入法(macOS:鼠须管;Linux:IBus-RIME/Fcitx5-RIME)" - exit 1 - fi - echo "✅ 检测到 RIME 配置目录:$rime_dir" + echo "✅ 检测到 Rime 配置目录:$rime_dir" export RIME_DIR="$rime_dir" } echo "⏳ 正在准备环境..." detect_rime_dir -# 所有文件都放在 Rime 配置目录下 -system="$(uname -s)" +system="$(detect_system)" if [ "$system" = "Darwin" ]; then COMMAND_LINK="$RIME_DIR/Rime配置助手.command" -else +elif [ "$system" = "Linux" ]; then COMMAND_LINK="$RIME_DIR/Rime配置助手.desktop" +elif [ "$system" = "Windows" ]; then + COMMAND_LINK="$RIME_DIR/Rime配置助手.bat" +else + echo "❌ 不支持的操作系统" + exit 1 fi RIME_CONFIG_DIR="$RIME_DIR/rime-mate-config" -BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME" +if [ "$system" = "Windows" ]; then + BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME.exe" +else + BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME" +fi + VERSION_FILE="$RIME_CONFIG_DIR/version" # ========================================= get_os_arch() { - system="$(uname -s)" + system="$(detect_system)" arch="$(uname -m)" case "$system" in Darwin) os="darwin" ;; Linux) os="linux" ;; + Windows) os="windows" ;; *) echo "❌ 不支持的系统"; exit 1 ;; esac @@ -82,53 +132,28 @@ get_os_arch() { *) echo "❌ 不支持的架构:$arch"; exit 1 ;; esac - echo "${TOOL_NAME}-${os}-${arch}" + if [ "$os" = "windows" ]; then + echo "${TOOL_NAME}-${os}-${arch}.exe" + else + echo "${TOOL_NAME}-${os}-${arch}" + fi } FILE_NAME="$(get_os_arch)" -# --- 步骤A: 环境检测与版本检查 --- +# --- 步骤A: 版本检测 --- MISSING_FILES=false -if [ ! -f "$COMMAND_LINK" ] || [ ! -f "$BINARY_PATH" ] || [ ! -f "$VERSION_FILE" ]; then - MISSING_FILES=true -fi - -if [ "$MISSING_FILES" = true ]; then - echo "✨ 检测到首次安装或文件缺失,正在获取版本信息..." -else - echo "🔍 环境完整,正在检查更新..." -fi +[ ! -f "$COMMAND_LINK" ] && MISSING_FILES=true +[ ! -f "$BINARY_PATH" ] && MISSING_FILES=true +[ ! -f "$VERSION_FILE" ] && MISSING_FILES=true LATEST_VERSION="$(curl -s "https://api.github.com/repos/$REPO/releases/latest" \ | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" -if [ -z "$LATEST_VERSION" ]; then - echo "⚠️ 版本信息获取失败,可能是网络或代理问题,将尝试不使用代理获取版本信息" - LATEST_VERSION="$(curl -s --noproxy "*" "https://api.github.com/repos/$REPO/releases/latest" \ - | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" -fi - NEED_DOWNLOAD=false -VERSION_TO_WRITE="" - -if [ -z "$LATEST_VERSION" ]; then - echo "⚠️ 无法获取最新版本信息,将尝试强制安装..." +if [ "$MISSING_FILES" = true ]; then + NEED_DOWNLOAD=true +elif [ "$(cat "$VERSION_FILE")" != "$LATEST_VERSION" ]; then NEED_DOWNLOAD=true - VERSION_TO_WRITE="unknown" -else - VERSION_TO_WRITE="$LATEST_VERSION" - if [ "$MISSING_FILES" = true ]; then - echo "⬇️ 准备下载版本: $LATEST_VERSION" - NEED_DOWNLOAD=true - else - LOCAL_VERSION="$(cat "$VERSION_FILE")" - if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]; then - echo "✅ 当前已是最新版本 ($LOCAL_VERSION)" - NEED_DOWNLOAD=false - else - echo "⬆️ 发现新版本 ($LOCAL_VERSION -> $LATEST_VERSION)" - NEED_DOWNLOAD=true - fi - fi fi if [ "$NEED_DOWNLOAD" = true ]; then @@ -136,71 +161,47 @@ if [ "$NEED_DOWNLOAD" = true ]; then mkdir -p "$RIME_CONFIG_DIR" curl -L "$BASE_URL/$FILE_NAME" -o "$BINARY_PATH" - if [ ! -s "$BINARY_PATH" ]; then - echo "❌ 下载失败或文件为空,请检查网络连接或服务器状态。" - rm -f "$BINARY_PATH" - exit 1 - fi + [ ! -s "$BINARY_PATH" ] && echo "❌ 下载失败" && exit 1 - echo "$VERSION_TO_WRITE" > "$VERSION_FILE" + echo "$LATEST_VERSION" > "$VERSION_FILE" chmod +x "$BINARY_PATH" - if [ "$(uname -s)" = "Darwin" ]; then + if [ "$system" = "Darwin" ]; then xattr -d com.apple.quarantine "$BINARY_PATH" 2>/dev/null fi fi -# --- 步骤B: 在 Rime 配置目录生成“快捷方式” --- - +# --- 步骤B: 生成快捷方式 --- if [ ! -f "$COMMAND_LINK" ]; then - echo "🖥️ 正在 Rime 配置目录生成快捷方式..." - - if [ "$(uname -s)" = "Darwin" ]; then + if [ "$system" = "Darwin" ]; then cat < "$COMMAND_LINK" #!/bin/bash -TARGET_DIR="$RIME_DIR" -if [ "\$(pwd)" != "\$TARGET_DIR" ]; then - cd "\$TARGET_DIR" -fi +cd "$RIME_DIR" ./rime-mate-config/$TOOL_NAME -echo "" EOF - else + elif [ "$system" = "Linux" ]; then cat < "$COMMAND_LINK" [Desktop Entry] Type=Application Name=Rime配置助手 -Exec=sh -c 'cd "$RIME_DIR" && ./rime-mate-config/$TOOL_NAME'; +Exec=sh -c 'cd "$RIME_DIR" && ./rime-mate-config/$TOOL_NAME' Terminal=true -Icon=utilities-terminal -Categories=Utility; +EOF + elif [ "$system" = "Windows" ]; then + cat < "$COMMAND_LINK" +@echo off +cd /d "%~dp0" +start rime-mate-config\\$TOOL_NAME.exe EOF fi chmod +x "$COMMAND_LINK" - - if [ "$(uname -s)" = "Darwin" ]; then - xattr -d com.apple.quarantine "$COMMAND_LINK" 2>/dev/null - fi - - echo "✅ 快捷方式已创建:$COMMAND_LINK" - if [ "$(uname -s)" = "Darwin" ]; then - echo "🛠️ 打开 RIME 配置目录后,双击 'Rime配置助手.command' 即可启动配置助手。" - fi - if [ "$(uname -s)" = "Linux" ]; then - echo "🛠️ 打开 RIME 配置目录后,双击 'Rime配置助手.desktop' 即可启动配置助手。" - fi fi -# --- 步骤C: 打开配置文件夹 --- -echo "📂 正在打开 RIME 配置目录..." -case "$(uname -s)" in +# --- 步骤C: 打开配置目录 --- +echo "📂 正在打开 Rime 配置目录..." +case "$system" in Darwin) open "$RIME_DIR" ;; - Linux) - if command -v xdg-open >/dev/null 2>&1; then - xdg-open "$RIME_DIR" - else - echo "⚠️ 未找到 xdg-open,无法自动打开文件夹,手动路径:$RIME_DIR" - fi - ;; + Linux) command -v xdg-open >/dev/null && xdg-open "$RIME_DIR" ;; + Windows) explorer "$RIME_DIR" ;; esac From b6c536352ba6047a2b79dcc096254add9ca8ed0a Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 16:20:17 +0800 Subject: [PATCH 03/18] =?UTF-8?q?Windows=E8=84=9A=E6=9C=AC=E5=88=86?= =?UTF-8?q?=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.ps1 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 53 ++------------------------------------ 2 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 setup.ps1 diff --git a/setup.ps1 b/setup.ps1 new file mode 100644 index 0000000..707b02a --- /dev/null +++ b/setup.ps1 @@ -0,0 +1,76 @@ +# ================= 配置区 ================= +$Repo = "hunter-ji/rime-mate" +$BaseUrl = "https://github.com/$Repo/releases/latest/download" +$ToolName = "rime-mate" +# ========================================= + +Write-Host "⏳ 正在准备环境..." + +$uninstallKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Weasel" +if (-not (Test-Path $uninstallKey)) { + Write-Host "❌ 未检测到小狼毫(Weasel),请先安装后再运行本脚本" + exit 1 +} +Write-Host "✅ 已检测到小狼毫" + +$userKey = "HKCU:\Software\Rime\Weasel" +$rimeDir = (Get-ItemProperty -Path $userKey -Name RimeUserDir -ErrorAction SilentlyContinue).RimeUserDir + +if (-not $rimeDir -or -not (Test-Path $rimeDir)) { + Write-Host "❌ 未找到 Rime 用户目录,请在小狼毫配置工具中设置『用户目录』" + exit 1 +} + +Write-Host "✅ Rime 配置目录:$rimeDir" + +$configDir = Join-Path $rimeDir "rime-mate-config" +$exePath = Join-Path $configDir "$ToolName.exe" +$versionFile = Join-Path $configDir "version" + +$arch = switch ($env:PROCESSOR_ARCHITECTURE) { + "AMD64" { "amd64" } + "ARM64" { "arm64" } + default { throw "不支持的 Windows 架构: $env:PROCESSOR_ARCHITECTURE" } +} + +$fileName = "$ToolName-windows-$arch.exe" + +$needDownload = $true + +try { + $latest = (Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest").tag_name + if (Test-Path $versionFile) { + if ((Get-Content $versionFile) -eq $latest -and (Test-Path $exePath)) { + $needDownload = $false + } + } +} catch { + Write-Host "⚠️ 无法获取最新版本信息,将强制下载" +} + +if ($needDownload) { + Write-Host "⬇️ 正在下载 $fileName ..." + New-Item -ItemType Directory -Force -Path $configDir | Out-Null + + $url = "$BaseUrl/$fileName" + Invoke-WebRequest -Uri $url -OutFile $exePath + + if (-not (Test-Path $exePath)) { + Write-Host "❌ 下载失败" + exit 1 + } + + $latest | Out-File -Encoding ascii $versionFile +} + +$batPath = Join-Path $rimeDir "Rime配置助手.bat" +if (-not (Test-Path $batPath)) { +@" +@echo off +cd /d "%~dp0" +start rime-mate-config\$ToolName.exe +"@ | Out-File -Encoding ascii $batPath +} + +Write-Host "📂 正在打开 Rime 配置目录..." +explorer.exe $rimeDir diff --git a/setup.sh b/setup.sh index ffaa935..e1df38f 100644 --- a/setup.sh +++ b/setup.sh @@ -13,9 +13,6 @@ detect_system() { Linux) echo "Linux" ;; - MINGW*|MSYS*|CYGWIN*) - echo "Windows" - ;; *) echo "UNKNOWN" ;; @@ -52,34 +49,6 @@ detect_rime_dir() { exit 1 fi ;; - Windows) - rime_dir="" - echo "🔍 正在检查Windows下的小狼毫(Rime)配置:" - - uninstall_reg_path="HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Weasel" - if reg query "$uninstall_reg_path" >/dev/null 2>&1; then - echo " - 小狼毫是否安装? 是" - else - echo " - 小狼毫是否安装? 否" - echo "❌ Windows 下未检测到小狼毫输入法,请先安装" - exit 1 - fi - - user_reg_path="HKCU\\Software\\Rime\\Weasel" - reg_value=$(reg query "$user_reg_path" /v "RimeUserDir" 2>/dev/null \ - | grep -i "RimeUserDir" | awk '{print $NF}') - - if [ -n "$reg_value" ] && [ -d "$reg_value" ]; then - echo " - 注册表 RimeUserDir: $reg_value (存在? 是)" - rime_dir="$reg_value" - elif [ -n "$reg_value" ]; then - echo " - 注册表 RimeUserDir: $reg_value (存在? 否,路径无效)" - exit 1 - else - echo "❌ 请使用小狼毫配置工具选择自定义配置目录" - exit 1 - fi - ;; *) echo "❌ 不支持的操作系统" exit 1 @@ -98,19 +67,13 @@ if [ "$system" = "Darwin" ]; then COMMAND_LINK="$RIME_DIR/Rime配置助手.command" elif [ "$system" = "Linux" ]; then COMMAND_LINK="$RIME_DIR/Rime配置助手.desktop" -elif [ "$system" = "Windows" ]; then - COMMAND_LINK="$RIME_DIR/Rime配置助手.bat" else echo "❌ 不支持的操作系统" exit 1 fi RIME_CONFIG_DIR="$RIME_DIR/rime-mate-config" -if [ "$system" = "Windows" ]; then - BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME.exe" -else - BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME" -fi +BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME" VERSION_FILE="$RIME_CONFIG_DIR/version" # ========================================= @@ -122,7 +85,6 @@ get_os_arch() { case "$system" in Darwin) os="darwin" ;; Linux) os="linux" ;; - Windows) os="windows" ;; *) echo "❌ 不支持的系统"; exit 1 ;; esac @@ -132,11 +94,7 @@ get_os_arch() { *) echo "❌ 不支持的架构:$arch"; exit 1 ;; esac - if [ "$os" = "windows" ]; then - echo "${TOOL_NAME}-${os}-${arch}.exe" - else - echo "${TOOL_NAME}-${os}-${arch}" - fi + echo "${TOOL_NAME}-${os}-${arch}" } FILE_NAME="$(get_os_arch)" @@ -186,12 +144,6 @@ Type=Application Name=Rime配置助手 Exec=sh -c 'cd "$RIME_DIR" && ./rime-mate-config/$TOOL_NAME' Terminal=true -EOF - elif [ "$system" = "Windows" ]; then - cat < "$COMMAND_LINK" -@echo off -cd /d "%~dp0" -start rime-mate-config\\$TOOL_NAME.exe EOF fi @@ -203,5 +155,4 @@ echo "📂 正在打开 Rime 配置目录..." case "$system" in Darwin) open "$RIME_DIR" ;; Linux) command -v xdg-open >/dev/null && xdg-open "$RIME_DIR" ;; - Windows) explorer "$RIME_DIR" ;; esac From f1bc14421e42f724f1bc112cf3357a96885ce4d8 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 16:20:37 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Windows=E9=80=82?= =?UTF-8?q?=E5=BA=94=E6=80=A7=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9732dbb..54245d0 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,21 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了 ### 1. 安装 -打开你的“终端”应用 (Terminal),复制并运行以下命令: - -```bash -/bin/bash -c "$(curl -fsSL https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.sh)" -``` +- **macOS/Linux用户:** + + 打开你的“终端”应用 (Terminal),复制并运行以下命令: + + ```bash + /bin/bash -c "$(curl -fsSL https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.sh)" + ``` + +- **Windows用户:** + + 按 `Win + R` 打开运行对话框,输入 `powershell` 并按 `Enter` 打开,复制并运行以下命令: + ```shell + powershell -NoProfile -ExecutionPolicy Bypass -Command ` + "irm https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.ps1 | iex" + ``` 脚本会自动下载最新版本,并在你的 Rime 配置目录中创建一个快捷方式。 @@ -38,7 +48,7 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了 2. 你会看到一个名为 **`Rime配置助手.desktop`** 的文件,**双击运行**它。 3. 在弹出的窗口中,使用键盘 `↑` `↓` 选择功能,按 `Enter` 确认即可。 - Windows: - 1. 打开 Rime 配置文件夹(`%APPDATA%\Rime`)。 + 1. 打开 Rime 配置文件夹(`%APPDATA%\Rime`或小狼毫配置工具自定义目录)。 2. 你会看到一个名为 **`Rime配置助手.bat`** 的文件,**双击运行**它。 3. 在弹出的窗口中,使用键盘 `↑` `↓` 选择功能,按 `Enter` 确认即可。 From 1c524345646cbb527afcf71e7b5331f172f91918 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 16:21:21 +0800 Subject: [PATCH 05/18] =?UTF-8?q?Windows=20Rime=E6=B3=A8=E5=86=8C=E8=A1=A8?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/ohMyRime/lang_model.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/module/ohMyRime/lang_model.go b/module/ohMyRime/lang_model.go index 4f41459..d11da0f 100644 --- a/module/ohMyRime/lang_model.go +++ b/module/ohMyRime/lang_model.go @@ -3,10 +3,12 @@ package ohMyRime import ( "fmt" "os" + "os/exec" "path/filepath" "rime-mate/util" "runtime" "slices" + "strings" "github.com/goccy/go-yaml" ) @@ -49,10 +51,29 @@ func getCrossPlatformRimeDir() (string, error) { } return "", fmt.Errorf("未找到 Linux 下的 Rime 配置目录,请检查是否安装 iBus-Rime/Fcitx5-Rime") case "windows": - path := filepath.Join(home, "AppData/Roaming/Rime") + cmd := exec.Command( + "reg", + "query", + `HKCU\Software\Rime\Weasel`, + "/v", + "RimeUserDir", + ) + output, err := cmd.Output() + if err == nil { + fields := strings.Fields(string(output)) + if len(fields) > 0 { + regPath := fields[len(fields)-1] + if _, err := os.Stat(regPath); err == nil { + return regPath, nil + } + } + } + + path := filepath.Join(home, "AppData", "Roaming", "Rime") if _, err := os.Stat(path); err == nil { return path, nil } + return "", fmt.Errorf("未找到 Windows 下的 Rime 配置目录") default: return "", fmt.Errorf("不支持的系统: %s", runtime.GOOS) From 1eecb519f3313c6afe8b8f077bfdcf0d1dd14d2e Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 16:21:41 +0800 Subject: [PATCH 06/18] =?UTF-8?q?Windows=20=E8=84=9A=E6=9C=AC=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d41dd9..5d36672 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,8 +32,10 @@ jobs: - name: Run build script run: ./build.sh - - name: Copy setup.sh to output - run: cp setup.sh output/ + - name: Copy setup script to output + run: | + cp setup.sh output/ + cp setup.ps1 output/ - name: Create Draft Release uses: softprops/action-gh-release@v1 @@ -47,5 +49,6 @@ jobs: output/rime-mate-windows-amd64.exe output/rime-mate-windows-arm64.exe output/setup.sh + output/setup.ps1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d590bb6086401cf2bc46dc61bf51d26674ceec7f Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:36:17 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=B8=A6DOM?= =?UTF-8?q?=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.ps1 | 76 ------------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 setup.ps1 diff --git a/setup.ps1 b/setup.ps1 deleted file mode 100644 index 707b02a..0000000 --- a/setup.ps1 +++ /dev/null @@ -1,76 +0,0 @@ -# ================= 配置区 ================= -$Repo = "hunter-ji/rime-mate" -$BaseUrl = "https://github.com/$Repo/releases/latest/download" -$ToolName = "rime-mate" -# ========================================= - -Write-Host "⏳ 正在准备环境..." - -$uninstallKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Weasel" -if (-not (Test-Path $uninstallKey)) { - Write-Host "❌ 未检测到小狼毫(Weasel),请先安装后再运行本脚本" - exit 1 -} -Write-Host "✅ 已检测到小狼毫" - -$userKey = "HKCU:\Software\Rime\Weasel" -$rimeDir = (Get-ItemProperty -Path $userKey -Name RimeUserDir -ErrorAction SilentlyContinue).RimeUserDir - -if (-not $rimeDir -or -not (Test-Path $rimeDir)) { - Write-Host "❌ 未找到 Rime 用户目录,请在小狼毫配置工具中设置『用户目录』" - exit 1 -} - -Write-Host "✅ Rime 配置目录:$rimeDir" - -$configDir = Join-Path $rimeDir "rime-mate-config" -$exePath = Join-Path $configDir "$ToolName.exe" -$versionFile = Join-Path $configDir "version" - -$arch = switch ($env:PROCESSOR_ARCHITECTURE) { - "AMD64" { "amd64" } - "ARM64" { "arm64" } - default { throw "不支持的 Windows 架构: $env:PROCESSOR_ARCHITECTURE" } -} - -$fileName = "$ToolName-windows-$arch.exe" - -$needDownload = $true - -try { - $latest = (Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest").tag_name - if (Test-Path $versionFile) { - if ((Get-Content $versionFile) -eq $latest -and (Test-Path $exePath)) { - $needDownload = $false - } - } -} catch { - Write-Host "⚠️ 无法获取最新版本信息,将强制下载" -} - -if ($needDownload) { - Write-Host "⬇️ 正在下载 $fileName ..." - New-Item -ItemType Directory -Force -Path $configDir | Out-Null - - $url = "$BaseUrl/$fileName" - Invoke-WebRequest -Uri $url -OutFile $exePath - - if (-not (Test-Path $exePath)) { - Write-Host "❌ 下载失败" - exit 1 - } - - $latest | Out-File -Encoding ascii $versionFile -} - -$batPath = Join-Path $rimeDir "Rime配置助手.bat" -if (-not (Test-Path $batPath)) { -@" -@echo off -cd /d "%~dp0" -start rime-mate-config\$ToolName.exe -"@ | Out-File -Encoding ascii $batPath -} - -Write-Host "📂 正在打开 Rime 配置目录..." -explorer.exe $rimeDir From 24c42fcbe5d54a68fd514793a87b9c1b88044261 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:36:42 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=BA=E5=B8=A6DOM?= =?UTF-8?q?=E7=9A=84=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.ps1 | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 setup.ps1 diff --git a/setup.ps1 b/setup.ps1 new file mode 100644 index 0000000..39d5035 --- /dev/null +++ b/setup.ps1 @@ -0,0 +1,115 @@ +# ================= 配置区 ================= +$Repo = "hunter-ji/rime-mate" +$ToolName = "rime-mate" +$BaseUrl = "https://github.com/$Repo/releases/latest/download" +# ========================================= + +Write-Host "⏳ 正在准备环境..." + +# ---------- 小狼毫 ---------- +$uninstallKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Weasel" +if (-not (Test-Path $uninstallKey)) { + Write-Host "❌ 未检测到小狼毫(Weasel),请先安装后再运行本脚本" + exit 1 +} +Write-Host "✅ 已检测到小狼毫" + +# ---------- Rime 目录 ---------- +$userKey = "HKCU:\Software\Rime\Weasel" +$rimeDir = (Get-ItemProperty -Path $userKey -Name RimeUserDir -ErrorAction SilentlyContinue).RimeUserDir +if (-not $rimeDir -or -not (Test-Path $rimeDir)) { + Write-Host "❌ 未找到 Rime 用户目录" + exit 1 +} +Write-Host "✅ Rime 配置目录:$rimeDir" + +# ---------- 路径 ---------- +$configDir = Join-Path $rimeDir "rime-mate-config" +$exePath = Join-Path $configDir "$ToolName.exe" +$versionFile = Join-Path $configDir "version" + +# ---------- 架构 ---------- +$arch = switch ($env:PROCESSOR_ARCHITECTURE) { + "AMD64" { "amd64" } + "ARM64" { "arm64" } + default { Write-Host "❌ 不支持的架构"; exit 1 } +} + +# $fileName = "$ToolName-windows-$arch.exe" +$fileName = "$ToolName-linux-$arch" +$downloadUrl = "$BaseUrl/$fileName" + +# ---------- 版本检测 ---------- +Write-Host "🔍 正在检测最新版本..." + +$latestVersion = $null +$versionCheckOk = $false + +try { + $resp = Invoke-RestMethod ` + -Uri "https://api.github.com/repos/$Repo/releases/latest" ` + -Headers @{ "User-Agent" = "rime-mate-installer" } ` + -TimeoutSec 10 + + if ($resp.tag_name) { + $latestVersion = $resp.tag_name + $versionCheckOk = $true + Write-Host "✅ 最新版本:$latestVersion" + } +} catch {} + +if (-not $versionCheckOk) { + Write-Host "⚠️ 无法获取版本信息,将执行强制安装" +} + +# ---------- 是否需要安装 ---------- +$needInstall = $true + +if ($versionCheckOk -and (Test-Path $exePath) -and (Test-Path $versionFile)) { + $localVersion = Get-Content $versionFile + if ($localVersion -eq $latestVersion) { + Write-Host "✅ 已安装最新版本($localVersion),无需更新" + $needInstall = $false + } else { + Write-Host "⬆️ 已安装版本:$localVersion,将更新至 $latestVersion" + } +} + +if (-not $versionCheckOk) { + Write-Host "⬇️ 无法判断本地版本,执行强制安装" +} + +# ---------- 安装 / 更新 ---------- +if ($needInstall) { + Write-Host "⬇️ 正在下载:$fileName" + New-Item -ItemType Directory -Force -Path $configDir | Out-Null + + try { + Start-BitsTransfer ` + -Source $downloadUrl ` + -Destination $exePath ` + -ErrorAction Stop + } catch { + Write-Host "❌ 下载失败:当前网络无法访问 GitHub" + exit 1 + } + + if ($versionCheckOk) { + $latestVersion | Out-File -Encoding ascii $versionFile + } + + Write-Host "✅ 安装完成" +} + +# ---------- 启动脚本 ---------- +$batPath = Join-Path $rimeDir "Rime配置助手.bat" +if (-not (Test-Path $batPath)) { +@" +@echo off +cd /d "%~dp0" +start rime-mate-config\$ToolName.exe +"@ | Out-File -Encoding ascii $batPath +} + +Write-Host "📂 正在打开 Rime 配置目录..." +explorer.exe $rimeDir From 48bdc8ab5204e1db9376f9a4ec61cf1e67c2af7e Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:44:16 +0800 Subject: [PATCH 09/18] Update setup.sh Refactor system detection and improve output messages for Rime configuration directory checks. --- setup.sh | 138 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 45 deletions(-) diff --git a/setup.sh b/setup.sh index e1df38f..1dbaa21 100644 --- a/setup.sh +++ b/setup.sh @@ -5,23 +5,9 @@ REPO="hunter-ji/rime-mate" BASE_URL="https://github.com/$REPO/releases/latest/download" TOOL_NAME="rime-mate" -detect_system() { - case "$(uname -s)" in - Darwin) - echo "Darwin" - ;; - Linux) - echo "Linux" - ;; - *) - echo "UNKNOWN" - ;; - esac -} - detect_rime_dir() { home="$HOME" - system="$(detect_system)" + system="$(uname -s)" case "$system" in Darwin) @@ -29,7 +15,7 @@ detect_rime_dir() { ;; Linux) rime_dir="" - echo "🔍 正在检查 Linux 下的 Rime 配置路径:" + echo "🔍 正在检查Linux下的RIME配置路径:" if [ -d "$home/.config/ibus/rime" ]; then echo " - $home/.config/ibus/rime (存在? 是)" rime_dir="$home/.config/ibus/rime" @@ -45,41 +31,43 @@ detect_rime_dir() { fi fi if [ -z "$rime_dir" ]; then - echo "❌ Linux 下未找到 Rime 配置目录,请先安装 IBus-Rime/Fcitx5-Rime" + echo "❌ Linux 下未找到 RIME 配置目录,请先安装 IBus-RIME/Fcitx5-RIME" exit 1 fi ;; *) - echo "❌ 不支持的操作系统" + echo "❌ 不支持的操作系统: $(uname -s)" exit 1 ;; esac - echo "✅ 检测到 Rime 配置目录:$rime_dir" + if [ ! -d "$rime_dir" ]; then + echo "❌ 未检测到 Rime 配置目录: $rime_dir" + echo "请先安装对应系统的 Rime 输入法(macOS:鼠须管;Linux:IBus-RIME/Fcitx5-RIME)" + exit 1 + fi + echo "✅ 检测到 RIME 配置目录:$rime_dir" export RIME_DIR="$rime_dir" } echo "⏳ 正在准备环境..." detect_rime_dir -system="$(detect_system)" +# 所有文件都放在 Rime 配置目录下 +system="$(uname -s)" if [ "$system" = "Darwin" ]; then COMMAND_LINK="$RIME_DIR/Rime配置助手.command" -elif [ "$system" = "Linux" ]; then - COMMAND_LINK="$RIME_DIR/Rime配置助手.desktop" else - echo "❌ 不支持的操作系统" - exit 1 + COMMAND_LINK="$RIME_DIR/Rime配置助手.desktop" fi RIME_CONFIG_DIR="$RIME_DIR/rime-mate-config" BINARY_PATH="$RIME_CONFIG_DIR/$TOOL_NAME" - VERSION_FILE="$RIME_CONFIG_DIR/version" # ========================================= get_os_arch() { - system="$(detect_system)" + system="$(uname -s)" arch="$(uname -m)" case "$system" in @@ -98,20 +86,49 @@ get_os_arch() { } FILE_NAME="$(get_os_arch)" -# --- 步骤A: 版本检测 --- +# --- 步骤A: 环境检测与版本检查 --- MISSING_FILES=false -[ ! -f "$COMMAND_LINK" ] && MISSING_FILES=true -[ ! -f "$BINARY_PATH" ] && MISSING_FILES=true -[ ! -f "$VERSION_FILE" ] && MISSING_FILES=true +if [ ! -f "$COMMAND_LINK" ] || [ ! -f "$BINARY_PATH" ] || [ ! -f "$VERSION_FILE" ]; then + MISSING_FILES=true +fi + +if [ "$MISSING_FILES" = true ]; then + echo "✨ 检测到首次安装或文件缺失,正在获取版本信息..." +else + echo "🔍 环境完整,正在检查更新..." +fi LATEST_VERSION="$(curl -s "https://api.github.com/repos/$REPO/releases/latest" \ | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" +if [ -z "$LATEST_VERSION" ]; then + echo "⚠️ 版本信息获取失败,可能是网络或代理问题,将尝试不使用代理获取版本信息" + LATEST_VERSION="$(curl -s --noproxy "*" "https://api.github.com/repos/$REPO/releases/latest" \ + | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" +fi + NEED_DOWNLOAD=false -if [ "$MISSING_FILES" = true ]; then - NEED_DOWNLOAD=true -elif [ "$(cat "$VERSION_FILE")" != "$LATEST_VERSION" ]; then +VERSION_TO_WRITE="" + +if [ -z "$LATEST_VERSION" ]; then + echo "⚠️ 无法获取最新版本信息,将尝试强制安装..." NEED_DOWNLOAD=true + VERSION_TO_WRITE="unknown" +else + VERSION_TO_WRITE="$LATEST_VERSION" + if [ "$MISSING_FILES" = true ]; then + echo "⬇️ 准备下载版本: $LATEST_VERSION" + NEED_DOWNLOAD=true + else + LOCAL_VERSION="$(cat "$VERSION_FILE")" + if [ "$LOCAL_VERSION" = "$LATEST_VERSION" ]; then + echo "✅ 当前已是最新版本 ($LOCAL_VERSION)" + NEED_DOWNLOAD=false + else + echo "⬆️ 发现新版本 ($LOCAL_VERSION -> $LATEST_VERSION)" + NEED_DOWNLOAD=true + fi + fi fi if [ "$NEED_DOWNLOAD" = true ]; then @@ -119,40 +136,71 @@ if [ "$NEED_DOWNLOAD" = true ]; then mkdir -p "$RIME_CONFIG_DIR" curl -L "$BASE_URL/$FILE_NAME" -o "$BINARY_PATH" - [ ! -s "$BINARY_PATH" ] && echo "❌ 下载失败" && exit 1 + if [ ! -s "$BINARY_PATH" ]; then + echo "❌ 下载失败或文件为空,请检查网络连接或服务器状态。" + rm -f "$BINARY_PATH" + exit 1 + fi - echo "$LATEST_VERSION" > "$VERSION_FILE" + echo "$VERSION_TO_WRITE" > "$VERSION_FILE" chmod +x "$BINARY_PATH" - if [ "$system" = "Darwin" ]; then + if [ "$(uname -s)" = "Darwin" ]; then xattr -d com.apple.quarantine "$BINARY_PATH" 2>/dev/null fi fi -# --- 步骤B: 生成快捷方式 --- +# --- 步骤B: 在 Rime 配置目录生成“快捷方式” --- + if [ ! -f "$COMMAND_LINK" ]; then - if [ "$system" = "Darwin" ]; then + echo "🖥️ 正在 Rime 配置目录生成快捷方式..." + + if [ "$(uname -s)" = "Darwin" ]; then cat < "$COMMAND_LINK" #!/bin/bash -cd "$RIME_DIR" +TARGET_DIR="$RIME_DIR" +if [ "\$(pwd)" != "\$TARGET_DIR" ]; then + cd "\$TARGET_DIR" +fi ./rime-mate-config/$TOOL_NAME +echo "" EOF - elif [ "$system" = "Linux" ]; then + else cat < "$COMMAND_LINK" [Desktop Entry] Type=Application Name=Rime配置助手 -Exec=sh -c 'cd "$RIME_DIR" && ./rime-mate-config/$TOOL_NAME' +Exec=sh -c 'cd "$RIME_DIR" && ./rime-mate-config/$TOOL_NAME'; Terminal=true +Icon=utilities-terminal +Categories=Utility; EOF fi chmod +x "$COMMAND_LINK" + + if [ "$(uname -s)" = "Darwin" ]; then + xattr -d com.apple.quarantine "$COMMAND_LINK" 2>/dev/null + fi + + echo "✅ 快捷方式已创建:$COMMAND_LINK" + if [ "$(uname -s)" = "Darwin" ]; then + echo "🛠️ 打开 RIME 配置目录后,双击 'Rime配置助手.command' 即可启动配置助手。" + fi + if [ "$(uname -s)" = "Linux" ]; then + echo "🛠️ 打开 RIME 配置目录后,双击 'Rime配置助手.desktop' 即可启动配置助手。" + fi fi -# --- 步骤C: 打开配置目录 --- -echo "📂 正在打开 Rime 配置目录..." -case "$system" in +# --- 步骤C: 打开配置文件夹 --- +echo "📂 正在打开 RIME 配置目录..." +case "$(uname -s)" in Darwin) open "$RIME_DIR" ;; - Linux) command -v xdg-open >/dev/null && xdg-open "$RIME_DIR" ;; + Linux) + if command -v xdg-open >/dev/null 2>&1; then + xdg-open "$RIME_DIR" + else + echo "⚠️ 未找到 xdg-open,无法自动打开文件夹,手动路径:$RIME_DIR" + fi + ;; esac From f7215a35af120efd0123d9a17ec60406612dd9fb Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:45:23 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.ps1 b/setup.ps1 index 39d5035..c80201b 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -35,8 +35,7 @@ $arch = switch ($env:PROCESSOR_ARCHITECTURE) { default { Write-Host "❌ 不支持的架构"; exit 1 } } -# $fileName = "$ToolName-windows-$arch.exe" -$fileName = "$ToolName-linux-$arch" +$fileName = "$ToolName-windows-$arch.exe" $downloadUrl = "$BaseUrl/$fileName" # ---------- 版本检测 ---------- From 62e4670e5c38d46428adc594960979dfded779c5 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:56:00 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- setup.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.ps1 b/setup.ps1 index c80201b..de5faa2 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -55,7 +55,9 @@ try { $versionCheckOk = $true Write-Host "✅ 最新版本:$latestVersion" } -} catch {} +} catch { + Write-Warning "获取最新版本信息时出错:$($_.Exception.Message)" +} if (-not $versionCheckOk) { Write-Host "⚠️ 无法获取版本信息,将执行强制安装" From 6bf57a981d48f2536ad60d3f05f7c7e3c1ebe495 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:57:26 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E8=A1=A8=E8=BF=B0=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- module/ohMyRime/lang_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/ohMyRime/lang_model.go b/module/ohMyRime/lang_model.go index d11da0f..65b9e15 100644 --- a/module/ohMyRime/lang_model.go +++ b/module/ohMyRime/lang_model.go @@ -74,7 +74,7 @@ func getCrossPlatformRimeDir() (string, error) { return path, nil } - return "", fmt.Errorf("未找到 Windows 下的 Rime 配置目录") + return "", fmt.Errorf("未找到 Windows 下的小狼毫 (Weasel) Rime 配置目录") default: return "", fmt.Errorf("不支持的系统: %s", runtime.GOOS) } From 579fee016e92a31f2eee4f89ec7af21d123c9bf0 Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 21:59:44 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A9=BA=E7=99=BD?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- module/ohMyRime/lang_model.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/module/ohMyRime/lang_model.go b/module/ohMyRime/lang_model.go index 65b9e15..0e6ecc5 100644 --- a/module/ohMyRime/lang_model.go +++ b/module/ohMyRime/lang_model.go @@ -60,9 +60,27 @@ func getCrossPlatformRimeDir() (string, error) { ) output, err := cmd.Output() if err == nil { - fields := strings.Fields(string(output)) - if len(fields) > 0 { - regPath := fields[len(fields)-1] + lines := strings.Split(string(output), "\n") + for _, line := range lines { + line = strings.TrimSpace(line) + if line == "" || !strings.Contains(line, "RimeUserDir") { + continue + } + // Typical format: RimeUserDir REG_SZ C:\Path\To\Directory + parts := strings.Fields(line) + if len(parts) < 2 { + continue + } + valueType := parts[1] + typeIndex := strings.Index(line, valueType) + if typeIndex == -1 { + continue + } + valuePart := strings.TrimSpace(line[typeIndex+len(valueType):]) + if valuePart == "" { + continue + } + regPath := valuePart if _, err := os.Stat(regPath); err == nil { return regPath, nil } From 268c4337cea21c3aa3660840c1d76f49142d4a2a Mon Sep 17 00:00:00 2001 From: Gabriel Bao Date: Fri, 9 Jan 2026 22:00:57 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- setup.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.ps1 b/setup.ps1 index de5faa2..70168e7 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -16,7 +16,13 @@ Write-Host "✅ 已检测到小狼毫" # ---------- Rime 目录 ---------- $userKey = "HKCU:\Software\Rime\Weasel" -$rimeDir = (Get-ItemProperty -Path $userKey -Name RimeUserDir -ErrorAction SilentlyContinue).RimeUserDir +try { + $rimeProps = Get-ItemProperty -Path $userKey -Name RimeUserDir -ErrorAction Stop +} catch { + Write-Host "❌ 读取注册表中的 Rime 用户目录失败:$($_.Exception.Message)" + exit 1 +} +$rimeDir = $rimeProps.RimeUserDir if (-not $rimeDir -or -not (Test-Path $rimeDir)) { Write-Host "❌ 未找到 Rime 用户目录" exit 1 From 7a9442458b81ee35d801cd474d71238681f33a1c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 08:32:11 +0000 Subject: [PATCH 15/18] Initial plan From fdaebce1ff36b1db66d805503d5c3091f39727d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 08:36:02 +0000 Subject: [PATCH 16/18] feat: add comprehensive Copilot instructions for repository Co-authored-by: hunter-ji <25321169+hunter-ji@users.noreply.github.com> --- .github/copilot-instructions.md | 223 ++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..afe7169 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,223 @@ +# Copilot Instructions for Rime Mate + +## Project Overview + +Rime Mate (Rime 配置助手) is a visual configuration assistant for the Rime input method on macOS, Linux, and Windows. It simplifies complex Rime configuration files through an intuitive terminal-based UI, making it accessible for non-programmer users. + +**Key Features:** +- Visual configuration interface using Bubble Tea TUI framework +- One-click installation of dictionaries and language models +- Cross-platform support (macOS, Linux, Windows) +- Automatic handling of configuration paths and dependencies + +## Project Structure + +``` +. +├── .github/ +│ └── workflows/ # GitHub Actions CI/CD workflows +├── module/ # Core functionality modules +│ ├── config.go # Configuration management +│ ├── ohMyRime/ # Oh-my-rime integration (mint input method) +│ │ ├── lang_model.go # Language model installation/removal +│ │ ├── module.go # Module configuration +│ │ └── resources.go # Resource URLs and constants +│ └── rimeIce/ # Rime Ice integration (coming soon) +├── util/ # Utility functions +│ ├── download.go # File download with fallback URLs +│ ├── log.go # Logging utilities +│ ├── transform_path.go # Cross-platform path handling +│ └── yaml_reader.go # YAML configuration parsing +├── main.go # Application entry point +├── build_cli.go # TUI implementation with Bubble Tea +├── build.sh # Cross-platform build script +├── setup.sh # Unix installation script +└── setup.ps1 # Windows installation script +``` + +## Build and Development Commands + +### Building the Project + +```bash +# Vendor dependencies first +go mod vendor + +# Build for all platforms +./build.sh + +# Or build manually for specific platform +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -mod=vendor -o output/rime-mate-linux-amd64 . +``` + +### Running the Application + +```bash +# Run directly +go run . + +# Or build and run +go build -o rime-mate . && ./rime-mate +``` + +### Testing + +```bash +# Run tests (if available) +go test ./... + +# Run tests with coverage +go test -cover ./... +``` + +### Code Quality + +```bash +# Format code +go fmt ./... + +# Lint code (if golangci-lint is installed) +golangci-lint run +``` + +## Coding Standards and Conventions + +### General Guidelines + +1. **Language**: Go 1.25.5 +2. **Chinese Comments**: Use Chinese comments for user-facing functionality and UI strings +3. **English Comments**: Use English for technical implementation details and code documentation +4. **Error Handling**: Always handle errors explicitly; never ignore them + +### Code Style + +- Follow standard Go conventions (use `gofmt`) +- Use descriptive variable names in English +- Keep functions focused and single-purpose +- Prefer explicit error handling over panic + +### UI/UX Conventions + +- Use emoji icons for visual feedback (✅ ✗ 🚀 ❌) +- All user-facing text should be in Chinese +- Menu navigation: `↑`/`↓` or `j`/`k` for selection, `Enter` to confirm, `q` to quit +- Use Lipgloss styles consistently: + - `titleStyle`: Green (#04B575), bold, for titles + - `selectedStyle`: Pink (#FF7AB2), bold, for selected items + - `disabledStyle`: Gray (#626262) for disabled items + - `helpStyle`: Gray (#626262) for help text + +### Module Organization + +- Each input method (mint, rime-ice) should have its own module package +- Each module should implement standard interfaces from `module/config.go` +- Utilities should be in the `util/` package and be reusable + +### Cross-Platform Considerations + +- Always use cross-platform path handling via `util.TransformPath()` +- Detect OS using `runtime.GOOS` +- Test builds for all supported platforms: darwin/amd64, darwin/arm64, linux/amd64, linux/arm64, windows/amd64, windows/arm64 +- Use appropriate file extensions (.command for macOS, .desktop for Linux, .bat for Windows) + +### Download and Resource Management + +- Always provide fallback URLs (GitHub + CNB mirror) for downloads +- Use `util.DownloadResource()` for all downloads +- Display progress feedback to users +- Handle network errors gracefully with user-friendly messages + +## Git and Release Workflow + +### Branch Naming + +- Feature branches: `feature/description` +- Bug fixes: `fix/description` +- Copilot branches: `copilot/description` + +### Commit Messages + +- Use English for commit messages +- Format: `: ` +- Types: `feat`, `fix`, `docs`, `refactor`, `test`, `chore` +- Example: `feat: add language model installation for mint input` + +### Release Process + +1. Tag with version (e.g., `v1.0.0`) +2. GitHub Actions automatically builds for all platforms +3. Creates a draft release with binaries and setup scripts +4. Review and publish the release manually + +## Important Boundaries + +### DO NOT + +- **Never commit secrets or API keys** into the repository +- **Never modify or delete vendor files** - use `go mod vendor` to regenerate +- **Never edit `.git/` directory or git configuration** +- **Never remove working code** unless fixing a bug or security vulnerability +- **Never add unnecessary dependencies** - prefer standard library when possible +- **Never break cross-platform compatibility** - test on all platforms +- **Never modify setup scripts** without testing on target platforms + +### DO + +- **Always test builds** using `./build.sh` before committing +- **Always handle errors** with user-friendly Chinese messages +- **Always use CGO_ENABLED=0** for cross-platform compatibility +- **Always vendor dependencies** before building releases +- **Always preserve existing functionality** when adding features +- **Always use semantic versioning** for releases + +## Dependencies + +- **Bubble Tea** (github.com/charmbracelet/bubbletea): Terminal UI framework +- **Lipgloss** (github.com/charmbracelet/lipgloss): Style definitions for TUI +- **go-yaml** (github.com/goccy/go-yaml): YAML parsing for Rime configs + +## Testing Strategy + +- Test builds on all supported platforms before releases +- Manual testing of TUI navigation and functionality +- Verify download functionality with both primary and fallback URLs +- Test path handling on different operating systems + +## Common Tasks + +### Adding a New Input Method Module + +1. Create new package under `module/` +2. Implement required interfaces from `module/config.go` +3. Add menu entry in `build_cli.go` +4. Implement installation/removal functions +5. Add resource URLs in module's `resources.go` +6. Test on all platforms + +### Adding a New Feature to Existing Module + +1. Implement functionality in appropriate module file +2. Add menu option in `build_cli.go` if needed +3. Add error handling with Chinese user messages +4. Update README.md if user-facing +5. Test the feature manually + +### Updating Dependencies + +```bash +# Update specific dependency +go get -u github.com/charmbracelet/bubbletea@latest + +# Update go.mod +go mod tidy + +# Vendor dependencies +go mod vendor +``` + +## Additional Notes + +- The application is designed for users who are not familiar with programming +- All error messages and UI text should be clear and in Chinese +- Prioritize user experience and simplicity over advanced features +- The setup scripts handle automatic updates by re-running the installation command From a46b44bb1820b9ae558252a7b05635d4a06326b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 08:37:24 +0000 Subject: [PATCH 17/18] docs: add build verification step to dependency update process Co-authored-by: hunter-ji <25321169+hunter-ji@users.noreply.github.com> --- .github/copilot-instructions.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index afe7169..eaa8a5a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -213,6 +213,12 @@ go mod tidy # Vendor dependencies go mod vendor + +# Test build to verify compatibility +go build -o /tmp/rime-mate-test . + +# If build succeeds, run the application to verify it works +/tmp/rime-mate-test ``` ## Additional Notes From 92a7647a00e788d88c8d3794842b361a657692b3 Mon Sep 17 00:00:00 2001 From: Hunter Date: Thu, 15 Jan 2026 21:30:56 +0800 Subject: [PATCH 18/18] =?UTF-8?q?feat:=20=20=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?setup=E9=80=82=E9=85=8D=E6=B5=8B=E8=AF=95=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 83 ++++++++++++++++++++++++++++++++++++++++ setup.sh | 80 +++++++++++++++++++++++++++----------- 2 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4102d55 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,83 @@ +name: ci + +on: + push: + branches: [ "main", "master" ] + pull_request: + workflow_dispatch: + + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest ] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.25.5' + + - name: Go test + run: go test ./... + + - name: Build binary for current platform + shell: bash + run: | + set -e + GOOS=$(go env GOOS) + GOARCH=$(go env GOARCH) + OUT="rime-mate-${GOOS}-${GOARCH}" + BUILD_DIR="${RUNNER_TEMP}/rime-mate-build" + mkdir -p "$BUILD_DIR" + CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" go build -o "$BUILD_DIR/$OUT" . + echo "OUT_FILE=$BUILD_DIR/$OUT" >> "$GITHUB_ENV" + echo "BUILD_DIR=$BUILD_DIR" >> "$GITHUB_ENV" + + - name: Start local file server + shell: bash + run: | + set -e + cd "$BUILD_DIR" + python3 -m http.server 8000 >/tmp/rime-http.log 2>&1 & + echo $! > /tmp/rime-http.pid + + - name: Run setup.sh against local server + shell: bash + run: | + set -e + mkdir -p "$RUNNER_TEMP/rime-test" + TEST_BASE_URL="http://127.0.0.1:8000" \ + TEST_RIME_DIR="$RUNNER_TEMP/rime-test" \ + VERSION_OVERRIDE="dev-ci" \ + CI_MODE=1 \ + bash setup.sh + + - name: Validate install artifacts + shell: bash + run: | + set -e + ls -l "$RUNNER_TEMP/rime-test/rime-mate-config" + test -f "$RUNNER_TEMP/rime-test/rime-mate-config/version" + test -x "$RUNNER_TEMP/rime-test/rime-mate-config/rime-mate" + + # 检查是否存在匹配 Rime配置助手.* 的文件 + shopt -s nullglob + files=("$RUNNER_TEMP/rime-test"/Rime配置助手.*) + if [ ${#files[@]} -eq 0 ]; then + echo "未找到 Rime配置助手 文件" >&2 + exit 1 + fi + + - name: Stop local file server + if: always() + shell: bash + run: | + if [ -f /tmp/rime-http.pid ]; then + kill "$(cat /tmp/rime-http.pid)" || true + fi diff --git a/setup.sh b/setup.sh index 1dbaa21..f4df076 100644 --- a/setup.sh +++ b/setup.sh @@ -5,7 +5,21 @@ REPO="hunter-ji/rime-mate" BASE_URL="https://github.com/$REPO/releases/latest/download" TOOL_NAME="rime-mate" +# 以下变量仅用于 CI/本地自测 +TEST_BASE_URL="${TEST_BASE_URL:-}" # 覆盖下载源,指向本地 HTTP 服务器 +TEST_RIME_DIR="${TEST_RIME_DIR:-}" # 覆盖 RIME 目录,避免写入真实目录 +CI_MODE="${CI_MODE:-0}" # CI 模式下跳过交互(open/xattr 等) +VERSION_OVERRIDE="${VERSION_OVERRIDE:-}" # 指定版本号,跳过 GitHub API 请求 + detect_rime_dir() { + if [ -n "$TEST_RIME_DIR" ]; then + # CI/测试模式:使用临时目录代替真实 RIME 路径 + mkdir -p "$TEST_RIME_DIR" + echo "🔧 使用测试 RIME 目录:$TEST_RIME_DIR" + export RIME_DIR="$TEST_RIME_DIR" + return + fi + home="$HOME" system="$(uname -s)" @@ -84,7 +98,13 @@ get_os_arch() { echo "${TOOL_NAME}-${os}-${arch}" } + FILE_NAME="$(get_os_arch)" +# 仅当设置了测试源时才覆盖下载地址,默认保持生产 URL +EFFECTIVE_BASE_URL="$BASE_URL" +if [ -n "$TEST_BASE_URL" ]; then + EFFECTIVE_BASE_URL="$TEST_BASE_URL" +fi # --- 步骤A: 环境检测与版本检查 --- MISSING_FILES=false @@ -98,22 +118,32 @@ else echo "🔍 环境完整,正在检查更新..." fi -LATEST_VERSION="$(curl -s "https://api.github.com/repos/$REPO/releases/latest" \ - | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" - -if [ -z "$LATEST_VERSION" ]; then - echo "⚠️ 版本信息获取失败,可能是网络或代理问题,将尝试不使用代理获取版本信息" - LATEST_VERSION="$(curl -s --noproxy "*" "https://api.github.com/repos/$REPO/releases/latest" \ +# 如指定 VERSION_OVERRIDE,则直接使用指定版本;否则向 GitHub 查询最新版本 +if [ -n "$VERSION_OVERRIDE" ]; then + LATEST_VERSION="$VERSION_OVERRIDE" +else + LATEST_VERSION="$(curl -s --max-time 15 "https://api.github.com/repos/$REPO/releases/latest" \ | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" + + if [ -z "$LATEST_VERSION" ]; then + echo "⚠️ 版本信息获取失败,可能是网络或代理问题,将尝试不使用代理获取版本信息" + LATEST_VERSION="$(curl -s --noproxy "*" --max-time 10 "https://api.github.com/repos/$REPO/releases/latest" \ + | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')" + fi fi NEED_DOWNLOAD=false VERSION_TO_WRITE="" if [ -z "$LATEST_VERSION" ]; then - echo "⚠️ 无法获取最新版本信息,将尝试强制安装..." - NEED_DOWNLOAD=true - VERSION_TO_WRITE="unknown" + if [ "$MISSING_FILES" = true ]; then + echo "⚠️ 无法获取最新版本信息,且本地文件缺失,将尝试强制安装..." + NEED_DOWNLOAD=true + VERSION_TO_WRITE="unknown" + else + echo "⚠️ 无法获取最新版本信息,但检测到本地已安装。跳过更新,使用当前版本。" + NEED_DOWNLOAD=false + fi else VERSION_TO_WRITE="$LATEST_VERSION" if [ "$MISSING_FILES" = true ]; then @@ -134,7 +164,7 @@ fi if [ "$NEED_DOWNLOAD" = true ]; then echo "⬇️ 正在下载 $FILE_NAME ..." mkdir -p "$RIME_CONFIG_DIR" - curl -L "$BASE_URL/$FILE_NAME" -o "$BINARY_PATH" + curl -L "$EFFECTIVE_BASE_URL/$FILE_NAME" -o "$BINARY_PATH" if [ ! -s "$BINARY_PATH" ]; then echo "❌ 下载失败或文件为空,请检查网络连接或服务器状态。" @@ -145,7 +175,7 @@ if [ "$NEED_DOWNLOAD" = true ]; then echo "$VERSION_TO_WRITE" > "$VERSION_FILE" chmod +x "$BINARY_PATH" - if [ "$(uname -s)" = "Darwin" ]; then + if [ "$CI_MODE" != "1" ] && [ "$(uname -s)" = "Darwin" ]; then xattr -d com.apple.quarantine "$BINARY_PATH" 2>/dev/null fi fi @@ -179,7 +209,7 @@ EOF chmod +x "$COMMAND_LINK" - if [ "$(uname -s)" = "Darwin" ]; then + if [ "$CI_MODE" != "1" ] && [ "$(uname -s)" = "Darwin" ]; then xattr -d com.apple.quarantine "$COMMAND_LINK" 2>/dev/null fi @@ -193,14 +223,18 @@ EOF fi # --- 步骤C: 打开配置文件夹 --- -echo "📂 正在打开 RIME 配置目录..." -case "$(uname -s)" in - Darwin) open "$RIME_DIR" ;; - Linux) - if command -v xdg-open >/dev/null 2>&1; then - xdg-open "$RIME_DIR" - else - echo "⚠️ 未找到 xdg-open,无法自动打开文件夹,手动路径:$RIME_DIR" - fi - ;; -esac +if [ "$CI_MODE" = "1" ]; then + echo "ℹ️ CI 模式已跳过自动打开 RIME 配置目录" +else + echo "📂 正在打开 RIME 配置目录..." + case "$(uname -s)" in + Darwin) open "$RIME_DIR" ;; + Linux) + if command -v xdg-open >/dev/null 2>&1; then + xdg-open "$RIME_DIR" + else + echo "⚠️ 未找到 xdg-open,无法自动打开文件夹,手动路径:$RIME_DIR" + fi + ;; + esac +fi