chore: setup tauri

This commit is contained in:
reya
2024-07-23 13:33:48 +07:00
parent 8ae1368419
commit 462837565e
10 changed files with 1931 additions and 24 deletions

View File

@@ -1,16 +1,66 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// 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)
use border::WebviewWindowExt as WebviewWindowExtAlt;
use commands::account::{get_accounts, get_profile, login};
use nostr_sdk::prelude::*;
use serde::Serialize;
use std::{fs, sync::Mutex};
use tauri::Manager;
use tauri_plugin_decorum::WebviewWindowExt;
mod commands;
#[derive(Serialize)]
pub struct Nostr {
#[serde(skip_serializing)]
client: Client,
contact_list: Mutex<Vec<Contact>>,
}
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri::Builder::default()
.setup(|app| {
#[cfg(not(target_os = "linux"))]
let main_window = app.get_webview_window("main").unwrap();
// Set custom decoration
main_window.create_overlay_titlebar().unwrap();
// Restore native border
#[cfg(target_os = "macos")]
main_window.add_border(None);
tauri::async_runtime::block_on(async move {
// Create data folder if not exist
let dir = app.path().config_dir().expect("Config Directory not found.");
let _ = fs::create_dir_all(dir.join("Coop/"));
// Setup database
let database = SQLiteDatabase::open(dir.join("Coop/coop.db")).await;
// Setup nostr client
let client = match database {
Ok(db) => ClientBuilder::default().database(db).build(),
Err(_) => ClientBuilder::default().build(),
};
// Add bootstrap relay
let _ = client.add_relay("wss://relay.damus.io/").await;
let _ = client.add_relay("wss://relay.nostr.net/").await;
// Connect
client.connect().await;
// Create global state
app.handle().manage(Nostr { client, contact_list: Mutex::new(vec![]) })
});
Ok(())
})
.plugin(tauri_plugin_decorum::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![login, get_accounts, get_profile])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}