Skip to content

Commit 723e2f4

Browse files
authored
Merge pull request #7 from bao-cn/main
Windows 平台支持
2 parents d1fbfbb + 268c433 commit 723e2f4

6 files changed

Lines changed: 252 additions & 61 deletions

File tree

.github/workflows/build.yml

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,52 @@ name: Build and Release
33
on:
44
push:
55
tags:
6-
- "v*"
6+
- "v*"
77
workflow_dispatch:
8+
89
permissions:
910
contents: write
1011

1112
jobs:
1213
build-and-release:
1314
runs-on: ubuntu-latest
15+
1416
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v4
17-
18-
- name: Set up Go
19-
uses: actions/setup-go@v5
20-
with:
21-
go-version-file: 'go.mod'
22-
cache: true
23-
24-
- name: Vendor dependencies
25-
run: go mod vendor
26-
27-
- name: Cross compile
28-
run: |
29-
mkdir -p output
30-
declare -a targets=(
31-
"linux amd64"
32-
"linux arm64"
33-
"darwin amd64"
34-
"darwin arm64"
35-
)
36-
for target in "${targets[@]}"; do
37-
GOOS=$(echo $target | cut -d' ' -f1)
38-
GOARCH=$(echo $target | cut -d' ' -f2)
39-
BIN_NAME="rime-mate-${GOOS}-${GOARCH}"
40-
echo "🔨 Compiling ${BIN_NAME} (GOOS=${GOOS}, GOARCH=${GOARCH})"
41-
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o output/${BIN_NAME} .
42-
if [ ! -f "output/${BIN_NAME}" ]; then
43-
echo "❌ Compilation of ${BIN_NAME} failed"
44-
exit 1
45-
fi
46-
chmod +x output/${BIN_NAME}
47-
done
48-
49-
- name: Copy setup.sh to output
50-
run: cp setup.sh output/
51-
52-
- name: Create Draft Release
53-
uses: softprops/action-gh-release@v1
54-
with:
55-
draft: true
56-
files: |
57-
output/rime-mate-linux-amd64
58-
output/rime-mate-linux-arm64
59-
output/rime-mate-darwin-amd64
60-
output/rime-mate-darwin-arm64
61-
output/setup.sh
62-
env:
63-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: go.mod
24+
cache: true
25+
26+
- name: Vendor dependencies
27+
run: go mod vendor
28+
29+
- name: Make build.sh executable
30+
run: chmod +x build.sh
31+
32+
- name: Run build script
33+
run: ./build.sh
34+
35+
- name: Copy setup script to output
36+
run: |
37+
cp setup.sh output/
38+
cp setup.ps1 output/
39+
40+
- name: Create Draft Release
41+
uses: softprops/action-gh-release@v1
42+
with:
43+
draft: true
44+
files: |
45+
output/rime-mate-darwin-amd64
46+
output/rime-mate-darwin-arm64
47+
output/rime-mate-linux-amd64
48+
output/rime-mate-linux-arm64
49+
output/rime-mate-windows-amd64.exe
50+
output/rime-mate-windows-arm64.exe
51+
output/setup.sh
52+
output/setup.ps1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Rime Mate (Rime 配置助手)
22

3-
**让 macOS/Linux 上的 Rime (鼠须管/中州韻) 输入法配置变得简单、直观、可视化。**
3+
**让 macOS/Linux/Windows 上的 Rime (中州韻) 输入法配置变得简单、直观、可视化。**
44

55
![Rime Mate 截图](./rime-mate.jpg)
66

@@ -17,11 +17,21 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了
1717

1818
### 1. 安装
1919

20-
打开你的“终端”应用 (Terminal),复制并运行以下命令:
20+
- **macOS/Linux用户:**
2121

22-
```bash
23-
/bin/bash -c "$(curl -fsSL https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.sh)"
24-
```
22+
打开你的“终端”应用 (Terminal),复制并运行以下命令:
23+
24+
```bash
25+
/bin/bash -c "$(curl -fsSL https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.sh)"
26+
```
27+
28+
- **Windows用户:**
29+
30+
`Win + R` 打开运行对话框,输入 `powershell` 并按 `Enter` 打开,复制并运行以下命令:
31+
```shell
32+
powershell -NoProfile -ExecutionPolicy Bypass -Command `
33+
"irm https://github.com/hunter-ji/rime-mate/releases/latest/download/setup.ps1 | iex"
34+
```
2535

2636
脚本会自动下载最新版本,并在你的 Rime 配置目录中创建一个快捷方式。
2737

@@ -37,6 +47,10 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了
3747
1. 打开 Rime 配置文件夹(iBus: `~/.config/ibus/rime`, Fcitx5: `~/.local/share/fcitx5/rime`)。
3848
2. 你会看到一个名为 **`Rime配置助手.desktop`** 的文件,**双击运行**它。
3949
3. 在弹出的窗口中,使用键盘 `` `` 选择功能,按 `Enter` 确认即可。
50+
- Windows:
51+
1. 打开 Rime 配置文件夹(`%APPDATA%\Rime`或小狼毫配置工具自定义目录)。
52+
2. 你会看到一个名为 **`Rime配置助手.bat`** 的文件,**双击运行**它。
53+
3. 在弹出的窗口中,使用键盘 `` `` 选择功能,按 `Enter` 确认即可。
4054

4155
### 3. 更新
4256

@@ -47,6 +61,7 @@ Rime 是一款极具可玩性的输入法,但其复杂的配置文件劝退了
4761
在 Rime 的配置文件夹中:
4862
- macOS:删除`Rime配置助手.command`文件和`rime-mate-config`文件夹。
4963
- Linux:删除`Rime配置助手.desktop`文件和`rime-mate-config`文件夹。
64+
- Windows:删除`Rime配置助手.bat`文件和`rime-mate-config`文件夹。
5065

5166
## ❓ 常见问题
5267

build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
export CGO_ENABLED=0
4+
35
# Build script - Compile for macOS executable + Linux executable
46
echo "Building rime-mate..."
57

@@ -29,6 +31,15 @@ GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/
2931
echo "Building for Linux ARM64 (aarch64)..."
3032
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-linux-arm64" .
3133

34+
# Build for Windows executable
35+
# GOOS=windows GOARCH=amd64 - for x86_64 Windows
36+
# GOOS=windows GOARCH=arm64 - for ARM64 Windows (arm64)
37+
38+
echo "Building for Windows x86_64..."
39+
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-windows-amd64.exe" .
40+
41+
echo "Building for Windows ARM64 (arm64)..."
42+
GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -mod=vendor -o "${OUTPUTPATH}/${OUTPUT}-windows-arm64.exe" .
3243

3344

3445
if [ $? -eq 0 ]; then
@@ -38,6 +49,8 @@ if [ $? -eq 0 ]; then
3849
echo " ./output/${OUTPUT}-darwin-arm64"
3950
echo " ./output/${OUTPUT}-linux-amd64"
4051
echo " ./output/${OUTPUT}-linux-arm64"
52+
echo " ./output/${OUTPUT}-windows-amd64.exe"
53+
echo " ./output/${OUTPUT}-windows-arm64.exe"
4154
else
4255
echo "✗ Build failed"
4356
exit 1

module/ohMyRime/lang_model.go

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ package ohMyRime
22

33
import (
44
"fmt"
5-
"github.com/goccy/go-yaml"
65
"os"
6+
"os/exec"
77
"path/filepath"
88
"rime-mate/util"
99
"runtime"
1010
"slices"
11+
"strings"
12+
13+
"github.com/goccy/go-yaml"
1114
)
1215

1316
func loadResourceURLs() (string, string) {
1417
rimeDir, err := getCrossPlatformRimeDir()
1518
if err != nil {
16-
util.Error("获取RIME配置目录失败: " + err.Error())
17-
rimeDir = util.TransformPath("~/Library/Rime/")
19+
util.Error("获取 Rime 配置目录失败: " + err.Error())
20+
os.Exit(1)
1821
}
1922

2023
langModelPath := filepath.Join(rimeDir, "wanxiang-lts-zh-hans.gram")
@@ -31,7 +34,11 @@ func getCrossPlatformRimeDir() (string, error) {
3134

3235
switch runtime.GOOS {
3336
case "darwin":
34-
return filepath.Join(home, "Library/Rime"), nil
37+
path := filepath.Join(home, "Library/Rime")
38+
if _, err := os.Stat(path); err == nil {
39+
return path, nil
40+
}
41+
return "", fmt.Errorf("未找到 macOS 下的 Rime 配置目录")
3542
case "linux":
3643
paths := []string{
3744
filepath.Join(home, ".config/ibus/rime"),
@@ -42,7 +49,50 @@ func getCrossPlatformRimeDir() (string, error) {
4249
return p, nil
4350
}
4451
}
45-
return "", fmt.Errorf("未找到Linux下的RIME配置目录,请检查是否安装IBus-RIME/Fcitx5-RIME")
52+
return "", fmt.Errorf("未找到 Linux 下的 Rime 配置目录,请检查是否安装 iBus-Rime/Fcitx5-Rime")
53+
case "windows":
54+
cmd := exec.Command(
55+
"reg",
56+
"query",
57+
`HKCU\Software\Rime\Weasel`,
58+
"/v",
59+
"RimeUserDir",
60+
)
61+
output, err := cmd.Output()
62+
if err == nil {
63+
lines := strings.Split(string(output), "\n")
64+
for _, line := range lines {
65+
line = strings.TrimSpace(line)
66+
if line == "" || !strings.Contains(line, "RimeUserDir") {
67+
continue
68+
}
69+
// Typical format: RimeUserDir REG_SZ C:\Path\To\Directory
70+
parts := strings.Fields(line)
71+
if len(parts) < 2 {
72+
continue
73+
}
74+
valueType := parts[1]
75+
typeIndex := strings.Index(line, valueType)
76+
if typeIndex == -1 {
77+
continue
78+
}
79+
valuePart := strings.TrimSpace(line[typeIndex+len(valueType):])
80+
if valuePart == "" {
81+
continue
82+
}
83+
regPath := valuePart
84+
if _, err := os.Stat(regPath); err == nil {
85+
return regPath, nil
86+
}
87+
}
88+
}
89+
90+
path := filepath.Join(home, "AppData", "Roaming", "Rime")
91+
if _, err := os.Stat(path); err == nil {
92+
return path, nil
93+
}
94+
95+
return "", fmt.Errorf("未找到 Windows 下的小狼毫 (Weasel) Rime 配置目录")
4696
default:
4797
return "", fmt.Errorf("不支持的系统: %s", runtime.GOOS)
4898
}

0 commit comments

Comments
 (0)