Wire Tauri AppImage to native keyring
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::path::PathBuf;
|
||||
use trixy_native::{clear_session, default_settings_path, load_session, store_session, Settings};
|
||||
|
||||
fn error_message(error: std::io::Error) -> String {
|
||||
error.to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_client_settings() -> Result<Settings, String> {
|
||||
let path = default_settings_path();
|
||||
if !path.exists() {
|
||||
return Ok(Settings {
|
||||
server_address: "http://127.0.0.1:8787".to_string(),
|
||||
username: String::new(),
|
||||
});
|
||||
}
|
||||
Settings::load(path).map_err(error_message)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_client_settings(settings: Settings) -> Result<(), String> {
|
||||
if settings.server_address.trim().is_empty() || settings.username.trim().is_empty() {
|
||||
return Err("Server address and username are required.".to_string());
|
||||
}
|
||||
Settings::save(&settings, default_settings_path()).map_err(error_message)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_server_session(settings: Settings) -> Result<Option<String>, String> {
|
||||
load_session(&settings).map_err(error_message)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn store_server_session(settings: Settings, session: String) -> Result<(), String> {
|
||||
store_session(&settings, &session).map_err(error_message)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn clear_server_session(settings: Settings) -> Result<(), String> {
|
||||
clear_session(&settings).map_err(error_message)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn client_settings_path() -> String {
|
||||
PathBuf::from(default_settings_path())
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
load_client_settings,
|
||||
save_client_settings,
|
||||
load_server_session,
|
||||
store_server_session,
|
||||
clear_server_session,
|
||||
client_settings_path
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running Trixie client");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
trixy_linux_client_lib::run();
|
||||
}
|
||||
Reference in New Issue
Block a user