fix: All Rust-side errors and added TODOs where needed
This commit is contained in:
parent
f60bccf13b
commit
4588be4f24
6 changed files with 137 additions and 132 deletions
|
|
@ -63,22 +63,23 @@ impl fmt::Display for ImportType {
|
|||
}
|
||||
|
||||
pub async fn import_instances(import: ImportType, path: PathBuf) -> crate::Result<Vec<String>> {
|
||||
// TODO(pauline)(instance_import): Fix MultiMC based launcher import
|
||||
let instances_path = match import {
|
||||
ImportType::GDLauncher | ImportType::ATLauncher => "instances".to_string(),
|
||||
ImportType::Curseforge => "Instances".to_string(),
|
||||
ImportType::MultiMC => multibased::get_instances_path(path.clone().join("multimc.cfg"))
|
||||
.await
|
||||
.unwrap_or_else(|| "instances".to_string()),
|
||||
ImportType::PrismLauncher => {
|
||||
multibased::get_instances_path(path.clone().join("prismlauncher.cfg"))
|
||||
.await
|
||||
.unwrap_or_else(|| "instances".to_string())
|
||||
}
|
||||
// ImportType::MultiMC => multibased::get_instances_path(path.clone().join("multimc.cfg"))
|
||||
// .await
|
||||
// .unwrap_or_else(|| "instances".to_string()),
|
||||
// ImportType::PrismLauncher => {
|
||||
// multibased::get_instances_path(path.clone().join("prismlauncher.cfg"))
|
||||
// .await
|
||||
// .unwrap_or_else(|| "instances".to_string())
|
||||
// }
|
||||
ImportType::Modrinth => "profiles".to_string(),
|
||||
ImportType::TLauncher => "instances".to_string(),
|
||||
ImportType::Technic => "instances".to_string(),
|
||||
ImportType::FTBLauncher => "instances".to_string(),
|
||||
ImportType::Unknown | ImportType::Unknown => {
|
||||
_ | ImportType::Unknown => {
|
||||
return Err(anyhow::anyhow!("launcher type unknown, cant import").into())
|
||||
}
|
||||
};
|
||||
|
|
@ -118,72 +119,73 @@ pub async fn import_instance(
|
|||
) -> crate::Result<()> {
|
||||
tracing::debug!("importing instance from {instance_path}");
|
||||
|
||||
let result = match import {
|
||||
ImportType::MultiMC | ImportType::PrismLauncher => {
|
||||
multibased::import(path, instance_path, cluster_path.clone()).await
|
||||
}
|
||||
ImportType::ATLauncher => {
|
||||
atlauncher::import(path, instance_path, cluster_path.clone()).await
|
||||
}
|
||||
ImportType::GDLauncher => {
|
||||
gdlauncher::import(
|
||||
path.join("instances").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::Curseforge => {
|
||||
curseforge::import(
|
||||
path.join("Instances").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::Modrinth => {
|
||||
modrinth::import(
|
||||
path.join("profiles").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::TLauncher => {
|
||||
tlauncher::import(
|
||||
path.join("instances").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::Technic => {
|
||||
technic::import(
|
||||
path.join("instances").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::FTBLauncher => {
|
||||
ftb::import(
|
||||
path.join("instances").join(instance_path),
|
||||
cluster_path.clone(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ImportType::Unknown => {
|
||||
return Err(anyhow::anyhow!("unknown launcher type").into());
|
||||
}
|
||||
};
|
||||
// TODO(pauline)(instance_import): Finish this
|
||||
// let result = match import {
|
||||
// ImportType::MultiMC | ImportType::PrismLauncher => {
|
||||
// multibased::import(path, instance_path, cluster_path.clone()).await
|
||||
// }
|
||||
// ImportType::ATLauncher => {
|
||||
// atlauncher::import(path, instance_path, cluster_path.clone()).await
|
||||
// }
|
||||
// ImportType::GDLauncher => {
|
||||
// gdlauncher::import(
|
||||
// path.join("instances").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::Curseforge => {
|
||||
// curseforge::import(
|
||||
// path.join("Instances").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::Modrinth => {
|
||||
// modrinth::import(
|
||||
// path.join("profiles").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::TLauncher => {
|
||||
// tlauncher::import(
|
||||
// path.join("instances").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::Technic => {
|
||||
// technic::import(
|
||||
// path.join("instances").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::FTBLauncher => {
|
||||
// ftb::import(
|
||||
// path.join("instances").join(instance_path),
|
||||
// cluster_path.clone(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
// ImportType::Unknown => {
|
||||
// return Err(anyhow::anyhow!("unknown launcher type").into());
|
||||
// }
|
||||
// };
|
||||
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
tracing::warn!("failed to import modpack: {:?}", e);
|
||||
let _ = crate::api::cluster::remove(&cluster_path).await;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
// match result {
|
||||
// Ok(_) => {}
|
||||
// Err(e) => {
|
||||
// tracing::warn!("failed to import modpack: {:?}", e);
|
||||
// let _ = crate::api::cluster::remove(&cluster_path).await;
|
||||
// return Err(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
tokio::task::spawn(Clusters::update_versions());
|
||||
// tokio::task::spawn(Clusters::update_versions());
|
||||
|
||||
tracing::debug!("completed import of instance.");
|
||||
// tracing::debug!("completed import of instance.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -214,17 +216,19 @@ pub fn default_launcher_path(r#type: ImportType) -> Option<PathBuf> {
|
|||
#[tracing::instrument]
|
||||
#[onelauncher_debug::debugger]
|
||||
pub async fn is_valid_instance(instance_path: PathBuf, r#type: ImportType) -> bool {
|
||||
match r#type {
|
||||
ImportType::MultiMC | ImportType::PrismLauncher => multibased::is_valid(insance_path).await,
|
||||
ImportType::ATLauncher => atlauncher::is_valid(instance_path).await,
|
||||
ImportType::GDLauncher => gdlauncher::is_valid(instance_path).await,
|
||||
ImportType::Curseforge => curseforge::is_valid(instance_path).await,
|
||||
ImportType::Modrinth => modrinth::is_valid(instance_path).await,
|
||||
ImportType::TLauncher => tlauncher::is_valid(instance_path).await,
|
||||
ImportType::FTBLauncher => ftb::is_valid(instance_path).await,
|
||||
ImportType::Technic => technic::is_valid(instance_path).await,
|
||||
ImportType::Unknown => false,
|
||||
}
|
||||
false
|
||||
// TODO(pauline)(instance_import): Finish this
|
||||
// match r#type {
|
||||
// ImportType::MultiMC | ImportType::PrismLauncher => multibased::is_valid(insance_path).await,
|
||||
// ImportType::ATLauncher => atlauncher::is_valid(instance_path).await,
|
||||
// ImportType::GDLauncher => gdlauncher::is_valid(instance_path).await,
|
||||
// ImportType::Curseforge => curseforge::is_valid(instance_path).await,
|
||||
// ImportType::Modrinth => modrinth::is_valid(instance_path).await,
|
||||
// ImportType::TLauncher => tlauncher::is_valid(instance_path).await,
|
||||
// ImportType::FTBLauncher => ftb::is_valid(instance_path).await,
|
||||
// ImportType::Technic => technic::is_valid(instance_path).await,
|
||||
// ImportType::Unknown => false,
|
||||
// }
|
||||
}
|
||||
|
||||
/// caches an image file
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ impl ClusterPath {
|
|||
self.0.to_str().ok_or(anyhow::anyhow!(
|
||||
"invalid file path string {}!",
|
||||
self.0.clone().to_string_lossy()
|
||||
));
|
||||
))?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,11 +58,12 @@ pub async fn generate_context(
|
|||
}
|
||||
|
||||
let mut result = HashMap::new();
|
||||
let mut stream = tokio_stream::iter(result_packages);
|
||||
while let Some((k, v)) = stream.next().await {
|
||||
let k = PackagePath::from_path(k).await?;
|
||||
result.insert(k, v);
|
||||
}
|
||||
// TODO(pauline): Finish this
|
||||
// let mut stream = tokio_stream::iter(result_packages);
|
||||
// while let Some((k, v)) = stream.next().await {
|
||||
// let k = PackagePath::from_path(k).await?;
|
||||
// result.insert(k, v);
|
||||
// }
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ fn sync_write(
|
|||
let tmp_path = tempfile.into_temp_path();
|
||||
let path = path.as_ref();
|
||||
// this is a sorta dangerous call but shouldnt matter because of async
|
||||
tmp_path.persist(path);
|
||||
tmp_path.persist(path)?;
|
||||
std::io::Result::Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
use onelauncher::game::client_manager::ClientManager;
|
||||
use onelauncher::AppState;
|
||||
use onelauncher::State;
|
||||
use serde::{Serialize, Serializer};
|
||||
use tauri::plugin::TauriPlugin;
|
||||
use tauri::{Manager, State};
|
||||
use tauri::Manager;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub fn init() -> TauriPlugin<tauri::Wry> {
|
||||
pub fn init<R: tauri::Runtime>() -> TauriPlugin<R> {
|
||||
tauri::plugin::Builder::new("onelauncher")
|
||||
.setup(|app, _| {
|
||||
app.manage(Mutex::new(AppState::new()?));
|
||||
app.manage(Mutex::new(State::get()));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -16,14 +15,6 @@ pub fn init() -> TauriPlugin<tauri::Wry> {
|
|||
.build()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn refresh_client_manager(state: State<'_, Mutex<AppState>>) -> Result<(), String> {
|
||||
let mut state = state.lock().await;
|
||||
state.clients = ClientManager::new()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, OneLauncherSerializableError>;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
|
@ -51,6 +42,7 @@ macro_rules! impl_serialize_err {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
use serde::ser::SerializeStruct;
|
||||
match self {
|
||||
OneLauncherSerializableError::OneLauncher(onelauncher_error) => {
|
||||
$crate::error::display_tracing_error(onelauncher_error);
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@ pub mod api;
|
|||
pub mod error;
|
||||
pub mod ext;
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[tauri::command]
|
||||
async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
|
||||
onelauncher::ProxyState::initialize(app).await?;
|
||||
let s = onelauncher::State::get().await?;
|
||||
onelauncher::State::update();
|
||||
// #[tracing::instrument(skip_all)]
|
||||
// #[tauri::command]
|
||||
// async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
|
||||
// onelauncher::ProxyState::initialize(app).await?;
|
||||
// let s = onelauncher::State::get().await?;
|
||||
// onelauncher::State::update();
|
||||
|
||||
s.processor.write().await.restore().await?;
|
||||
Ok(())
|
||||
}
|
||||
// s.processor.write().await.restore().await?;
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
#[tauri::command]
|
||||
fn is_dev() -> bool {
|
||||
|
|
@ -33,14 +33,18 @@ pub async fn run() {
|
|||
let _log_guard = onelauncher::start_logger();
|
||||
tracing::info!("initialized tracing subscriber. loading onelauncher...");
|
||||
|
||||
run_app(tauri::Builder::default(), setup).await;
|
||||
run_app(tauri::Builder::default(), |app| {
|
||||
if let Err(err) = setup(app) {
|
||||
tracing::error!("failed to setup app: {:?}", err);
|
||||
}
|
||||
}).await;
|
||||
}
|
||||
|
||||
pub async fn run_app<R: tauri::Runtime, F: FnOnce(&tauri::App<R>) + Send + 'static>(
|
||||
pub async fn run_app<R: tauri::Runtime, F: FnOnce(&mut tauri::App<R>) + Send + 'static>(
|
||||
builder: tauri::Builder<R>,
|
||||
setup: F,
|
||||
) {
|
||||
let mut builder = builder
|
||||
let builder = builder
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
|
||||
println!("{}, {argv:?}, {cwd}", app.package_info().name);
|
||||
|
|
@ -56,7 +60,10 @@ pub async fn run_app<R: tauri::Runtime, F: FnOnce(&tauri::App<R>) + Send + 'stat
|
|||
|
||||
let builder = builder
|
||||
.plugin(api::init())
|
||||
.invoke_handler(tauri::generate_handler![initialize_state, is_dev,]);
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
// initialize_state,
|
||||
is_dev,
|
||||
]);
|
||||
|
||||
let app = builder
|
||||
.build(tauri::tauri_build_context!())
|
||||
|
|
@ -74,21 +81,22 @@ fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use tauri::Manager;
|
||||
// TODO: Add tests
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use tauri::Manager;
|
||||
|
||||
#[test]
|
||||
async fn run_app() {
|
||||
super::run_app(tauri::test::mock_builder(), |app| {
|
||||
super::setup(app);
|
||||
// #[tokio::test]
|
||||
// async fn run_app() {
|
||||
// super::run_app(tauri::test::mock_builder(), |app| {
|
||||
// super::setup(app);
|
||||
|
||||
let win = app.get_webview_window("main").unwrap();
|
||||
tokio::spawn(async move || {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
win.close().unwrap();
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
// let win = app.get_webview_window("main").unwrap();
|
||||
// tokio::spawn(async move {
|
||||
// tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
// win.close().unwrap();
|
||||
// });
|
||||
// })
|
||||
// .await
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue