// 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 {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

fn main() {
    tauri::Builder::default()
        .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");
}
