forked from akanyan/STARTLINER
feat: new config format
This commit is contained in:
@ -2,21 +2,18 @@ mod cmd;
|
||||
mod model;
|
||||
mod pkg;
|
||||
mod pkg_store;
|
||||
mod profile;
|
||||
mod util;
|
||||
mod start;
|
||||
mod liner;
|
||||
mod download_handler;
|
||||
mod appdata;
|
||||
mod display;
|
||||
mod modules;
|
||||
mod profiles;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use closure::closure;
|
||||
use appdata::AppData;
|
||||
use model::misc::Game;
|
||||
use pkg::PkgKey;
|
||||
use profile::Profile;
|
||||
use tauri::{Listener, Manager};
|
||||
use tauri::{AppHandle, Listener, Manager};
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use tauri_plugin_cli::CliExt;
|
||||
use tokio::{sync::Mutex, fs, try_join};
|
||||
@ -40,28 +37,7 @@ pub async fn run(_args: Vec<String>) {
|
||||
.expect("No main window")
|
||||
.set_focus();
|
||||
if args.len() == 2 {
|
||||
// Todo deindent this chimera
|
||||
let url = &args[1];
|
||||
if &url[..13] == "rainycolor://" {
|
||||
log::info!("Deep link: {}", url);
|
||||
let regex = regex::Regex::new(
|
||||
r"rainycolor://v1/install/rainy\.patafour\.zip/([^/]+)/([^/]+)/[0-9]+\.[0-9]+\.[0-9]+/"
|
||||
).expect("Invalid regex");
|
||||
if let Some(caps) = regex.captures(url) {
|
||||
if caps.len() == 3 {
|
||||
let apph = app.clone();
|
||||
let key = PkgKey(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str()));
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mutex = apph.state::<Mutex<AppData>>();
|
||||
let mut appd = mutex.lock().await;
|
||||
_ = appd.pkgs.fetch_listings().await;
|
||||
if let Err(e) = appd.pkgs.install_package(&key, true, true).await {
|
||||
log::warn!("Fail: {}", e.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
deep_link(app.clone(), args);
|
||||
}
|
||||
}))
|
||||
.plugin(tauri_plugin_cli::init())
|
||||
@ -85,7 +61,7 @@ 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.remain_open = false;
|
||||
app_data.state.remain_open = false;
|
||||
} else {
|
||||
tauri::WebviewWindowBuilder::new(app, "main", tauri::WebviewUrl::App("index.html".into()))
|
||||
.title("STARTLINER")
|
||||
@ -125,7 +101,6 @@ pub async fn run(_args: Vec<String>) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
app.listen("download-end", closure!(clone apph, |ev| {
|
||||
let raw = ev.payload();
|
||||
let key = PkgKey(raw[1..raw.len()-1].to_owned());
|
||||
@ -142,27 +117,24 @@ pub async fn run(_args: Vec<String>) {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mutex = apph.state::<Mutex<AppData>>();
|
||||
let appd = mutex.lock().await;
|
||||
if !appd.remain_open {
|
||||
if !appd.state.remain_open {
|
||||
apph.exit(0);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
if start_immediately == true {
|
||||
let apph_clone = apph.clone();
|
||||
tauri::async_runtime::spawn(async {
|
||||
let apph_clone_clone = apph_clone.clone();
|
||||
{
|
||||
let mtx = apph_clone.state::<Mutex<AppData>>();
|
||||
let mut appd = mtx.lock().await;
|
||||
if let Err(e) = appd.pkgs.reload_all().await {
|
||||
log::error!("Unable to reload packages: {}", e);
|
||||
apph_clone.exit(1);
|
||||
}
|
||||
let apph = apph.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mtx = apph.state::<Mutex<AppData>>();
|
||||
let mut appd = mtx.lock().await;
|
||||
if let Err(e) = appd.pkgs.reload_all().await {
|
||||
log::error!("Unable to reload packages: {}", e);
|
||||
apph.exit(1);
|
||||
}
|
||||
if let Err(e) = cmd::startline(apph_clone).await {
|
||||
if let Err(e) = cmd::startline(apph.clone()).await {
|
||||
log::error!("Unable to launch: {}", e);
|
||||
apph_clone_clone.exit(1);
|
||||
apph.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -181,9 +153,9 @@ pub async fn run(_args: Vec<String>) {
|
||||
cmd::list_profiles,
|
||||
cmd::init_profile,
|
||||
cmd::load_profile,
|
||||
cmd::rename_profile,
|
||||
cmd::get_current_profile,
|
||||
cmd::save_current_profile,
|
||||
cmd::set_cfg,
|
||||
|
||||
cmd::startline,
|
||||
cmd::kill,
|
||||
@ -195,3 +167,31 @@ pub async fn run(_args: Vec<String>) {
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
fn deep_link(app: AppHandle, args: Vec<String>) {
|
||||
let url = &args[1];
|
||||
let proto = "rainycolor://";
|
||||
if &url[..proto.len()] == proto {
|
||||
log::info!("Deep link: {}", url);
|
||||
|
||||
let regex = regex::Regex::new(
|
||||
r"rainycolor://v1/install/rainy\.patafour\.zip/([^/]+)/([^/]+)/[0-9]+\.[0-9]+\.[0-9]+/"
|
||||
).expect("Invalid regex");
|
||||
|
||||
if let Some(caps) = regex.captures(url) {
|
||||
if caps.len() == 3 {
|
||||
let app = app.clone();
|
||||
let key = PkgKey(format!("{}-{}", caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str()));
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mutex = app.state::<Mutex<AppData>>();
|
||||
let mut appd = mutex.lock().await;
|
||||
if let Err(e) = appd.pkgs.fetch_listings().await {
|
||||
log::warn!("Deep link fetch failed: {:?}", e);
|
||||
} else if let Err(e) = appd.pkgs.install_package(&key, true, true).await {
|
||||
log::warn!("Deep link installation failed: {}", e.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user