doc: update docs/wails.md #973 cb3b1b89c5

This commit is contained in:
jaywcjlove
2025-06-16 13:43:39 +00:00
parent b4abe87a75
commit 5b736ba678
4 changed files with 13 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -78,7 +78,7 @@
<!--rehype:style=padding-top: 12px;-->
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#命令行工具-cli">命令行工具 (CLI)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装与更新">安装与更新</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#常用命令参数">常用命令参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#项目命令">项目命令</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#项目配置">项目配置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#项目结构">项目结构</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#wailsjson-详解">wails.json 详解</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#核心交互与生命周期">核心交互与生命周期</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#方法绑定-go---js">方法绑定 (Go &#x3C;-> JS)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#事件系统-events">事件系统 (Events)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#go-端-runtimeevents">Go 端 (runtime.Events*)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#javascript-端-runtimeevents">JavaScript 端 (runtime.Events*)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#应用生命周期钩子">应用生命周期钩子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#运行时-api-runtime">运行时 API (Runtime)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#窗口-window">窗口 (Window)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#对话框-dialog">对话框 (Dialog)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#go-端">Go 端</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#javascript-端">JavaScript 端</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#菜单-menu">菜单 (Menu)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#其他-runtime-api">其他 Runtime API</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#日志">日志</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#剪贴板">剪贴板</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#应用打包与分发">应用打包与分发</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#windows-打包">Windows 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-默认生成-exe-可执行文件"> 默认生成: .exe 可执行文件。</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-生成-nsis-安装程序"> 生成 NSIS 安装程序:</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-处理-webview2-依赖"> 处理 WebView2 依赖:</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#macos-打包">macOS 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-默认生成-app-应用程序包"> 默认生成: .app 应用程序包。</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-代码签名与公证"> 代码签名与公证:</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-跳过打包成-app-步骤"> 跳过打包成 .app 步骤:</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#linux-打包">Linux 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-生成可执行文件"> 生成可执行文件</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-打包成-deb"> 打包成 .deb</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-打包成-rpm"> 打包成 .rpm</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#appimage-支持">AppImage 支持</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#进阶主题与杂项">进阶主题与杂项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#平台特定构建选项">平台特定构建选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用-typescript">使用 TypeScript</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#调试">调试</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#参考资料">参考资料</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="命令行工具-cli"><a aria-hidden="true" tabindex="-1" href="#命令行工具-cli"><span class="icon icon-link"></span></a>命令行工具 (CLI)</h2><div class="wrap-body">
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#命令行工具-cli">命令行工具 (CLI)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装与更新">安装与更新</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#常用命令参数">常用命令参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#项目命令">项目命令</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#项目配置">项目配置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#项目结构">项目结构</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#wailsjson-详解">wails.json 详解</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#核心交互与生命周期">核心交互与生命周期</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#方法绑定-go---js">方法绑定 (Go &#x3C;-> JS)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#事件系统-events">事件系统 (Events)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#go-端-runtimeevents">Go 端 (runtime.Events*)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#javascript-端-runtimeevents">JavaScript 端 (runtime.Events*)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#应用生命周期钩子">应用生命周期钩子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#运行时-api-runtime">运行时 API (Runtime)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#窗口-window">窗口 (Window)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#对话框-dialog">对话框 (Dialog)</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#go-端">Go 端</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#javascript-端">JavaScript 端</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#菜单-menu">菜单 (Menu)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#其他-runtime-api">其他 Runtime API</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#日志">日志</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#剪贴板">剪贴板</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#应用打包与分发">应用打包与分发</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#windows-打包">Windows 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-默认生成-exe-可执行文件"> 默认生成: .exe 可执行文件。</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-生成-nsis-安装程序"> 生成 NSIS 安装程序:</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-处理-webview2-依赖"> 处理 WebView2 依赖:</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#macos-打包">macOS 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-默认生成-app-应用程序包"> 默认生成: .app 应用程序包。</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-代码签名与公证"> 代码签名与公证:</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-跳过打包成-app-步骤"> 跳过打包成 .app 步骤:</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#linux-打包">Linux 打包</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-生成可执行文件"> 生成可执行文件</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-打包成-deb"> 打包成 .deb</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#-打包成-rpm"> 打包成 .rpm</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#appimage-支持">AppImage 支持</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#进阶主题与杂项">进阶主题与杂项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#平台特定构建选项">平台特定构建选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用-typescript">使用 TypeScript</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#调试">调试</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#参考资料">参考资料</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="命令行工具-cli"><a aria-hidden="true" tabindex="-1" href="#命令行工具-cli"><span class="icon icon-link"></span></a>命令行工具 (CLI)</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="安装与更新"><a aria-hidden="true" tabindex="-1" href="#安装与更新"><span class="icon icon-link"></span></a>安装与更新</h3><div class="wrap-body">
<pre class="wrap-text"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 安装 Wails CLI</span>
</span><span class="code-line">$ go <span class="token function">install</span> github.com/wailsapp/wails/v2/cmd/wails@latest
@@ -494,11 +494,11 @@
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="应用打包与分发"><a aria-hidden="true" tabindex="-1" href="#应用打包与分发"><span class="icon icon-link"></span></a>应用打包与分发</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="windows-打包"><a aria-hidden="true" tabindex="-1" href="#windows-打包"><span class="icon icon-link"></span></a>Windows 打包</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<h4 style="text-align: left;font-weight: bold;" id="-默认生成-exe-可执行文件"><a aria-hidden="true" tabindex="-1" href="#-默认生成-exe-可执行文件"><span class="icon icon-link"></span></a><red></red> 默认生成: <code>.exe</code> 可执行文件。</h4>
<h4 style="text-align: left;font-weight: bold;" id="-默认生成-exe-可执行文件"><a aria-hidden="true" tabindex="-1" href="#-默认生成-exe-可执行文件"><span class="icon icon-link"></span></a><red></red> 默认生成: <code>.exe</code> 可执行文件。</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> windows/amd64
</span></code></pre>
<h4 style="text-align: left;font-weight: bold;" id="-生成-nsis-安装程序"><a aria-hidden="true" tabindex="-1" href="#-生成-nsis-安装程序"><span class="icon icon-link"></span></a><red></red> 生成 NSIS 安装程序:</h4>
<h4 style="text-align: left;font-weight: bold;" id="-生成-nsis-安装程序"><a aria-hidden="true" tabindex="-1" href="#-生成-nsis-安装程序"><span class="icon icon-link"></span></a><red></red> 生成 NSIS 安装程序:</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<p><strong>前提条件</strong>: 需要预先安装 <a href="https://nsis.sourceforge.io/Download">NSIS (Nullsoft Scriptable Install System)</a></p>
<ul>
@@ -518,7 +518,7 @@
<p><strong>生成安装程序</strong>:</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> windows/amd64 <span class="token parameter variable">-nsis</span>
</span></code></pre>
<h4 style="text-align: left;font-weight: bold;" id="-处理-webview2-依赖"><a aria-hidden="true" tabindex="-1" href="#-处理-webview2-依赖"><span class="icon icon-link"></span></a><red></red> 处理 WebView2 依赖:</h4>
<h4 style="text-align: left;font-weight: bold;" id="-处理-webview2-依赖"><a aria-hidden="true" tabindex="-1" href="#-处理-webview2-依赖"><span class="icon icon-link"></span></a><red></red> 处理 WebView2 依赖:</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<p><code>download</code>: 提示用户下载 WebView2。</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> windows/amd64 <span class="token parameter variable">-webview2</span> download
@@ -530,28 +530,28 @@
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> windows/amd64 <span class="token parameter variable">-webview2</span> browser
</span></code></pre>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="macos-打包"><a aria-hidden="true" tabindex="-1" href="#macos-打包"><span class="icon icon-link"></span></a>macOS 打包</h3><div class="wrap-body">
<h4 style="text-align: left;font-weight: bold;" id="-默认生成-app-应用程序包"><a aria-hidden="true" tabindex="-1" href="#-默认生成-app-应用程序包"><span class="icon icon-link"></span></a><red></red> 默认生成: <code>.app</code> 应用程序包。</h4>
<h4 style="text-align: left;font-weight: bold;" id="-默认生成-app-应用程序包"><a aria-hidden="true" tabindex="-1" href="#-默认生成-app-应用程序包"><span class="icon icon-link"></span></a><red></red> 默认生成: <code>.app</code> 应用程序包。</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> darwin/amd64
</span></code></pre>
<h4 style="text-align: left;font-weight: bold;" id="-代码签名与公证"><a aria-hidden="true" tabindex="-1" href="#-代码签名与公证"><span class="icon icon-link"></span></a><red></red> 代码签名与公证:</h4>
<h4 style="text-align: left;font-weight: bold;" id="-代码签名与公证"><a aria-hidden="true" tabindex="-1" href="#-代码签名与公证"><span class="icon icon-link"></span></a><red></red> 代码签名与公证:</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<p>需要通过 Apple 开发者账户进行 <strong>代码签名</strong><strong>公证</strong> 才能分发。</p>
<h4 style="text-align: left;font-weight: bold;" id="-跳过打包成-app-步骤"><a aria-hidden="true" tabindex="-1" href="#-跳过打包成-app-步骤"><span class="icon icon-link"></span></a><red></red> 跳过打包成 <code>.app</code> 步骤:</h4>
<h4 style="text-align: left;font-weight: bold;" id="-跳过打包成-app-步骤"><a aria-hidden="true" tabindex="-1" href="#-跳过打包成-app-步骤"><span class="icon icon-link"></span></a><red></red> 跳过打包成 <code>.app</code> 步骤:</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="wrap-text"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> darwin/amd64 <span class="token parameter variable">-skippackage</span>
</span></code></pre>
<!--rehype:className=wrap-text-->
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="linux-打包"><a aria-hidden="true" tabindex="-1" href="#linux-打包"><span class="icon icon-link"></span></a>Linux 打包</h3><div class="wrap-body">
<h4 style="text-align: left;font-weight: bold;" id="-生成可执行文件"><a aria-hidden="true" tabindex="-1" href="#-生成可执行文件"><span class="icon icon-link"></span></a><red></red> 生成可执行文件</h4>
<h4 style="text-align: left;font-weight: bold;" id="-生成可执行文件"><a aria-hidden="true" tabindex="-1" href="#-生成可执行文件"><span class="icon icon-link"></span></a><red></red> 生成可执行文件</h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> linux/amd64
</span></code></pre>
<h4 style="text-align: left;font-weight: bold;" id="-打包成-deb"><a aria-hidden="true" tabindex="-1" href="#-打包成-deb"><span class="icon icon-link"></span></a><red></red> 打包成 <code>.deb</code></h4>
<h4 style="text-align: left;font-weight: bold;" id="-打包成-deb"><a aria-hidden="true" tabindex="-1" href="#-打包成-deb"><span class="icon icon-link"></span></a><red></red> 打包成 <code>.deb</code></h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> linux/amd64 <span class="token parameter variable">-deb</span>
</span></code></pre>
<h4 style="text-align: left;font-weight: bold;" id="-打包成-rpm"><a aria-hidden="true" tabindex="-1" href="#-打包成-rpm"><span class="icon icon-link"></span></a><red></red> 打包成 <code>.rpm</code></h4>
<h4 style="text-align: left;font-weight: bold;" id="-打包成-rpm"><a aria-hidden="true" tabindex="-1" href="#-打包成-rpm"><span class="icon icon-link"></span></a><red></red> 打包成 <code>.rpm</code></h4>
<!--rehype:style=text-align: left;font-weight: bold;-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ wails build <span class="token parameter variable">-platform</span> linux/amd64 <span class="token parameter variable">-rpm</span>
</span></code></pre>

View File

@@ -1776,7 +1776,7 @@
<li><a href="https://marketplace.visualstudio.com/items?itemName=jackiotyu.quick-reference">Quick Reference for VSCode</a><a href="https://github.com/jackiotyu/vscode-quick-reference">jackiotyu</a> 提供</li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 <a href="https://wangchujiang.com/#/app" target="_blank">Kenny Wang</a>. Updated on 2025/06/16 21:41:11</footer></footer><script src="data.js?v=1.8.3" defer></script><script src="js/fuse.min.js?v=1.8.3" defer></script><script src="js/main.js?v=1.8.3" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 <a href="https://wangchujiang.com/#/app" target="_blank">Kenny Wang</a>. Updated on 2025/06/16 21:42:50</footer></footer><script src="data.js?v=1.8.3" defer></script><script src="js/fuse.min.js?v=1.8.3" defer></script><script src="js/main.js?v=1.8.3" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
<path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>