Compare commits
	
		
			2 Commits
		
	
	
		
			74cde73353
			...
			3c0f80ca02
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3c0f80ca02 | |||
| abb2ae69ff | 
							
								
								
									
										1628
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1628
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -8,11 +8,16 @@ 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" | ||||||
|  | axum = { version = "0.7.5", features = ["tokio", "http2"] } | ||||||
|  | futures = "0.3.30" | ||||||
|  | tower = "0.4.13" | ||||||
|  |  | ||||||
|  | [features] | ||||||
|  | # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! | ||||||
|  | custom-protocol = ["tauri/custom-protocol"] | ||||||
|   | |||||||
| @@ -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" |  | ||||||
|   ] |  | ||||||
| } |  | ||||||
| @@ -1,16 +1,99 @@ | |||||||
| // 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 futures::executor::block_on; | ||||||
|  |  | ||||||
|  | use axum::{ | ||||||
|  |     Router as AxumRouter, | ||||||
|  |     routing::get as AxumGetter, | ||||||
|  |     http::Request as AxumRequest, | ||||||
|  |     http::Response as AxumResponse, | ||||||
|  |     body::{ Body as AxumBody, to_bytes }, | ||||||
|  |     http::{StatusCode, Uri}, | ||||||
|  |     // extract::Path as AxumPath, | ||||||
|  |     // body::Bytes as AxumBytes, | ||||||
|  |     // response::IntoResponse, | ||||||
|  | }; | ||||||
|  | use tauri::http::ResponseBuilder; | ||||||
|  | use tower::{Service, ServiceExt}; | ||||||
|  |  | ||||||
| // 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 { | ||||||
|     format!("Hello, {}! You've been greeted from Rust!", name) |     format!("Hello, {}! You've been greeted from Rust!", name) | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | async fn test() -> &'static str { | ||||||
|  |     println!("test method called"); | ||||||
|  |     "Path: /test" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async fn root() -> &'static str { | ||||||
|  |     println!("root method called"); | ||||||
|  |     "Path: /" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async fn fallback(uri: Uri) -> (StatusCode, String) { | ||||||
|  |     println!("fallback method called on uri: {}", uri); | ||||||
|  |     (StatusCode::NOT_FOUND, format!("No route for {uri}")) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async fn build_response(router: &mut AxumRouter<()>, path: &str) -> AxumResponse<AxumBody> { | ||||||
|  |     let path = path.replace("clego://", "http://0.0.0.0/"); | ||||||
|  |     println!("build_response: path = {:?}", path); | ||||||
|  |  | ||||||
|  |     let request = AxumRequest::builder() | ||||||
|  |         .method("GET") | ||||||
|  |         .uri(path) | ||||||
|  |         .body(AxumBody::empty()) | ||||||
|  |         .unwrap(); | ||||||
|  |  | ||||||
|  |     println!("build_response: request = {:#?}", request); | ||||||
|  |  | ||||||
|  |     let response = router | ||||||
|  |         .as_service() | ||||||
|  |         .ready() | ||||||
|  |         .await | ||||||
|  |         .unwrap() | ||||||
|  |         .call(request) | ||||||
|  |         .await | ||||||
|  |         .unwrap(); | ||||||
|  |  | ||||||
|  |     println!("build_response: response = {:?}", response); | ||||||
|  |  | ||||||
|  |     response | ||||||
|  | } | ||||||
|  |  | ||||||
| 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", move |_app, request| { | ||||||
|  |             println!("------ register_uri_scheme_protocol ------"); | ||||||
|  |  | ||||||
|  |             let mut router: AxumRouter<_> = AxumRouter::new() | ||||||
|  |                 .route("/test/", AxumGetter(test)) | ||||||
|  |                 .route("/", AxumGetter(root)) | ||||||
|  |                 .fallback(fallback); | ||||||
|  |      | ||||||
|  |             let path = request.uri(); | ||||||
|  |             println!("register_uri_scheme_protocol: path = {:?}", path); | ||||||
|  |             let future = build_response(&mut router, path); | ||||||
|  |             let response: AxumResponse<AxumBody> = block_on(future); | ||||||
|  |             // extract body and headers from response | ||||||
|  |             let (parts, body) = response.into_parts(); | ||||||
|  |  | ||||||
|  |             println!("register_uri_scheme_protocol: body = {:?} ; parts {:?}", body, parts); | ||||||
|  |              | ||||||
|  |             // Convert body into a Vec<u8> | ||||||
|  |             let body_bytes = block_on(to_bytes(body, usize::MAX))?; | ||||||
|  |  | ||||||
|  |             // Build a tauri response from the axum response | ||||||
|  |             ResponseBuilder::new() | ||||||
|  |                 .status(parts.status.as_u16()) | ||||||
|  |                 .mimetype("text/html") | ||||||
|  |                 .body(body_bytes.to_vec()) | ||||||
|  |         }) | ||||||
|         .run(tauri::generate_context!()) |         .run(tauri::generate_context!()) | ||||||
|         .expect("error while running tauri application"); |         .expect("error while running tauri application"); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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" |  | ||||||
|     ] |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -36,6 +36,10 @@ | |||||||
|       </form> |       </form> | ||||||
|  |  | ||||||
|       <p id="greet-msg"></p> |       <p id="greet-msg"></p> | ||||||
|  |  | ||||||
|  |       <a href="clego://test">Test `clego://test` uri scheme handler</a> | ||||||
|  |       <a href="clego://walala">Test `clego://walala` uri scheme handler</a> | ||||||
|  |       <a href="https://clego.localhost/test">Test `https://clego.localhost/test` uri scheme handler</a> | ||||||
|     </div> |     </div> | ||||||
|   </body> |   </body> | ||||||
| </html> | </html> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user