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 pkg::PkgKey;
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_cli::CliExt;
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);
if start_arg.occurrences > 0 {
start_immediately = true;
app_data.state.remain_open = false;
} else {
tauri::WebviewWindowBuilder::new(app, "main", tauri::WebviewUrl::App("index.html".into()))
.title("STARTLINER")
.inner_size(900f64, 480f64)
.min_inner_size(900f64, 480f64)
.build()?;
open_window(apph.clone())?;
start_immediately = false;
}
@ -157,13 +152,20 @@ pub async fn run(_args: Vec<String>) {
{
let mut appd = mtx.lock().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);
}
}
if let Err(e) = cmd::startline(apph.clone(), false).await {
log::error!("Unable to launch: {}", e);
apph.exit(1);
log::error!("unable to launch: {}", e);
_ = 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 {
@ -321,5 +323,16 @@ async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
log::info!("ending auto-update check");
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;
errorHeader.value = event.payload.header;
});
listen<string>('launch-error', (event) => {
errorVisible.value = true;
errorMessage.value = event.payload;
errorHeader.value = 'Launch error';
});
</script>
<template>
@ -122,7 +128,7 @@ listen<{ message: string; header: string }>('invoke-error', (event) => {
{{ errorMessage }}
<Button
class="m-auto"
label="A sad state of affairs"
label="OK"
@click="errorVisible = false"
/>
</div>

View File

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