You've already forked AstralRinth
forked from didirus/AstralRinth
Misc improvements and fixes (#109)
* now utilizing tracing better * better tracing * fix mac vs pc oppositional env var issue * modified loading package * added droppable loadingbarid that sends completion message * loading bar * regressed bug on mac * fixed non-updated loading bar on playground * Loading bar improvements --------- Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
@@ -15,7 +15,7 @@ tauri-build = { version = "1.2", features = [] }
|
||||
regex = "1.5"
|
||||
|
||||
[dependencies]
|
||||
theseus = { path = "../../theseus", features = ["tauri"] }
|
||||
theseus = { path = "../../theseus", features = ["tauri", "cli"] }
|
||||
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
@@ -30,6 +30,10 @@ url = "2.2"
|
||||
uuid = { version = "1.1", features = ["serde", "v4"] }
|
||||
os_info = "3.7.0"
|
||||
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = "0.2"
|
||||
tracing-error = "0.1"
|
||||
|
||||
[features]
|
||||
# by default Tauri runs in production mode
|
||||
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
||||
|
||||
@@ -47,6 +47,8 @@ where
|
||||
}
|
||||
|
||||
// Lists active progress bars
|
||||
// Create a new HashMap with the same keys
|
||||
// Values provided should not be used directly, as they are not guaranteed to be up-to-date
|
||||
#[tauri::command]
|
||||
pub async fn progress_bars_list(
|
||||
) -> Result<std::collections::HashMap<uuid::Uuid, theseus::LoadingBar>> {
|
||||
@@ -64,6 +66,16 @@ macro_rules! impl_serialize {
|
||||
S: Serializer,
|
||||
{
|
||||
match self {
|
||||
// For the Theseus variant, we add a special display for the error,
|
||||
// to view the spans if subscribed to them (which is information that is lost when serializing)
|
||||
TheseusSerializableError::Theseus(theseus_error) => {
|
||||
$crate::error::display_tracing_error(theseus_error);
|
||||
|
||||
let mut state = serializer.serialize_struct("Theseus", 2)?;
|
||||
state.serialize_field("field_name", "Theseus")?;
|
||||
state.serialize_field("message", &theseus_error.to_string())?;
|
||||
state.end()
|
||||
}
|
||||
$(
|
||||
TheseusSerializableError::$variant(message) => {
|
||||
let mut state = serializer.serialize_struct(stringify!($variant), 2)?;
|
||||
@@ -80,7 +92,6 @@ macro_rules! impl_serialize {
|
||||
|
||||
// Use the macro to implement Serialize for TheseusSerializableError
|
||||
impl_serialize! {
|
||||
Theseus,
|
||||
IO,
|
||||
NoProfileFound,
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ use theseus::prelude::*;
|
||||
// Creates a pack from a version ID (returns a path to the created profile)
|
||||
// invoke('pack_install_version_id', version_id)
|
||||
#[tauri::command]
|
||||
pub async fn pack_install_version_id(version_id: String) -> Result<PathBuf> {
|
||||
let res = pack::install_pack_from_version_id(version_id).await?;
|
||||
pub async fn pack_install_version_id(
|
||||
version_id: String,
|
||||
pack_title: Option<String>,
|
||||
) -> Result<PathBuf> {
|
||||
let res =
|
||||
pack::install_pack_from_version_id(version_id, pack_title).await?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct FrontendSettings {
|
||||
pub default_user: Option<uuid::Uuid>,
|
||||
pub hooks: Hooks,
|
||||
pub max_concurrent_downloads: usize,
|
||||
pub max_concurrent_writes: usize,
|
||||
pub version: u32,
|
||||
pub collapsed_navigation: bool,
|
||||
}
|
||||
@@ -39,6 +40,7 @@ pub async fn settings_get() -> Result<FrontendSettings> {
|
||||
default_user: backend_settings.default_user,
|
||||
hooks: backend_settings.hooks,
|
||||
max_concurrent_downloads: backend_settings.max_concurrent_downloads,
|
||||
max_concurrent_writes: backend_settings.max_concurrent_writes,
|
||||
version: backend_settings.version,
|
||||
collapsed_navigation: backend_settings.collapsed_navigation,
|
||||
};
|
||||
@@ -77,6 +79,7 @@ pub async fn settings_set(settings: FrontendSettings) -> Result<()> {
|
||||
default_user: settings.default_user,
|
||||
hooks: settings.hooks,
|
||||
max_concurrent_downloads: settings.max_concurrent_downloads,
|
||||
max_concurrent_writes: settings.max_concurrent_writes,
|
||||
version: settings.version,
|
||||
collapsed_navigation: settings.collapsed_navigation,
|
||||
};
|
||||
|
||||
18
theseus_gui/src-tauri/src/error.rs
Normal file
18
theseus_gui/src-tauri/src/error.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use tracing_error::ExtractSpanTrace;
|
||||
|
||||
pub fn display_tracing_error(err: &theseus::Error) {
|
||||
match get_span_trace(err) {
|
||||
Some(span_trace) => {
|
||||
tracing::error!(error = %err, span_trace = %span_trace);
|
||||
}
|
||||
None => {
|
||||
tracing::error!(error = %err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_span_trace<'a>(
|
||||
error: &'a (dyn std::error::Error + 'static),
|
||||
) -> Option<&'a tracing_error::SpanTrace> {
|
||||
error.source().and_then(|e| e.span_trace())
|
||||
}
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
use theseus::prelude::*;
|
||||
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
mod api;
|
||||
mod error;
|
||||
|
||||
// Should be called in launcher initialization
|
||||
#[tauri::command]
|
||||
@@ -37,7 +41,34 @@ async fn should_disable_mouseover() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
tracing is set basd on the environment variable RUST_LOG=xxx, depending on the amount of logs to show
|
||||
ERROR > WARN > INFO > DEBUG > TRACE
|
||||
eg. RUST_LOG=info will show info, warn, and error logs
|
||||
RUST_LOG="theseus=trace" will show *all* messages but from theseus only (and not dependencies using similar crates)
|
||||
RUST_LOG="theseus=trace" will show *all* messages but from theseus only (and not dependencies using similar crates)
|
||||
|
||||
Error messages returned to Tauri will display as traced error logs if they return an error.
|
||||
This will also include an attached span trace if the error is from a tracing error, and the level is set to info, debug, or trace
|
||||
|
||||
on unix:
|
||||
RUST_LOG="theseus=trace" {run command}
|
||||
|
||||
*/
|
||||
let filter = EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| EnvFilter::new("theseus=info"));
|
||||
|
||||
let subscriber = tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.with(filter)
|
||||
.with(ErrorLayer::default());
|
||||
|
||||
tracing::subscriber::set_global_default(subscriber)
|
||||
.expect("setting default subscriber failed");
|
||||
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
initialize_state,
|
||||
|
||||
@@ -25,15 +25,16 @@ import { listen } from '@tauri-apps/api/event'
|
||||
/// Payload for the 'loading' event
|
||||
/*
|
||||
LoadingPayload {
|
||||
event: "StateInit", "PackDownload", etc
|
||||
- Certain states have additional fields:
|
||||
- PackDownload: {
|
||||
pack_name: name of the pack
|
||||
pack_id, optional, the id of the modpack
|
||||
pack_version, optional, the version of the modpack
|
||||
- MinecraftDownload: {
|
||||
profile_name: name of the profile
|
||||
profile_uuid: unique identification of the profile
|
||||
event: {
|
||||
type: string, one of "StateInit", "PackDownload", etc
|
||||
(Optional fields depending on event type)
|
||||
pack_name: name of the pack
|
||||
pack_id, optional, the id of the modpack
|
||||
pack_version, optional, the version of the modpack
|
||||
profile_name: name of the profile
|
||||
profile_uuid: unique identification of the profile
|
||||
|
||||
}
|
||||
loader_uuid: unique identification of the loading bar
|
||||
fraction: number, (as a fraction of 1, how much we'vel oaded so far). If null, by convention, loading is finished
|
||||
message: message to display to the user
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
|
||||
// Installs pack from a version ID
|
||||
export async function install(versionId) {
|
||||
return await invoke('pack_install_version_id', { versionId })
|
||||
export async function install(versionId, packTitle) {
|
||||
return await invoke('pack_install_version_id', { versionId, packTitle })
|
||||
}
|
||||
|
||||
// Installs pack from a path
|
||||
|
||||
Reference in New Issue
Block a user