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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies] [build-dependencies]
tauri-build = { version = "2.0.0-beta", features = [] } tauri-build = { version = "1", features = [] }
[dependencies] [dependencies]
tauri = { version = "2.0.0-beta", features = [] } tauri = { version = "1", features = ["shell-open"] }
tauri-plugin-shell = "2.0.0-beta"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" 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!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![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 // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command] #[tauri::command]
fn greet(name: &str) -> String { fn greet(name: &str) -> String {
@ -9,8 +11,17 @@ fn greet(name: &str) -> String {
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet]) .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!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

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

View File

@ -36,6 +36,9 @@
</form> </form>
<p id="greet-msg"></p> <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> </div>
</body> </body>
</html> </html>