初始化,可用。

This commit is contained in:
cheney
2026-07-07 17:53:20 +08:00
commit 73b9e679e6
26 changed files with 8325 additions and 0 deletions
+5971
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
[package]
name = "tauri-demo"
version = "0.1.0"
description = "Tauri Android 能力演示 App"
edition = "2021"
rust-version = "1.77.2"
[lib]
# 移动端要求以库形式构建,名称需与 tauri.conf 中保持一致
name = "tauri_demo_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-os = "2"
tauri-plugin-dialog = "2"
tauri-plugin-notification = "2"
tauri-plugin-fs = "2"
tauri-plugin-clipboard-manager = "2"
tauri-plugin-http = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+4
View File
@@ -0,0 +1,4 @@
// Tauri 构建脚本:在编译期生成必要的上下文与元数据
fn main() {
tauri_build::build()
}
+21
View File
@@ -0,0 +1,21 @@
{
"$schema": "../gen/schemas/mobile-schema.json",
"identifier": "default",
"description": "演示 App 所需的能力集合",
"windows": ["main"],
"webviews": ["main"],
"permissions": [
"core:default",
"os:default",
"dialog:default",
"notification:default",
"clipboard-manager:allow-read-text",
"clipboard-manager:allow-write-text",
"fs:allow-app-read-recursive",
"fs:allow-app-write-recursive",
{
"identifier": "http:default",
"allow": [{ "url": "https://*" }]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

+59
View File
@@ -0,0 +1,59 @@
use serde::Serialize;
/// 系统信息返回结构,序列化为 JSON 传回前端
#[derive(Serialize)]
struct SysInfo {
/// 目标操作系统(如 android、windows)
os: String,
/// 目标 CPU 架构(如 aarch64、x86_64)
arch: String,
/// 应用版本号
app_version: String,
}
/// 向前端返回一句问候语
///
/// # 参数
/// - `name`: 前端传入的名字
///
/// # 返回
/// 拼接后的中文问候字符串
#[tauri::command]
fn greet(name: &str) -> String {
format!("你好,{}!这条消息来自 Rust 后端 👋", name)
}
/// 汇总当前运行环境的系统信息
///
/// # 返回
/// 格式化后的 JSON 字符串(包含 os、arch、app_version)
///
/// # 注意
/// os 与 arch 取自编译期常量,反映的是构建目标平台。
#[tauri::command]
fn system_summary() -> String {
let info = SysInfo {
os: std::env::consts::OS.to_string(),
arch: std::env::consts::ARCH.to_string(),
app_version: env!("CARGO_PKG_VERSION").to_string(),
};
serde_json::to_string_pretty(&info).unwrap_or_else(|_| "{}".to_string())
}
/// 应用运行入口:注册插件与命令并启动 Tauri
///
/// # 注意
/// 使用 `#[cfg_attr(mobile, ...)]` 标记,移动端会由平台生成的入口调用此函数。
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_http::init())
.invoke_handler(tauri::generate_handler![greet, system_summary])
.run(tauri::generate_context!())
.expect("启动 Tauri 应用失败");
}
+7
View File
@@ -0,0 +1,7 @@
// 桌面端可执行文件入口:直接调用库中的 run 函数
// 移动端不会使用此文件,而是通过生成的原生工程调用 lib 中的入口。
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri_demo_lib::run()
}
+36
View File
@@ -0,0 +1,36 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "TauriDemo",
"version": "0.1.0",
"identifier": "com.tauridemo.app",
"build": {
"frontendDist": "../dist",
"devUrl": "http://localhost:1420",
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build"
},
"app": {
"windows": [
{
"title": "Tauri 能力演示",
"width": 420,
"height": 780,
"resizable": true
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.png",
"icons/icon.ico"
]
}
}
Binary file not shown.