codecamp

Tauri 将Tauri添加到Cargo项目中

接下来,我们将添加必要的项,将我们的Cargo项目转换为Tauri项目。首先,我们需要在Cargo清单(Cargo.toml)中添加依赖项,以便Cargo在构建时知道拉取这些依赖项。

Cargo.toml​:

[package]
name = "hello-tauri-webdriver"
version = "0.1.0"
edition = "2021"
rust-version = "1.56"

# Needed to set up some things for Tauri at build time
[build-dependencies]
tauri-build = "1"

# The actual Tauri dependency, along with `custom-protocol` to serve the pages.
[dependencies]
tauri = { version = "1", features = ["custom-protocol"] }

# Make --release build a binary that is small (opt-level = "s") and fast (lto = true).
# This is completely optional, but shows that testing the application as close to the
# typical release settings is possible. Note: this will slow down compilation.
[profile.release]
incremental = false
codegen-units = 1
panic = "abort"
opt-level = "s"
lto = true

正如你可能已经注意到的,我们添加了一个[build-dependency]。为了使用构建依赖项,我们必须在构建脚本中使用它。我们将在`build.rs`中创建一个构建脚本。

build.rs​:

fn main() {
// Only watch the `dist/` directory for recompiling, preventing unnecessary
// changes when we change files in other project subdirectories.
println!("cargo:rerun-if-changed=dist");

// Run the Tauri build-time helpers
tauri_build::build()
}

现在,我们的Cargo项目已经知道如何使用所有这些设置来引入和构建Tauri的依赖项。让我们通过在实际项目代码中设置Tauri来完成这个极简示例的Tauri应用程序。我们将编辑src/main.rs文件,以添加Tauri功能。

src/main.rs​:

fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("unable to run Tauri application");
}

相当简单,对吧?


Tauri 创建一个极简的前端
Tauri 配置
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Tauri 指南

Tauri 特性

Tauri 插件

Tauri 应用程序接口

Tauri JavaScript/TypeScript

Tauri 命令行界面

Tauri 进程

Tauri 参考

Tauri WebView 版本

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }