diff --git a/qt/launcher-gui/src-tauri/src/commands.rs b/qt/launcher-gui/src-tauri/src/commands.rs index a8afdb2c1..f9177e936 100644 --- a/qt/launcher-gui/src-tauri/src/commands.rs +++ b/qt/launcher-gui/src-tauri/src/commands.rs @@ -21,13 +21,12 @@ use anyhow::Result; use strum::IntoEnumIterator; use tauri::AppHandle; use tauri::Emitter; -use tauri::Manager; use tauri::Runtime; use tauri::WebviewWindow; use tauri_plugin_os::locale; -use crate::lang::get_tr; -use crate::lang::setup_i18n; +use crate::app::StateExt; +use crate::lang::I18nExt; use crate::lang::LANGS; use crate::lang::LANGS_DEFAULT_REGION; use crate::lang::LANGS_WITH_REGIONS; @@ -41,7 +40,7 @@ pub async fn i18n_resources( _window: WebviewWindow, input: I18nResourcesRequest, ) -> Result { - let tr = get_tr(&app)?; + let tr = app.tr()?; serde_json::to_vec(&tr.resources_for_js(&input.modules)) .with_context(|| "failed to serialise i18n resources") .map(Into::into) @@ -87,7 +86,7 @@ pub async fn set_lang( } else { input.split('-').next().unwrap().to_owned() }; - setup_i18n(&app, &[&*input]); + app.setup_tr(&[&*input]); Ok(()) } @@ -95,8 +94,7 @@ pub async fn get_state( app: AppHandle, _window: WebviewWindow, ) -> Result { - let state = app.state::(); - let kind = match &*state { + let kind = match app.flow() { State::LaunchAnki(_) => unreachable!(), State::OsUnsupported(e) => StateProtoKind::OsUnsupported(format!("{e:?}")), State::UnknownError(e) => StateProtoKind::UnknownError(format!("{e:?}")), @@ -112,7 +110,7 @@ pub async fn get_mirrors( app: AppHandle, _window: WebviewWindow, ) -> Result { - let tr = get_tr(&app)?; + let tr = app.tr()?; Ok(GetMirrorsResponse { mirrors: Mirror::iter() .map(|mirror| get_mirrors_response::Pair { @@ -131,7 +129,7 @@ pub async fn get_options( app: AppHandle, _window: WebviewWindow, ) -> Result { - let state = app.state::(); + let state = app.flow(); let options = (&state.normal()?.initial_options).into(); Ok(options) } @@ -140,8 +138,7 @@ pub async fn get_available_versions( app: AppHandle, _window: WebviewWindow, ) -> Result { - let state = app.state::(); - let state = state.normal()?; + let state = app.flow().normal()?; let mut rx = state.available_versions.clone().unwrap(); rx.changed().await.unwrap(); let x = rx.borrow(); @@ -156,8 +153,7 @@ pub async fn get_existing_versions( app: AppHandle, _window: WebviewWindow, ) -> Result { - let state = app.state::(); - let state = state.normal()?; + let state = app.flow().normal()?; let mut rx = state.current_versions.clone().unwrap(); rx.changed().await.unwrap(); let x = rx.borrow(); @@ -172,8 +168,7 @@ pub async fn choose_version( _window: WebviewWindow, input: ChooseVersionRequest, ) -> Result { - let state = app.state::(); - let state = state.normal()?; + let state = app.flow().normal()?; let paths = state.paths.clone(); tauri::async_runtime::spawn_blocking(move || { @@ -210,7 +205,7 @@ pub async fn choose_version( } pub async fn launch_anki(app: AppHandle, _window: WebviewWindow) -> Result<()> { - app.state::().paths().and_then(uv::launch_anki) + app.flow().paths().and_then(uv::launch_anki) } pub async fn exit(app: AppHandle, window: WebviewWindow) -> Result<()> {