feat(platform): 三端支持 —— Windows / Linux 已出包,macOS 走 Actions

老板要求:开发 macOS 和 Linux 版。

一、代码跨平台化(原来只能编 Windows)
  · Cargo.toml:clipboard-win / windows-sys 挪到 [target.'cfg(windows)'.dependencies];
    非 Windows 加 arboard(macOS 走 NSPasteboard,Linux 走 X11/Wayland)
  · main.rs:
      - windows_subsystem 属性加目标平台判断(mac/Linux 没这个概念)
      - 剪贴板三个命令按平台分文件级实现
      - 「复制文件本身」在 mac/Linux 退化为复制路径文本(这两个平台剪贴板没有
        通用的文件格式,要写 NSPasteboard / GTK 私有 target,代价不值)
      - reveal_in_explorer:explorer / open -R / xdg-open
      - open_external:explorer / open / xdg-open
  · 修了重构时误删的 message_box 命令(构建时才暴露,已核对 19 个命令齐全)

二、打包配置
  · tauri icon 生成三端图标集(.ico / .icns / 多尺寸 png)
  · bundle.targets = "all":win→nsis,mac→app+dmg,linux→deb+rpm+appimage
  · macOS minimumSystemVersion 10.15;linux.deb 依赖声明

三、发布链路升级成多平台
  · publish.py 重写:自动扫描 target 下**存在的**产物,按平台归位,
    清单**合并**写入(在 Windows 发版不会冲掉 mac 的条目)
  · 官网页新增 macOS / Linux 下载卡,按 latest.json 里有没有该平台决定显隐,
    避免指向不存在的文件

四、实测(Linux 版)
  · 本机装 webkit2gtk-4.1 等依赖后原生构建成功
  · deb 2.79MB、AppImage 103.62MB(AppImage 自带 webkit 运行时所以大)
  · 已发布:latest.json 现在有 windows-x86_64 + linux-x86_64 两个平台
  · 官网 Linux 卡已显示,macOS 卡等有产物再自动出现

五、macOS
  · .github/workflows/build.yml:macos-latest(arm64 + intel)/ ubuntu / windows 矩阵出包
  · 需要仓库 Secrets 配升级签名私钥(和可选的苹果开发者证书)
This commit is contained in:
Jidekin committed 2026-11-20 11:28:32 +08:00
1 parent 580e875be5
commit 08f42cf1ce
61 files changed
+618 -94

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
name: build
# 三端出包:
# Windows → .exe(NSIS 安装包)
# macOS → .dmg(Intel + Apple Silicon 各一份)
# Linux → .deb / .AppImage
#
# Linux 版和 Windows 版本机就能交叉/原生编译,macOS 必须有苹果的编译链,
# 所以这里统一交给 GitHub Actions(macos-latest 就是真机 macOS)。
on:
workflow_dispatch:
push:
tags:
- 'v*'
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: macos-latest
target: aarch64-apple-darwin
label: macOS (Apple Silicon)
- platform: macos-latest
target: x86_64-apple-darwin
label: macOS (Intel)
- platform: ubuntu-22.04
target: ''
label: Linux
- platform: windows-latest
target: ''
label: Windows
name: ${{ matrix.label }}
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: 安装 Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
- name: 缓存 cargo
uses: swatinem/rust-cache@v2
with:
workspaces: src-tauri
- name: 安装 Linux 系统依赖
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev \
librsvg2-dev libxdo-dev patchelf
- name: 安装前端依赖
run: npm install
- name: 构建并上传产物
uses: tauri-apps/tauri-action@v0
env:
# 升级签名:把私钥内容存到仓库 Secret(TAURI_SIGNING_PRIVATE_KEY)
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
# macOS 代码签名(没有苹果开发者证书时留空,产物未签名,用户需右键「打开」)
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
with:
args: ${{ matrix.target != '' && format('--target {0}', matrix.target) || '' }}
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: xiaoyin-markdown-${{ matrix.platform }}${{ matrix.target != '' && format('-{0}', matrix.target) || '' }}
path: |
src-tauri/target/**/release/bundle/**/*.exe
src-tauri/target/**/release/bundle/**/*.msi
src-tauri/target/**/release/bundle/**/*.dmg
src-tauri/target/**/release/bundle/**/*.deb
src-tauri/target/**/release/bundle/**/*.AppImage
src-tauri/target/**/release/bundle/**/*.tar.gz
src-tauri/target/**/release/bundle/**/*.sig
if-no-files-found: warn
+56
View File
@@ -147,6 +147,62 @@ npx electron-packager . XiaoyinMarkdown --platform=win32 --arch=x64 --out=dist ^
打包完成后把 `dist\XiaoyinMarkdown-win32-x64` 整个目录拷到 `%USERPROFILE%\Apps\XiaoyinMarkdown` 覆盖即可(exe 依赖同目录的 dll,不能只拷 exe)。 打包完成后把 `dist\XiaoyinMarkdown-win32-x64` 整个目录拷到 `%USERPROFILE%\Apps\XiaoyinMarkdown` 覆盖即可(exe 依赖同目录的 dll,不能只拷 exe)。
## 三端支持(Windows / macOS / Linux)
| 平台 | 产物 | 状态 |
| --- | --- | --- |
| Windows 10/11 x64 | `xymd_<版本>.exe`(NSIS 安装包)| ✅ 已发布 |
| Linux x86_64 | `xymd_<版本>_amd64.AppImage` / `.deb` | ✅ 已发布 |
| macOS 11+ | `xymd_<版本>_aarch64.dmg` / `_x64.dmg` | ⏳ 需在 macOS 上构建(见下)|
### 平台差异
| 能力 | Windows | macOS | Linux |
| --- | --- | --- | --- |
| 「复制文件本身」到剪贴板 | ✅ Win32 CF_HDROP | ⚠️ 退化为复制路径文本 | ⚠️ 退化为复制路径文本 |
| 在文件管理器中显示 | 资源管理器并选中 | `open -R` | `xdg-open` 打开所在目录 |
| 打开外部链接 | `explorer` | `open` | `xdg-open` |
| 文本剪贴板 | `clipboard-win` | `arboard` | `arboard` |
| 在线升级 | ✅ | ✅(需签名)| ✅(仅 AppImage 形态)|
macOS / Linux 的剪贴板没有跨平台的「文件」格式(要写 NSPasteboard / GTK 私有 target),
所以这两个平台上「复制文件」会退化成把**路径文本**放进剪贴板。
### 本机构建(Linux / Windows 交叉)
```bash
# Linux 原生(需要 webkit2gtk-4.1 等系统库)
sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev libxdo-dev
npx tauri build --bundles deb,appimage
# Windows(在 Linux 上交叉编译)
npx tauri build --target x86_64-pc-windows-gnu --bundles nsis
```
### macOS
macOS 的包**必须**在 macOS 上构建(需要 Xcode 的命令行工具链,Linux 无法交叉编译):
仓库里的 `.github/workflows/build.yml` 会同时在 `macos-latest`(Apple Silicon + Intel)、
`ubuntu-22.04`、`windows-latest` 三个 runner 上出包,产物在 Actions 的 Artifacts 里。
需要在仓库 Secrets 里配:
- `TAURI_SIGNING_PRIVATE_KEY` / `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` —— 升级签名私钥
- `APPLE_CERTIFICATE` / `APPLE_CERTIFICATE_PASSWORD` / `APPLE_SIGNING_IDENTITY` —— 苹果开发者证书(可选)
- `APPLE_ID` / `APPLE_PASSWORD` / `APPLE_TEAM_ID` —— 公证用(可选)
没有苹果开发者证书时产物是**未签名**的,用户首次打开需要「右键 → 打开」,
或在终端执行 `xattr -dr com.apple.quarantine /Applications/XiaoyinMarkdown.app`。
### 发布
```bash
python3 tools/release/publish.py --notes-file notes.txt
```
会自动扫描 `src-tauri/target` 下**存在的**产物(Windows / Linux / macOS 各归各位),
拷到官网 `download/`,并把对应平台写进 `update/latest.json`(**合并**语义:
在 Windows 上发版不会把 macOS 那条冲掉)。
## 用 Tauri 打包(推荐的安装包) ## 用 Tauri 打包(推荐的安装包)
Tauri 版走系统 WebView2,**不用捆绑运行时**,安装包比 Electron 版小一个数量级。 Tauri 版走系统 WebView2,**不用捆绑运行时**,安装包比 Electron 版小一个数量级。
+35 -1
View File
@@ -482,6 +482,26 @@
</p> </p>
<a class="btn btn-line" data-dl="portable" href="/download/latest-portable.exe" download>下载便携版 .exe</a> <a class="btn btn-line" data-dl="portable" href="/download/latest-portable.exe" download>下载便携版 .exe</a>
</div> </div>
<div class="dl-card" data-plat="mac" hidden>
<h3>macOS</h3>
<div class="dl-size">.dmg · Apple Silicon / Intel</div>
<p>
拖进「应用程序」即可。未做苹果开发者签名,首次打开需<b>右键 → 打开</b>(或
在终端执行 <code>xattr -dr com.apple.quarantine /Applications/XiaoyinMarkdown.app</code>)。
</p>
<a class="btn btn-line" data-dl="mac-arm" href="/download/latest-setup.exe" download>Apple Silicon</a>
<a class="btn btn-line" data-dl="mac-x64" href="/download/latest-setup.exe" download style="margin-top:8px">Intel</a>
</div>
<div class="dl-card" data-plat="linux" hidden>
<h3>Linux</h3>
<div class="dl-size">AppImage / deb · x86_64</div>
<p>
AppImage 免安装,<code>chmod +x</code> 后双击即可;deb 适合 Debian / Ubuntu 系。
需要系统里有 WebKitGTK 4.1。
</p>
<a class="btn btn-line" data-dl="linux-appimage" href="/download/latest-setup.exe" download>AppImage</a>
<a class="btn btn-line" data-dl="linux-deb" href="/download/latest-setup.exe" download style="margin-top:8px">.deb</a>
</div>
<div class="dl-card"> <div class="dl-card">
<h3>源码 / 旧版</h3> <h3>源码 / 旧版</h3>
<div class="dl-size">Gitea · GitHub</div> <div class="dl-size">Gitea · GitHub</div>
@@ -546,13 +566,27 @@
document.querySelectorAll('[data-ver]').forEach((el) => { el.textContent = m.version; }); document.querySelectorAll('[data-ver]').forEach((el) => { el.textContent = m.version; });
document.querySelectorAll('[data-notes]').forEach((el) => { el.textContent = m.notes || ''; }); document.querySelectorAll('[data-notes]').forEach((el) => { el.textContent = m.notes || ''; });
// 下载文件名带版本号:xymd_2.6.2.exe / xymd_2.6.2_portable.exe // 下载文件名带版本号:xymd_2.6.2.exe / xymd_2.6.2_portable.exe
const map = { setup: `xymd_${m.version}.exe`, portable: `xymd_${m.version}_portable.exe` }; const map = {
setup: `xymd_${m.version}.exe`,
portable: `xymd_${m.version}_portable.exe`,
'mac-arm': `xymd_${m.version}_aarch64.dmg`,
'mac-x64': `xymd_${m.version}_x64.dmg`,
'linux-appimage': `xymd_${m.version}_amd64.AppImage`,
'linux-deb': `xymd_${m.version}_amd64.deb`,
};
Object.entries(map).forEach(([kind, name]) => { Object.entries(map).forEach(([kind, name]) => {
document.querySelectorAll(`[data-dl="${kind}"]`).forEach((a) => { document.querySelectorAll(`[data-dl="${kind}"]`).forEach((a) => {
a.setAttribute('href', `/download/${name}`); a.setAttribute('href', `/download/${name}`);
a.setAttribute('download', name); a.setAttribute('download', name);
}); });
}); });
// 清单里出现哪个平台,才显示那张下载卡(没构建过就不显示,避免 404)
const plats = Object.keys(m.platforms || {});
const has = (p) => plats.some((k) => k === p || k.startsWith(p));
document.querySelectorAll('[data-plat]').forEach((el) => {
const ok = el.dataset.plat === 'mac' ? has('darwin') : has('linux');
el.hidden = !ok;
});
}) })
.catch(() => {}); .catch(() => {});
</script> </script>
+7 -1
View File
@@ -1,13 +1,19 @@
{ {
"version": "2.6.5", "version": "2.6.5",
"notes": "① 状态栏右下角显示当前版本号(就在「检查更新」左边)\n② 版本号从程序本身读取,不会和实际版本对不上", "notes": "① 状态栏右下角显示当前版本号(就在「检查更新」左边)\n② 版本号从程序本身读取,不会和实际版本对不上",
"pub_date": "2026-11-20T03:03:02Z", "pub_date": "2026-11-20T03:26:59Z",
"platforms": { "platforms": {
"windows-x86_64": { "windows-x86_64": {
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVSWWkrQjVjQnNqN3VxSWFBMjI5Vi9iajIwaVNtWTJlOXJ0Z3B5cGdyWUZsSGVpUXVNbW1aQ2hXazViaUJTWHZ5ZGtUY2NMOUZPMkJZazZZd0ZZa3JFWkZRdDR6RlFSdndZPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk1MTQzNjgwCWZpbGU6WGlhb3lpbk1hcmtkb3duXzIuNi41X3g2NC1zZXR1cC5leGUJdmVyc2lvbjoyLjYuNQpYcjVSbFB3bzdUeTZ2eTVjSlB1Uk41ZE9MaStSeCtxNVFLZ2RlNHF3QVozRUVvNiszaXp1SVRzait3dTM1U3J3RzBsa0ZXVmVnS21ZejBicXZrZndBdz09Cg==", "signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVSWWkrQjVjQnNqN3VxSWFBMjI5Vi9iajIwaVNtWTJlOXJ0Z3B5cGdyWUZsSGVpUXVNbW1aQ2hXazViaUJTWHZ5ZGtUY2NMOUZPMkJZazZZd0ZZa3JFWkZRdDR6RlFSdndZPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk1MTQzNjgwCWZpbGU6WGlhb3lpbk1hcmtkb3duXzIuNi41X3g2NC1zZXR1cC5leGUJdmVyc2lvbjoyLjYuNQpYcjVSbFB3bzdUeTZ2eTVjSlB1Uk41ZE9MaStSeCtxNVFLZ2RlNHF3QVozRUVvNiszaXp1SVRzait3dTM1U3J3RzBsa0ZXVmVnS21ZejBicXZrZndBdz09Cg==",
"url": "https://md.wangjinding.com/download/xymd_2.6.5.exe", "url": "https://md.wangjinding.com/download/xymd_2.6.5.exe",
"size": 2324255, "size": 2324255,
"sha256": "db19986c7497e5409828f76d130b75df1a14f39ce6b24205c06545d9ed003806" "sha256": "db19986c7497e5409828f76d130b75df1a14f39ce6b24205c06545d9ed003806"
},
"linux-x86_64": {
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVSWWkrQjVjQnNqN3AyTHlzdUhtSzVrb0VEelJFUk01Y1ZVLzVXNjVtbjd2V2hQelkzeXRvV2IzT2x1WERNdHovMmZSMDlUcUdESm1tWXBGN0R5REdMSk84YTg5QStCUGdFPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk1MTQ1MDk1CWZpbGU6WGlhb3lpbk1hcmtkb3duXzIuNi41X2FtZDY0LkFwcEltYWdlCXZlcnNpb246Mi42LjUKckFYTE9WQ2JLdkZLcWd5VGc0YWNJQVBKbDFGd2M4K1dNOU1sVnhwMlJRRlo4dEpacHY3RkNhRHZCdEtETENpOUY2VzN2bzFySVdENkFNMGs1Vjg3QVE9PQo=",
"url": "https://md.wangjinding.com/download/xymd_2.6.5_amd64.AppImage",
"size": 108648952,
"sha256": "cc4b73017ae835b3cc4ba25f338ebfcdf20538c31942e9c607ae52d5dc73ab71"
} }
} }
} }
+169
View File
@@ -47,6 +47,26 @@ version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]]
name = "arboard"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aeb9553e62312c8756a5979254fc6d7da8bbeb5986a1e17037fab932f7037917"
dependencies = [
"clipboard-win",
"image",
"log",
"objc2",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation",
"parking_lot",
"percent-encoding",
"windows-sys 0.61.2",
"x11rb",
]
[[package]] [[package]]
name = "async-broadcast" name = "async-broadcast"
version = "0.7.2" version = "0.7.2"
@@ -358,6 +378,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "byteorder-lite"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.12.2" version = "1.12.2"
@@ -643,6 +669,12 @@ version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
[[package]]
name = "crunchy"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.7" version = "0.1.7"
@@ -1042,6 +1074,12 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
[[package]]
name = "fax"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"
[[package]] [[package]]
name = "fdeflate" name = "fdeflate"
version = "0.3.7" version = "0.3.7"
@@ -1329,6 +1367,16 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "gethostname"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
dependencies = [
"rustix",
"windows-link",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.17" version = "0.2.17"
@@ -1513,6 +1561,17 @@ dependencies = [
"syn 2.0.119", "syn 2.0.119",
] ]
[[package]]
name = "half"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
dependencies = [
"cfg-if",
"crunchy",
"zerocopy",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@@ -1822,6 +1881,20 @@ dependencies = [
"icu_properties", "icu_properties",
] ]
[[package]]
name = "image"
version = "0.25.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
dependencies = [
"bytemuck",
"byteorder-lite",
"moxcms",
"num-traits",
"png",
"tiff",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "1.9.3"
@@ -2229,6 +2302,16 @@ dependencies = [
"windows-sys 0.61.2", "windows-sys 0.61.2",
] ]
[[package]]
name = "moxcms"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
dependencies = [
"num-traits",
"pxfm",
]
[[package]] [[package]]
name = "muda" name = "muda"
version = "0.20.0" version = "0.20.0"
@@ -2355,6 +2438,7 @@ dependencies = [
"block2", "block2",
"objc2", "objc2",
"objc2-core-foundation", "objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation", "objc2-foundation",
"objc2-quartz-core", "objc2-quartz-core",
] ]
@@ -2913,6 +2997,18 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "pxfm"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
[[package]]
name = "quick-error"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.42.0" version = "0.42.0"
@@ -4282,6 +4378,20 @@ dependencies = [
"syn 3.0.10", "syn 3.0.10",
] ]
[[package]]
name = "tiff"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52"
dependencies = [
"fax",
"flate2",
"half",
"quick-error",
"weezl",
"zune-jpeg",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.55" version = "0.3.55"
@@ -4929,6 +5039,12 @@ dependencies = [
"windows-core", "windows-core",
] ]
[[package]]
name = "weezl"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@@ -5358,6 +5474,23 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "x11rb"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414"
dependencies = [
"gethostname",
"rustix",
"x11rb-protocol",
]
[[package]]
name = "x11rb-protocol"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
[[package]] [[package]]
name = "xattr" name = "xattr"
version = "1.7.0" version = "1.7.0"
@@ -5372,6 +5505,7 @@ dependencies = [
name = "xiaoyin-markdown" name = "xiaoyin-markdown"
version = "2.6.5" version = "2.6.5"
dependencies = [ dependencies = [
"arboard",
"chrono", "chrono",
"clipboard-win", "clipboard-win",
"serde", "serde",
@@ -5478,6 +5612,26 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "zerocopy"
version = "0.8.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]] [[package]]
name = "zerofrom" name = "zerofrom"
version = "0.1.8" version = "0.1.8"
@@ -5582,6 +5736,21 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
[[package]]
name = "zune-core"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b"
[[package]]
name = "zune-jpeg"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
dependencies = [
"zune-core",
]
[[package]] [[package]]
name = "zvariant" name = "zvariant"
version = "5.15.1" version = "5.15.1"
+7
View File
@@ -17,6 +17,9 @@ tauri-plugin-process = "2"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
chrono = "0.4" chrono = "0.4"
serde_json = "1" serde_json = "1"
# —— 三端:平台专属依赖各归各的 ——
# Windows:剪贴板里放「文件本身」要靠 Win32 的 CF_HDROP
[target.'cfg(windows)'.dependencies]
clipboard-win = "5" clipboard-win = "5"
windows-sys = { version = "0.61", features = [ windows-sys = { version = "0.61", features = [
"Win32_Foundation", "Win32_Foundation",
@@ -26,6 +29,10 @@ windows-sys = { version = "0.61", features = [
"Win32_UI_WindowsAndMessaging" "Win32_UI_WindowsAndMessaging"
] } ] }
# macOS / Linux:文本剪贴板用 arboard(macOS 走 NSPasteboard,Linux 走 X11/Wayland)
[target.'cfg(not(windows))'.dependencies]
arboard = "3"
[profile.release] [profile.release]
opt-level = "s" opt-level = "s"
lto = true lto = true
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<background android:drawable="@color/ic_launcher_background"/>
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

+96 -11
View File
@@ -1,5 +1,6 @@
// 小银 Markdown —— Tauri 2 后端 // 小银 Markdown —— Tauri 2 后端
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // 只在 Windows 上隐藏控制台窗口(macOS/Linux 没有这个概念)
#![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
use serde::Serialize; use serde::Serialize;
use std::fs; use std::fs;
@@ -254,9 +255,10 @@ fn read_dir(path: String) -> DirResult {
/* ---------------- 剪贴板 ---------------- */ /* ---------------- 剪贴板 ---------------- */
/// Windows:把「文件本身」放进剪贴板(CF_HDROP),能直接粘到资源管理器 / 微信
#[cfg(windows)]
#[tauri::command] #[tauri::command]
fn copy_file_to_clipboard(path: String) -> Result<(), String> { fn copy_file_to_clipboard(path: String) -> Result<(), String> {
// 手写 CF_HDROP:DROPFILES 头 + 双 \0 结尾的 UTF-16 路径列表
use windows_sys::Win32::System::DataExchange::{CloseClipboard, EmptyClipboard, OpenClipboard, SetClipboardData}; use windows_sys::Win32::System::DataExchange::{CloseClipboard, EmptyClipboard, OpenClipboard, SetClipboardData};
use windows_sys::Win32::System::Memory::{GlobalAlloc, GlobalLock, GlobalUnlock, GMEM_MOVEABLE, GMEM_ZEROINIT}; use windows_sys::Win32::System::Memory::{GlobalAlloc, GlobalLock, GlobalUnlock, GMEM_MOVEABLE, GMEM_ZEROINIT};
use windows_sys::Win32::UI::Shell::DROPFILES; use windows_sys::Win32::UI::Shell::DROPFILES;
@@ -273,10 +275,10 @@ fn copy_file_to_clipboard(path: String) -> Result<(), String> {
} }
let mut wide: Vec<u16> = path.encode_utf16().collect(); let mut wide: Vec<u16> = path.encode_utf16().collect();
wide.push(0); // 路径自身的 \0 终止符 wide.push(0);
let header_size = std::mem::size_of::<DROPFILES>(); let header_size = std::mem::size_of::<DROPFILES>();
let list_bytes = (wide.len() + 1) * 2; // +1 是列表级双 \0 结束符 let list_bytes = (wide.len() + 1) * 2;
let total = header_size + list_bytes; let total = header_size + list_bytes;
let h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, total); let h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, total);
@@ -291,7 +293,7 @@ fn copy_file_to_clipboard(path: String) -> Result<(), String> {
} }
let df = locked as *mut DROPFILES; let df = locked as *mut DROPFILES;
(*df).pFiles = header_size as u32; (*df).pFiles = header_size as u32;
(*df).fWide = 1; // UTF-16 (*df).fWide = 1;
let dst = (locked as *mut u8).add(header_size); let dst = (locked as *mut u8).add(header_size);
std::ptr::copy_nonoverlapping(wide.as_ptr() as *const u8, dst, wide.len() * 2); std::ptr::copy_nonoverlapping(wide.as_ptr() as *const u8, dst, wide.len() * 2);
GlobalUnlock(h); GlobalUnlock(h);
@@ -305,18 +307,42 @@ fn copy_file_to_clipboard(path: String) -> Result<(), String> {
Ok(()) Ok(())
} }
/// macOS / Linux:剪贴板没有跨平台的「文件」格式(要写 GTK/X11 私有 target),
/// 退化成把路径当文本复制 —— 粘到终端、编辑器、下载框里都还能用。
#[cfg(not(windows))]
#[tauri::command]
fn copy_file_to_clipboard(path: String) -> Result<(), String> {
write_clipboard_text(path)
}
#[cfg(windows)]
#[tauri::command] #[tauri::command]
fn read_clipboard_text() -> String { fn read_clipboard_text() -> String {
use clipboard_win::formats; use clipboard_win::formats;
use clipboard_win::get_clipboard; clipboard_win::get_clipboard(formats::Unicode).unwrap_or_default()
get_clipboard(formats::Unicode).unwrap_or_default()
} }
#[cfg(not(windows))]
#[tauri::command]
fn read_clipboard_text() -> String {
arboard::Clipboard::new()
.and_then(|mut c| c.get_text())
.unwrap_or_default()
}
#[cfg(windows)]
#[tauri::command] #[tauri::command]
fn write_clipboard_text(text: String) -> Result<(), String> { fn write_clipboard_text(text: String) -> Result<(), String> {
use clipboard_win::formats; use clipboard_win::formats;
use clipboard_win::set_clipboard; clipboard_win::set_clipboard(formats::Unicode, text).map_err(|e| e.to_string())
set_clipboard(formats::Unicode, text).map_err(|e| e.to_string()) }
#[cfg(not(windows))]
#[tauri::command]
fn write_clipboard_text(text: String) -> Result<(), String> {
arboard::Clipboard::new()
.and_then(|mut c| c.set_text(text))
.map_err(|e| e.to_string())
} }
/* ---------------- 系统 ---------------- */ /* ---------------- 系统 ---------------- */
@@ -324,6 +350,10 @@ fn write_clipboard_text(text: String) -> Result<(), String> {
#[tauri::command] #[tauri::command]
fn reveal_in_explorer(path: String) -> Result<(), String> { fn reveal_in_explorer(path: String) -> Result<(), String> {
let p = PathBuf::from(&path); let p = PathBuf::from(&path);
// Windows:资源管理器并选中该文件
#[cfg(windows)]
{
if p.is_file() { if p.is_file() {
std::process::Command::new("explorer") std::process::Command::new("explorer")
.arg(format!("/select,{}", p.to_string_lossy())) .arg(format!("/select,{}", p.to_string_lossy()))
@@ -335,7 +365,42 @@ fn reveal_in_explorer(path: String) -> Result<(), String> {
.spawn() .spawn()
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
} }
Ok(()) return Ok(());
}
// macOS:Finder 里选中(open -R)
#[cfg(target_os = "macos")]
{
let _ = &p;
if p.is_file() {
std::process::Command::new("open")
.arg("-R")
.arg(&p)
.spawn()
.map_err(|e| e.to_string())?;
} else {
std::process::Command::new("open")
.arg(&p)
.spawn()
.map_err(|e| e.to_string())?;
}
return Ok(());
}
// Linux:没有统一的「选中」接口,打开所在目录
#[cfg(all(unix, not(target_os = "macos")))]
{
let dir = if p.is_dir() {
p.clone()
} else {
p.parent().map(|x| x.to_path_buf()).unwrap_or(p.clone())
};
std::process::Command::new("xdg-open")
.arg(&dir)
.spawn()
.map_err(|e| e.to_string())?;
return Ok(());
}
} }
#[tauri::command] #[tauri::command]
@@ -343,11 +408,31 @@ fn open_external(url: String) -> Result<(), String> {
if !url.starts_with("http://") && !url.starts_with("https://") { if !url.starts_with("http://") && !url.starts_with("https://") {
return Err("仅允许打开 http/https 链接".into()); return Err("仅允许打开 http/https 链接".into());
} }
#[cfg(windows)]
{
std::process::Command::new("explorer") std::process::Command::new("explorer")
.arg(&url) .arg(&url)
.spawn() .spawn()
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
Ok(()) return Ok(());
}
#[cfg(target_os = "macos")]
{
std::process::Command::new("open")
.arg(&url)
.spawn()
.map_err(|e| e.to_string())?;
return Ok(());
}
#[cfg(all(unix, not(target_os = "macos")))]
{
std::process::Command::new("xdg-open")
.arg(&url)
.spawn()
.map_err(|e| e.to_string())?;
return Ok(());
}
} }
#[tauri::command] #[tauri::command]
+20 -4
View File
@@ -25,10 +25,12 @@
}, },
"bundle": { "bundle": {
"active": true, "active": true,
"targets": [ "targets": "all",
"nsis"
],
"icon": [ "icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico" "icons/icon.ico"
], ],
"fileAssociations": [ "fileAssociations": [
@@ -68,7 +70,21 @@
"installerHooks": "installer-hooks.nsh" "installerHooks": "installer-hooks.nsh"
} }
}, },
"createUpdaterArtifacts": true "createUpdaterArtifacts": true,
"linux": {
"deb": {
"depends": [
"libwebkit2gtk-4.1-0",
"libgtk-3-0"
]
},
"appimage": {
"bundleMediaFramework": false
}
},
"macOS": {
"minimumSystemVersion": "10.15"
}
}, },
"plugins": { "plugins": {
"updater": { "updater": {
+124 -77
View File
@@ -1,36 +1,39 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""把小银 Markdown 的构建产物发布到官网,并生成升级清单。 """把三端构建产物发布到官网,并生成/合并升级清单。
用法: 用法:
python3 tools/release/publish.py --notes "更新说明……" # 用当前 tauri.conf.json 的版本 python3 tools/release/publish.py --notes-file notes.txt # 自动扫描全部产物
python3 tools/release/publish.py --notes "……" --dry-run python3 tools/release/publish.py --notes "一句话" --dry-run
做的事: 自动识别(存在哪些就发哪些,都按平台归位):
1. 从 src-tauri/.../bundle/nsis/ 找安装包和 .sig 签名 Windows target/x86_64-pc-windows-gnu/release/bundle/nsis/*x64-setup.exe
2. 拷安装包到站点 download/(顺便拷一份免安装 exe) Linux target/release/bundle/{appimage/*.AppImage, deb/*.deb}
3. 写 site/update/latest.json —— 客户端 updater 就拉这个 macOS target/<triple>/release/bundle/{macos/*.app.tar.gz, dmg/*.dmg}
4. 打印最终 URL 与校验值
客户端地址:https://md.wangjinding.com/update/latest.json 升级清单是**合并**的:只更新这次扫到的平台,其它平台的条目原样保留
(这样在 Windows 上发版不会把 macOS 的那条冲掉)。
客户端拉取:https://md.wangjinding.com/update/latest.json
""" """
from __future__ import annotations from __future__ import annotations
import argparse import argparse
import hashlib import hashlib
import json import json
import platform as _py_platform
import re
import shutil import shutil
import subprocess
import sys import sys
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
ROOT = Path(__file__).resolve().parents[2] ROOT = Path(__file__).resolve().parents[2]
TARGET = ROOT / "src-tauri" / "target" / "x86_64-pc-windows-gnu" / "release"
NSIS_DIR = TARGET / "bundle" / "nsis"
SITE = ROOT / "site" SITE = ROOT / "site"
SITE_DOWNLOAD = Path("/opt/1panel/www/sites/md.wangjinding.com/index/download") SITE_ROOT = Path("/opt/1panel/www/sites/md.wangjinding.com/index")
SITE_UPDATE = Path("/opt/1panel/www/sites/md.wangjinding.com/index/update") SITE_DOWNLOAD = SITE_ROOT / "download"
SITE_UPDATE = SITE_ROOT / "update"
BASE_URL = "https://md.wangjinding.com" BASE_URL = "https://md.wangjinding.com"
TARGETS = ROOT / "src-tauri" / "target"
def conf_version() -> str: def conf_version() -> str:
@@ -46,104 +49,148 @@ def sha256(path: Path) -> str:
return h.hexdigest() return h.hexdigest()
def find_one(patterns: list[str]) -> Path | None:
for pat in patterns:
hits = sorted(TARGETS.glob(pat), key=lambda p: p.stat().st_mtime, reverse=True)
if hits:
return hits[0]
return None
def collect():
"""返回 [{platform, artifact, sig, dl_name}],只包含本机实际构建出来的。"""
found = []
# ── Windows ──
exe = find_one([
"x86_64-pc-windows-gnu/release/bundle/nsis/*_x64-setup.exe",
"release/bundle/nsis/*_x64-setup.exe",
])
if exe:
found.append({"platform": "windows-x86_64", "artifact": exe, "sig": Path(str(exe) + ".sig"), "ext": ".exe"})
# ── Linux(updater 只认 AppImage,deb 额外给人手装)──
appimg = find_one(["release/bundle/appimage/*.AppImage", "*/release/bundle/appimage/*.AppImage"])
if appimg:
found.append({"platform": "linux-x86_64", "artifact": appimg, "sig": Path(str(appimg) + ".sig"), "ext": ".AppImage"})
deb = find_one(["release/bundle/deb/*.deb", "*/release/bundle/deb/*.deb"])
if deb:
found.append({"platform": "linux-deb", "artifact": deb, "sig": None, "ext": ".deb"})
# ── macOS(Intel / Apple Silicon 各一份)──
for triple, key in (("aarch64-apple-darwin", "darwin-aarch64"), ("x86_64-apple-darwin", "darwin-x86_64")):
tar = find_one([f"{triple}/release/bundle/macos/*.app.tar.gz",
f"*/{triple}/release/bundle/macos/*.app.tar.gz"])
if tar:
found.append({"platform": key, "artifact": tar, "sig": Path(str(tar) + ".sig"), "ext": ".app.tar.gz"})
dmg = find_one([f"{triple}/release/bundle/dmg/*.dmg", f"*/{triple}/release/bundle/dmg/*.dmg"])
if dmg:
arch = "aarch64" if "aarch64" in triple else "x64"
found.append({"platform": f"{key}-dmg", "artifact": dmg, "sig": None, "ext": f"_{arch}.dmg"})
return found
def main() -> int: def main() -> int:
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
ap.add_argument("--notes", default="", help="更新说明(会显示在客户的升级弹窗里)") ap.add_argument("--notes", default="")
ap.add_argument("--notes-file", default="", help="从文件读更新说明,多行编号时用,避免命令行转义") ap.add_argument("--notes-file", default="")
ap.add_argument("--dry-run", action="store_true") ap.add_argument("--dry-run", action="store_true")
args = ap.parse_args() args = ap.parse_args()
if args.notes_file: if args.notes_file:
args.notes = Path(args.notes_file).read_text(encoding="utf-8").strip() args.notes = Path(args.notes_file).read_text(encoding="utf-8").strip()
version = conf_version() version = conf_version()
setup = NSIS_DIR / f"XiaoyinMarkdown_{version}_x64-setup.exe" items = collect()
sig_file = Path(str(setup) + ".sig") if not items:
print("❌ 没找到任何构建产物(先跑 `npx tauri build`)", file=sys.stderr)
if not setup.exists():
print(f"❌ 找不到安装包:{setup}", file=sys.stderr)
return 1
if not sig_file.exists():
print(f"❌ 找不到签名:{sig_file}\n 构建时是否漏了 TAURI_SIGNING_PRIVATE_KEY?", file=sys.stderr)
return 1 return 1
signature = sig_file.read_text(encoding="utf-8").strip() # 现有清单(合并用)
size = setup.stat().st_size manifest_path = SITE_UPDATE / "latest.json"
digest = sha256(setup) manifest = {"version": version, "notes": args.notes or f"小银 Markdown v{version}",
# 下载文件名带版本号:xymd_2.6.2.exe(浏览器另存就是这个名)
dl_name = f"xymd_{version}.exe"
url = f"{BASE_URL}/download/{dl_name}"
manifest = {
"version": version,
"notes": args.notes or f"小银 Markdown v{version}",
"pub_date": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), "pub_date": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"platforms": { "platforms": {}}
"windows-x86_64": { if manifest_path.exists():
"signature": signature, try:
old = json.loads(manifest_path.read_text(encoding="utf-8"))
manifest["platforms"] = old.get("platforms", {})
except Exception:
pass
print(f" 版本: {version}\n")
for it in items:
art: Path = it["artifact"]
size = art.stat().st_size
digest = sha256(art)
# 落地文件名:xymd_<版本>[_arch].<ext>
if it["platform"] == "windows-x86_64":
dl = f"xymd_{version}{it['ext']}"
elif it["platform"] == "linux-x86_64":
dl = f"xymd_{version}_amd64{it['ext']}"
elif it["platform"] == "linux-deb":
dl = f"xymd_{version}_amd64{it['ext']}"
else:
dl = f"xymd_{version}{it['ext']}"
url = f"{BASE_URL}/download/{dl}"
has_updater = it["sig"] is not None and it["sig"].exists()
if has_updater:
entry = {
"signature": it["sig"].read_text(encoding="utf-8").strip(),
"url": url, "url": url,
"size": size, "size": size,
"sha256": digest, "sha256": digest,
} }
}, key = it["platform"]
} manifest["platforms"][key] = entry
print(f" ✔ {key:18} {art.name} {size/1048576:.2f} MB → /download/{dl}")
else:
print(f" · {it['platform']:18} {art.name} {size/1048576:.2f} MB → /download/{dl}(不上升级清单)")
print(f" 版本 : {version}") if not args.dry_run:
print(f" 安装包 : {setup.name} {size/1048576:.2f} MB") SITE_DOWNLOAD.mkdir(parents=True, exist_ok=True)
print(f" sha256 : {digest[:32]}…") shutil.copy2(art, SITE_DOWNLOAD / dl)
print(f" 签名 : {signature[:40]}…") (SITE_DOWNLOAD / dl).chmod(0o644)
print(f" 下载地址 : {url}")
if args.dry_run: if args.dry_run:
print(" [dry-run] 不写入任何文件") print("\n [dry-run] 不写入任何文件")
return 0 return 0
SITE_UPDATE.mkdir(parents=True, exist_ok=True) # 写清单:站点 + 仓库各一份
SITE_DOWNLOAD.mkdir(parents=True, exist_ok=True)
# ① 安装包(客户下载 + updater 拉取的是同一个)
shutil.copy2(setup, SITE_DOWNLOAD / setup.name)
(SITE_DOWNLOAD / setup.name).chmod(0o644)
# ② 免安装版
portable = TARGET / "xiaoyin-markdown.exe"
if portable.exists():
shutil.copy2(portable, SITE_DOWNLOAD / "XiaoyinMarkdown-portable.exe")
(SITE_DOWNLOAD / "XiaoyinMarkdown-portable.exe").chmod(0o644)
# ③ 升级清单(站点 + 仓库各存一份,方便回滚)
body = json.dumps(manifest, ensure_ascii=False, indent=2) + "\n" body = json.dumps(manifest, ensure_ascii=False, indent=2) + "\n"
SITE_UPDATE.mkdir(parents=True, exist_ok=True)
(SITE_UPDATE / "latest.json").write_text(body, encoding="utf-8") (SITE_UPDATE / "latest.json").write_text(body, encoding="utf-8")
(SITE / "update").mkdir(parents=True, exist_ok=True) (SITE / "update").mkdir(parents=True, exist_ok=True)
(SITE / "update" / "latest.json").write_text(body, encoding="utf-8") (SITE / "update" / "latest.json").write_text(body, encoding="utf-8")
# ④ 带版本号的文件名(浏览器另存为 xymd_<版本>.exe) # 稳定别名(官网页 JS 会按版本改名,这些是 JS 被禁时的兜底)
for name, real in ((dl_name, setup.name), (f"xymd_{version}_portable.exe", "XiaoyinMarkdown-portable.exe")): alias_src = None
link = SITE_DOWNLOAD / name for it in items:
if link.is_symlink() or link.exists(): if it["platform"] == "windows-x86_64":
link.unlink() alias_src = f"xymd_{version}.exe"
if (SITE_DOWNLOAD / real).exists(): if alias_src and (SITE_DOWNLOAD / alias_src).exists():
link.symlink_to(real) for alias in ("latest-setup.exe",):
# ⑤ 稳定别名:官网页固定链到 latest-setup.exe,发版不用改 HTML
for alias, real in (("latest-setup.exe", setup.name), ("latest-portable.exe", "XiaoyinMarkdown-portable.exe")):
link = SITE_DOWNLOAD / alias link = SITE_DOWNLOAD / alias
if link.is_symlink() or link.exists(): if link.is_symlink() or link.exists():
link.unlink() link.unlink()
link.symlink_to(real) link.symlink_to(alias_src)
# ⑤ 官网静态兜底版本号也一起改(正常浏览器会被 latest.json 覆盖,这是给无 JS 情况的) # 官网静态兜底版本号
import re as _re
idx = SITE / "index.html" idx = SITE / "index.html"
if idx.exists(): if idx.exists():
html = idx.read_text(encoding="utf-8") html = idx.read_text(encoding="utf-8")
html2 = _re.sub(r"(data-ver>)\d+\.\d+\.\d+", lambda m: m.group(1) + version, html) html2 = re.sub(r"(data-ver>)\d+\.\d+\.\d+", lambda m: m.group(1) + version, html)
if html2 != html: if html2 != html:
idx.write_text(html2, encoding="utf-8") idx.write_text(html2, encoding="utf-8")
if SITE_ROOT.exists():
shutil.copy2(idx, SITE_ROOT / "index.html")
print(f"\n ✅ 已发布:{BASE_URL}/update/latest.json") print(f"\n ✅ 清单已更新:{BASE_URL}/update/latest.json({len(manifest['platforms'])} 个平台)")
print(f" ✅ 稳定别名:{BASE_URL}/download/latest-setup.exe") for k in manifest["platforms"]:
print(f" ✅ 版本文件名:{url}") print(f" · {k}")
print(f" ✅ 安装包:{url}")
return 0 return 0