因為想要做一個符合自己用途的計時器,今天在研究 Tauri 官方網站的教學 (由於對於安裝設定我常常安裝到錯誤發生,所以記錄一下安裝的過程~)
Build smaller, faster, and more secure desktop applications with a web frontend | Tauri Apps
https://tauri.app/
https://tauri.app/v1/guides/getting-started/prerequisites
跟著步驟安裝
先從最簡單的 creat-tauri-app 中,選擇使用的套件工具的指令來安裝,我使用的是 yarn
,且打算使用HTML + CSS + JavaScript 來製作計時器。
yarn create tauri-app
C:\Users\anki6\Documents>yarn create tauri-app
yarn create v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "create-tauri-app@3.7.3" with binaries:
- create-tauri-app
# 這邊會需要輸入專案的名稱(這邊是flowtime)、 前端要使用的語言、套件管理工具 等
✔ Project name · flowtime
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm)
# 選項
# TypeScript / JavaScript (pnpm, yarn, npm)
# Rust
✔ Choose your package manager · yarn
# 選項
# pnpm
# yarn
# npm
✔ Choose your UI template · Vanilla
# 選項
# Vanilla
# Vue
# Svelte
# React
# Solid
# Angular
# Preact
✔ Choose your UI flavor · JavaScript
# 選項
# TypeScript
# JavaScript
Template created! To get started run:
cd flowtime
yarn
yarn tauri dev
Done in 19.44s.
cd flowtime
, yarn
, yarn tauri dev
指令:# cd flowtime
C:\Users\anki6\Documents>cd flowtime
C:\Users\anki6\Documents\flowtime>yarn
yarn install v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 5.55s.
#------ yarn tauri dev -----
C:\Users\anki6\Documents\flowtime>yarn tauri dev
$ tauri dev
Info Watching C:\Users\anki6\Documents\flowtime\src-tauri for changes...
Updating crates.io index
Compiling proc-macro2 v1.0.67
Compiling unicode-ident v1.0.12
Compiling cfg-if v1.0.0
Compiling serde v1.0.188
Compiling syn v1.0.109
Compiling autocfg v1.1.0
Compiling ppv-lite86 v0.2.17
Compiling siphasher v0.3.11
Compiling getrandom v0.1.16
Compiling windows_x86_64_msvc v0.48.5
Compiling getrandom v0.2.10
...
...
...
Compiling encoding_rs v0.8.33
Compiling state v0.5.3
Compiling webview2-com v0.19.1
Finished dev [unoptimized + debuginfo] target(s) in 5m 01s
Done in 378.60s.
第一次輸入 yarn tauri dev
時,載入到一半,就出現錯誤:
一開始沒注意到防毒軟體的視窗,以為是權限問題,所以重新用管理員權限開啟命令列提示字元(或PowerShell),結果還是一樣,後來才注意到是防毒軟體阻擋其載入的套件導致出錯,所以重新載入當下有把防毒軟體關掉,載入成功出現Welcome to Tauri視窗後關閉,開啟防毒軟體後,再重新 yarn tauri dev
就可以了。
用yarn create tauri-app
另外再建立專案時,輸入專案的名稱testConvention
,後面建置成功後會出現警告訊息:
warning: crate `testConvention` should have a snake case name
|
= help: convert the identifier to snake case: `test_convention`
= note: `#[warn(non_snake_case)]` on by default
warning: `testConvention` (bin "testConvention") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 2m 22s
Done in 945.57s.
這是Rust 編譯時出現的警告訊息,說明testConvention
命名不符合Rust慣例的 蛇型命名snake case,並建議將 crate 名稱 testConvention
改成 test_convention
。
從Rust 程式語言文件中得知 crate 是在 Cargo.toml
中定義的:
Packages and Crates - The Rust Programming Language (rust-lang.org)
testConvention
下的 src-tauri/Cargo.toml
中修改 package的 name="testConvention"
為 name="test_convention"
。testConvention
之下輸入 yarn tauri dev
,警告訊息就會消失了。關於命名慣例的討論