feature: make register_uri_scheme_protocol works on tauri v1

This commit is contained in:
Florian Briand 2024-07-16 12:19:38 +02:00
parent db285c8aea
commit d07221975b
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B
6 changed files with 546 additions and 1147 deletions

1608
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,11 +8,13 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "2.0.0-beta", features = [] }
tauri-build = { version = "1", features = [] }
[dependencies]
tauri = { version = "2.0.0-beta", features = [] }
tauri-plugin-shell = "2.0.0-beta"
tauri = { version = "1", features = ["shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

View File

@ -1,17 +0,0 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"image:default",
"resources:default",
"menu:default",
"tray:default",
"shell:allow-open"
]
}

View File

@ -1,6 +1,8 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::http::ResponseBuilder;
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
@ -9,8 +11,17 @@ fn greet(name: &str) -> String {
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.register_uri_scheme_protocol("clego", |_app, request| {
let path = request.uri();
let body = format!("<html><body>Hello from Rust! Path: {}</body></html>", path);
println!("body: {}", body);
let body_bytes: Vec<u8> = body.into_bytes();
ResponseBuilder::new()
.body(body_bytes)
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -1,12 +1,21 @@
{
"productName": "tauri",
"version": "0.0.0",
"identifier": "org.p4pillon.krys4lide",
"build": {
"frontendDist": "../webapp"
"devPath": "../webapp",
"distDir": "../webapp",
"withGlobalTauri": true
},
"package": {
"productName": "tauri",
"version": "0.0.0"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
}
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "tauri",
@ -16,11 +25,11 @@
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "org.p4pillon.krys4lide",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
@ -29,4 +38,5 @@
"icons/icon.ico"
]
}
}
}

View File

@ -36,6 +36,9 @@
</form>
<p id="greet-msg"></p>
<a href="clego://test/scheme/handler">Test `clego://` uri scheme handler</a>
<a href="https://clego.localhost/test/scheme/handler">Test `https://clego.localhost` uri scheme handler</a>
</div>
</body>
</html>