老板要求:用 Tauri 打包成 exe,安装后 .md 默认由小银 Markdown 打开。 一、交叉编译(Linux → Windows,无需 Windows 机器) 本机从零装了 rustc 1.100 / mingw-w64(GCC 14)/ NSIS 3.11, target `x86_64-pc-windows-gnu`,crates 走清华镜像: npx tauri build --target x86_64-pc-windows-gnu --bundles nsis 产物: · XiaoyinMarkdown_2.6.1_x64-setup.exe 1.52 MiB(NSIS 安装包) · xiaoyin-markdown.exe 3.5 MiB(免安装版) electron-packager 那版是 152 MiB —— 因为 Tauri 用系统 WebView2,不捆绑运行时。 已核对导入表:只依赖系统 DLL + 安装包内自带的 WebView2Loader.dll, 没有 libgcc_s_seh-1 / libwinpthread 之类的 mingw 运行时依赖,干净 Windows 可跑。 二、默认打开方式(两步,缺一不可) 1. tauri.conf.json 的 fileAssociations 早就配了 md/markdown/mdown/mkd/mdwn/txt; 已核对生成的 installer.nsi:6 条 APP_ASSOCIATE,写 HKCU\Software\Classes\.md = XiaoyinMarkdown.Document(默认 ProgId,不只是「打开方式」列表) 2. 新增 src-tauri/installer-hooks.nsh(NSIS_HOOK_POSTINSTALL): 删掉 HKCU\...\Explorer\FileExts\.md\UserChoice —— 这个键带哈希保护、只能删不能写, 不删的话用户原来的默认程序永远赢;删完再 SHChangeNotify 刷新图标缓存。 已用「故意 !error 探针」证明该钩子确实被 makensis 编译进去(installer.nsi:758), 不是写了没生效。 三、首次双击 .md 能打开文件 原来只有 single_instance 回调处理 argv(= 程序已在运行时才生效)。 新增 on_page_load(Finished) + std::sync::Once:冷启动时把 argv 里的文件路径 emit 给前端(前端 tauri-bridge 监听 open-external → doOpenPath)。 四、官网 下载区改成三档:安装版(1.6MB,推荐)/ 免安装 exe(3.5MB)/ 源码 + 旧 Electron 版。 两个新文件已部署到 /download/,公网 200。 README 补了「用 Tauri 打包」整节(含 UserChoice 这个坑),site/README 更新发布步骤。
72 lines
1.5 KiB
JSON
72 lines
1.5 KiB
JSON
{
|
|
"$schema": "https://schema.tauri.app/config/2",
|
|
"productName": "XiaoyinMarkdown",
|
|
"version": "2.6.1",
|
|
"identifier": "com.xiaoyin.markdown",
|
|
"build": {
|
|
"frontendDist": "../src/renderer"
|
|
},
|
|
"app": {
|
|
"withGlobalTauri": true,
|
|
"windows": [
|
|
{
|
|
"label": "main",
|
|
"title": "未命名 — 小银 Markdown",
|
|
"width": 1380,
|
|
"height": 880,
|
|
"minWidth": 860,
|
|
"minHeight": 520,
|
|
"dragDropEnabled": true
|
|
}
|
|
],
|
|
"security": {
|
|
"csp": null
|
|
}
|
|
},
|
|
"bundle": {
|
|
"active": true,
|
|
"targets": [
|
|
"nsis"
|
|
],
|
|
"icon": [
|
|
"icons/icon.ico"
|
|
],
|
|
"fileAssociations": [
|
|
{
|
|
"ext": [
|
|
"md",
|
|
"markdown",
|
|
"mdown",
|
|
"mkd",
|
|
"mdwn"
|
|
],
|
|
"name": "XiaoyinMarkdown.Document",
|
|
"description": "Markdown 文档 — 小银 Markdown",
|
|
"role": "Editor"
|
|
},
|
|
{
|
|
"ext": [
|
|
"txt"
|
|
],
|
|
"name": "XiaoyinMarkdown.Text",
|
|
"description": "文本文档 — 小银 Markdown",
|
|
"role": "Editor"
|
|
}
|
|
],
|
|
"windows": {
|
|
"webviewInstallMode": {
|
|
"type": "downloadBootstrapper"
|
|
},
|
|
"nsis": {
|
|
"installMode": "currentUser",
|
|
"languages": [
|
|
"SimpChinese"
|
|
],
|
|
"displayLanguageSelector": false,
|
|
"installerIcon": "icons/icon.ico",
|
|
"uninstallerIcon": "icons/icon.ico",
|
|
"installerHooks": "installer-hooks.nsh"
|
|
}
|
|
}
|
|
}
|
|
} |