refactor: app event bus (#6985)

* refactor: app event bus

* fix: use messagepack + cleanup

* fix: use postcard

* fix: lint

* fix: import gate

* fix: prettierignore + lint

* fix: lint

* fix: rev
This commit is contained in:
Calum H.
2026-08-13 16:33:06 +00:00
committed by GitHub
parent 5f7493491f
commit 579109a478
93 changed files with 2669 additions and 834 deletions
+13 -9
View File
@@ -3,9 +3,9 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
use tauri::plugin::TauriPlugin;
use tauri::{Emitter, Manager, PhysicalPosition, PhysicalSize, Runtime};
use tauri::{Manager, PhysicalPosition, PhysicalSize, Runtime};
use tauri_plugin_opener::OpenerExt;
use theseus::settings;
use theseus::{AppEvent, EventState, settings};
use tokio::sync::RwLock;
pub struct AdsState {
@@ -20,7 +20,6 @@ pub struct AdsState {
}
const AD_LINK: &str = "https://modrinth.com/wrapper/app-ads-cookie";
const ADS_CONSENT_REQUIRED_EVENT: &str = "ads-consent-required";
const APP_TITLE_BAR_HEIGHT: f32 = 48.0;
#[cfg(any(windows, target_os = "macos"))]
pub(super) const OCCLUDED_AREA_THRESHOLD: f64 = 0.5;
@@ -38,6 +37,12 @@ const ADS_USER_AGENT: &str = concat!(
" (Modrinth App)",
);
fn emit_ads_consent_required(required: bool) {
EventState::get()
.send(AppEvent::AdsConsentRequired(required))
.ok();
}
#[cfg(windows)]
fn ads_user_agent_override_params() -> String {
serde_json::json!({
@@ -666,7 +671,7 @@ pub async fn init_ads_window<R: Runtime>(
&& state.consent_required
&& state.consent_notification_enabled
{
app.emit_to("main", ADS_CONSENT_REQUIRED_EVENT, true).ok();
emit_ads_consent_required(true);
}
Ok(())
@@ -704,7 +709,7 @@ pub async fn update_ads_window_hold<R: Runtime>(
&& state.consent_required
&& state.consent_notification_enabled
{
app.emit_to("main", ADS_CONSENT_REQUIRED_EVENT, true).ok();
emit_ads_consent_required(true);
}
Ok(())
@@ -730,7 +735,7 @@ pub async fn hide_ads_window<R: Runtime>(
}
if reset {
app.emit_to("main", ADS_CONSENT_REQUIRED_EVENT, false).ok();
emit_ads_consent_required(false);
}
Ok(())
@@ -761,8 +766,7 @@ pub async fn show_ads_consent_ui<R: Runtime>(
)?;
}
app.emit_to("main", ADS_CONSENT_REQUIRED_EVENT, show_notification)
.ok();
emit_ads_consent_required(show_notification);
Ok(())
}
@@ -841,7 +845,7 @@ pub async fn finish_ads_consent_flow<R: Runtime>(
}
}
app.emit_to("main", ADS_CONSENT_REQUIRED_EVENT, false).ok();
emit_ads_consent_required(false);
Ok(())
}