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 配升级签名私钥(和可选的苹果开发者证书)
TXT
echo "  ✅ $(git log --oneline -1)"
This commit is contained in:
Jidekin committed 2026-11-20 11:28:05 +08:00
1 parent 6aa1689574
commit 7d8e95f348
61 files changed
+633 -109

No files matched your search

+108 -23
View File
@@ -1,5 +1,6 @@
// 小银 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 std::fs;
@@ -254,9 +255,10 @@ fn read_dir(path: String) -> DirResult {
/* ---------------- 剪贴板 ---------------- */
/// Windows:把「文件本身」放进剪贴板(CF_HDROP),能直接粘到资源管理器 / 微信
#[cfg(windows)]
#[tauri::command]
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::Memory::{GlobalAlloc, GlobalLock, GlobalUnlock, GMEM_MOVEABLE, GMEM_ZEROINIT};
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();
wide.push(0); // 路径自身的 \0 终止符
wide.push(0);
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 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;
(*df).pFiles = header_size as u32;
(*df).fWide = 1; // UTF-16
(*df).fWide = 1;
let dst = (locked as *mut u8).add(header_size);
std::ptr::copy_nonoverlapping(wide.as_ptr() as *const u8, dst, wide.len() * 2);
GlobalUnlock(h);
@@ -305,18 +307,42 @@ fn copy_file_to_clipboard(path: String) -> Result<(), String> {
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]
fn read_clipboard_text() -> String {
use clipboard_win::formats;
use clipboard_win::get_clipboard;
get_clipboard(formats::Unicode).unwrap_or_default()
clipboard_win::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]
fn write_clipboard_text(text: String) -> Result<(), String> {
use clipboard_win::formats;
use clipboard_win::set_clipboard;
set_clipboard(formats::Unicode, text).map_err(|e| e.to_string())
clipboard_win::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,18 +350,57 @@ fn write_clipboard_text(text: String) -> Result<(), String> {
#[tauri::command]
fn reveal_in_explorer(path: String) -> Result<(), String> {
let p = PathBuf::from(&path);
if p.is_file() {
std::process::Command::new("explorer")
.arg(format!("/select,{}", p.to_string_lossy()))
// Windows:资源管理器并选中该文件
#[cfg(windows)]
{
if p.is_file() {
std::process::Command::new("explorer")
.arg(format!("/select,{}", p.to_string_lossy()))
.spawn()
.map_err(|e| e.to_string())?;
} else {
std::process::Command::new("explorer")
.arg(&p)
.spawn()
.map_err(|e| e.to_string())?;
}
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())?;
} else {
std::process::Command::new("explorer")
.arg(&p)
.spawn()
.map_err(|e| e.to_string())?;
return Ok(());
}
Ok(())
}
#[tauri::command]
@@ -343,11 +408,31 @@ fn open_external(url: String) -> Result<(), String> {
if !url.starts_with("http://") && !url.starts_with("https://") {
return Err("仅允许打开 http/https 链接".into());
}
std::process::Command::new("explorer")
.arg(&url)
.spawn()
.map_err(|e| e.to_string())?;
Ok(())
#[cfg(windows)]
{
std::process::Command::new("explorer")
.arg(&url)
.spawn()
.map_err(|e| e.to_string())?;
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]