fix: better handling of broken shortcuts

This commit is contained in:
2025-04-16 15:46:39 +00:00
parent 9cbdf2a9c8
commit d0ce3cddc7
3 changed files with 31 additions and 12 deletions

View File

@ -16,7 +16,7 @@ use appdata::{AppData, ToggleAction};
use model::misc::Game; use model::misc::Game;
use pkg::PkgKey; use pkg::PkgKey;
use pkg_store::Payload; use pkg_store::Payload;
use tauri::{AppHandle, Listener, Manager, RunEvent}; use tauri::{AppHandle, Emitter, Listener, Manager, RunEvent};
use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_cli::CliExt; use tauri_plugin_cli::CliExt;
use tokio::{fs, sync::Mutex, try_join}; use tokio::{fs, sync::Mutex, try_join};
@ -66,13 +66,8 @@ pub async fn run(_args: Vec<String>) {
log::debug!("{:?} {:?} {:?}", start_arg, game_arg, name_arg); log::debug!("{:?} {:?} {:?}", start_arg, game_arg, name_arg);
if start_arg.occurrences > 0 { if start_arg.occurrences > 0 {
start_immediately = true; start_immediately = true;
app_data.state.remain_open = false;
} else { } else {
tauri::WebviewWindowBuilder::new(app, "main", tauri::WebviewUrl::App("index.html".into())) open_window(apph.clone())?;
.title("STARTLINER")
.inner_size(900f64, 480f64)
.min_inner_size(900f64, 480f64)
.build()?;
start_immediately = false; start_immediately = false;
} }
@ -157,13 +152,20 @@ pub async fn run(_args: Vec<String>) {
{ {
let mut appd = mtx.lock().await; let mut appd = mtx.lock().await;
if let Err(e) = appd.pkgs.reload_all().await { if let Err(e) = appd.pkgs.reload_all().await {
log::error!("Unable to reload packages: {}", e); log::error!("unable to reload packages: {}", e);
apph.exit(1); apph.exit(1);
} }
} }
if let Err(e) = cmd::startline(apph.clone(), false).await { if let Err(e) = cmd::startline(apph.clone(), false).await {
log::error!("Unable to launch: {}", e); log::error!("unable to launch: {}", e);
apph.exit(1); _ = open_window(apph.clone());
// stupid but effective
std::thread::sleep(std::time::Duration::from_secs(3));
_ = apph.emit("launch-error", e.to_string());
} else {
let mut appd = mtx.lock().await;
appd.state.remain_open = false;
log::info!("started quietly");
} }
}); });
} else { } else {
@ -323,3 +325,14 @@ async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
Ok(()) Ok(())
} }
fn open_window(apph: AppHandle) -> anyhow::Result<()> {
let config = apph.config().clone();
tauri::WebviewWindowBuilder::new(&apph, "main", tauri::WebviewUrl::App("index.html".into()))
.title(format!("STARTLINER {}", config.version.unwrap_or_default()))
.inner_size(900f64, 480f64)
.min_inner_size(900f64, 480f64)
.build()?;
Ok(())
}

View File

@ -80,6 +80,12 @@ listen<{ message: string; header: string }>('invoke-error', (event) => {
errorMessage.value = event.payload.message; errorMessage.value = event.payload.message;
errorHeader.value = event.payload.header; errorHeader.value = event.payload.header;
}); });
listen<string>('launch-error', (event) => {
errorVisible.value = true;
errorMessage.value = event.payload;
errorHeader.value = 'Launch error';
});
</script> </script>
<template> <template>
@ -122,7 +128,7 @@ listen<{ message: string; header: string }>('invoke-error', (event) => {
{{ errorMessage }} {{ errorMessage }}
<Button <Button
class="m-auto" class="m-auto"
label="A sad state of affairs" label="OK"
@click="errorVisible = false" @click="errorVisible = false"
/> />
</div> </div>

View File

@ -106,7 +106,7 @@ const menuItems = [
command: async () => await startline(true, false), command: async () => await startline(true, false),
}, },
{ {
label: 'Create shortcut', label: 'Create desktop shortcut',
icon: 'pi pi-link', icon: 'pi pi-link',
command: createShortcut, command: createShortcut,
}, },