feat: misc improvements

This commit is contained in:
2025-03-18 23:27:17 +00:00
parent fe1a32f31b
commit 1191cdd95c
15 changed files with 264 additions and 68 deletions

View File

@ -8,15 +8,19 @@ mod appdata;
mod modules;
mod profiles;
use std::sync::OnceLock;
use anyhow::anyhow;
use closure::closure;
use appdata::AppData;
use appdata::{AppData, ToggleAction};
use model::misc::Game;
use pkg::PkgKey;
use tauri::{AppHandle, Listener, Manager};
use pkg_store::Payload;
use tauri::{AppHandle, Listener, Manager, RunEvent};
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_cli::CliExt;
use tokio::{sync::Mutex, fs, try_join};
use tokio::{fs, sync::Mutex, try_join};
static EXIT_REQUESTED: OnceLock<()> = OnceLock::new();
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub async fn run(_args: Vec<String>) {
@ -30,7 +34,7 @@ pub async fn run(_args: Vec<String>) {
.unwrap_or_default()
);
tauri::Builder::default()
let tauri = tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
let _ = app
.get_webview_window("main")
@ -65,8 +69,8 @@ pub async fn run(_args: Vec<String>) {
} else {
tauri::WebviewWindowBuilder::new(app, "main", tauri::WebviewUrl::App("index.html".into()))
.title("STARTLINER")
.inner_size(600f64, 500f64)
.min_inner_size(600f64, 500f64)
.inner_size(640f64, 480f64)
.min_inner_size(640f64, 480f64)
.build()?;
start_immediately = false;
}
@ -102,17 +106,19 @@ pub async fn run(_args: Vec<String>) {
});
app.listen("download-end", closure!(clone apph, |ev| {
log::debug!("download-end triggered: {}", ev.payload());
let raw = ev.payload();
let key = PkgKey(raw[1..raw.len()-1].to_owned());
let apph = apph.clone();
tauri::async_runtime::spawn(async move {
let mutex = apph.state::<Mutex<AppData>>();
let mut appd = mutex.lock().await;
_ = appd.pkgs.install_package(&key, true, false).await;
log::debug!("download-end install {:?}", appd.pkgs.install_package(&key, true, false).await);
});
}));
app.listen("launch-end", closure!(clone apph, |_| {
log::debug!("launch-end triggered");
let apph = apph.clone();
tauri::async_runtime::spawn(async move {
let mutex = apph.state::<Mutex<AppData>>();
@ -123,6 +129,26 @@ pub async fn run(_args: Vec<String>) {
});
}));
app.listen("install-end-prelude", closure!(clone apph, |ev| {
log::debug!("install-end-prelude triggered: {}", ev.payload());
let payload = serde_json::from_str::<Payload>(ev.payload());
let apph = apph.clone();
if let Ok(payload) = payload {
tauri::async_runtime::spawn(async move {
let mutex = apph.state::<Mutex<AppData>>();
let mut appd = mutex.lock().await;
log::debug!(
"install-end-prelude toggle {:?}",
appd.toggle_package(payload.pkg.clone(), ToggleAction::EnableSelf)
);
use tauri::Emitter;
log::debug!("install-end {:?}", apph.emit("install-end", payload));
});
} else {
log::error!("install-end-prelude: invalid payload: {}", ev.payload());
}
}));
if start_immediately == true {
let apph = apph.clone();
tauri::async_runtime::spawn(async move {
@ -163,14 +189,40 @@ pub async fn run(_args: Vec<String>) {
cmd::duplicate_profile,
cmd::delete_profile,
cmd::get_current_profile,
cmd::sync_current_profile,
cmd::save_current_profile,
cmd::list_displays,
cmd::list_platform_capabilities,
cmd::list_directories,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
.build(tauri::generate_context!())
.expect("error while building tauri application");
tauri.run(move |app, event| {
match event {
RunEvent::ExitRequested { api, code, .. } => {
log::debug!("exit request {:?} {:?}", api, code);
if EXIT_REQUESTED.get().is_none() {
_= EXIT_REQUESTED.set(());
api.prevent_exit();
let app = app.clone();
tauri::async_runtime::spawn(async move {
let mutex = app.state::<Mutex<AppData>>();
let appd = mutex.lock().await;
if let Some(p) = &appd.profile {
log::debug!("save: {:?}", p.save());
app.exit(0);
}
});
}
},
RunEvent::Exit => {
log::info!("exit");
}
_ => {}
}
});
}
fn deep_link(app: AppHandle, args: Vec<String>) {