iT邦幫忙

2023 iThome 鐵人賽

DAY 6
0
自我挑戰組

我的日常學習雜記與筆記整理系列 第 6

Day - 6 Tauri 安裝紀錄 for Windows & 遇到的問題

  • 分享至 

  • xImage
  •  

因為想要做一個符合自己用途的計時器,今天在研究 Tauri 官方網站的教學 (由於對於安裝設定我常常安裝到錯誤發生,所以記錄一下安裝的過程~)

Tauri for Windows

Build smaller, faster, and more secure desktop applications with a web frontend | Tauri Apps
https://tauri.app/

Prerequisites | 開發環境設置

https://tauri.app/v1/guides/getting-started/prerequisites
跟著步驟安裝

  1. 安裝 working development environment.
  2. 安裝 WebView2
  3. 安裝 Rust

Quick Start

先從最簡單的 creat-tauri-app 中,選擇使用的套件工具的指令來安裝,我使用的是 yarn,且打算使用HTML + CSS + JavaScript 來製作計時器。

  1. 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.
  1. 依照上面get started run 依序輸入: 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.

成功建置會出現的畫面

https://ithelp.ithome.com.tw/upload/images/20230921/201403774PKtfb7BsY.jpg

Error訊息

第一次輸入 yarn tauri dev時,載入到一半,就出現錯誤:
https://ithelp.ithome.com.tw/upload/images/20230921/20140377y7OP8Ekd2V.jpg

一開始沒注意到防毒軟體的視窗,以為是權限問題,所以重新用管理員權限開啟命令列提示字元(或PowerShell),結果還是一樣,後來才注意到是防毒軟體阻擋其載入的套件導致出錯,所以重新載入當下有把防毒軟體關掉,載入成功出現Welcome to Tauri視窗後關閉,開啟防毒軟體後,再重新 yarn tauri dev就可以了。
https://ithelp.ithome.com.tw/upload/images/20230921/20140377rxrfMw9ahl.jpg

Warning 訊息

yarn create tauri-app另外再建立專案時,輸入專案的名稱testConvention,後面建置成功後會出現警告訊息:
https://ithelp.ithome.com.tw/upload/images/20230922/20140377rim9EzZt92.jpg


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)

  1. 所以依照建議,在testConvention 下的 src-tauri/Cargo.toml 中修改 package的 name="testConvention"name="test_convention"

https://ithelp.ithome.com.tw/upload/images/20230922/20140377IgRlHkfRax.jpg

https://ithelp.ithome.com.tw/upload/images/20230922/20140377CaCEGkmFLr.jpg

  1. 重新在testConvention之下輸入 yarn tauri dev,警告訊息就會消失了。

https://ithelp.ithome.com.tw/upload/images/20230922/20140377ziAhkqRH6j.jpg

參考資源:

關於命名慣例的討論

  1. Package and crate naming convention - help - The Rust Programming Language Forum (rust-lang.org)
  2. Naming - Rust API Guidelines (rust-lang.github.io)
  3. rfcs/text/0430-finalizing-naming-conventions.md at master · rust-lang/rfcs · GitHub

上一篇
Day - 5 常用指令整理
下一篇
Day - 7 Tauri 初步了解專案的設定(一)
系列文
我的日常學習雜記與筆記整理30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言