mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
add GetState rpc
This commit is contained in:
parent
0d1204521b
commit
bcd28c03ec
5 changed files with 41 additions and 4 deletions
|
|
@ -18,6 +18,8 @@ service LauncherService {
|
|||
rpc WindowReady(generic.Empty) returns (generic.Empty);
|
||||
rpc ZoomWebview(ZoomWebviewRequest) returns (generic.Empty);
|
||||
|
||||
rpc GetState(generic.Empty) returns (State);
|
||||
|
||||
rpc GetAvailableVersions(generic.Empty) returns (Versions);
|
||||
rpc GetExistingVersions(generic.Empty) returns (ExistingVersions);
|
||||
|
||||
|
|
@ -109,3 +111,16 @@ message ExistingVersions {
|
|||
optional Version previous = 2;
|
||||
bool pyproject_modified_by_user = 3;
|
||||
}
|
||||
|
||||
message NormalState {
|
||||
Options options = 1;
|
||||
}
|
||||
|
||||
message State {
|
||||
oneof kind {
|
||||
string os_unsupported = 1;
|
||||
string unknown_error = 2;
|
||||
NormalState normal = 3;
|
||||
google.protobuf.Empty uninstall = 4;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use crate::uv;
|
|||
pub const PROTOCOL: &str = "anki";
|
||||
|
||||
pub fn init() -> Option<State> {
|
||||
let mut state = State::init().unwrap_or_else(State::Error);
|
||||
let mut state = State::init().unwrap_or_else(State::UnknownError);
|
||||
|
||||
match state {
|
||||
State::Normal(ref mut state) => state.check_versions(),
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@
|
|||
use anki_proto::generic;
|
||||
use anki_proto::launcher::get_langs_response;
|
||||
use anki_proto::launcher::get_mirrors_response;
|
||||
use anki_proto::launcher::state::Kind as StateProtoKind;
|
||||
use anki_proto::launcher::ChooseVersionRequest;
|
||||
use anki_proto::launcher::ChooseVersionResponse;
|
||||
use anki_proto::launcher::GetLangsResponse;
|
||||
use anki_proto::launcher::GetMirrorsResponse;
|
||||
use anki_proto::launcher::I18nResourcesRequest;
|
||||
use anki_proto::launcher::Mirror;
|
||||
use anki_proto::launcher::NormalState as NormalStateProto;
|
||||
use anki_proto::launcher::Options;
|
||||
use anki_proto::launcher::State as StateProto;
|
||||
use anki_proto::launcher::ZoomWebviewRequest;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Context;
|
||||
|
|
@ -88,6 +91,23 @@ pub async fn set_lang<R: Runtime>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_state<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
_window: WebviewWindow<R>,
|
||||
) -> Result<StateProto> {
|
||||
let state = app.state::<State>();
|
||||
let kind = match &*state {
|
||||
State::LaunchAnki(_) => unreachable!(),
|
||||
State::OsUnsupported(e) => StateProtoKind::OsUnsupported(format!("{e:?}")),
|
||||
State::UnknownError(e) => StateProtoKind::UnknownError(format!("{e:?}")),
|
||||
State::Uninstall(_) => StateProtoKind::Uninstall(()),
|
||||
State::Normal(normal) => StateProtoKind::Normal(NormalStateProto {
|
||||
options: Some((&normal.initial_options).into()),
|
||||
}),
|
||||
};
|
||||
Ok(StateProto { kind: Some(kind) })
|
||||
}
|
||||
|
||||
pub async fn get_mirrors<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
_window: WebviewWindow<R>,
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ impl From<NormalState> for State {
|
|||
|
||||
pub enum State {
|
||||
LaunchAnki(Arc<uv::Paths>),
|
||||
#[allow(dead_code)] // TODO: use
|
||||
Error(anyhow::Error),
|
||||
OsUnsupported(anyhow::Error),
|
||||
UnknownError(anyhow::Error),
|
||||
Uninstall(Arc<uv::Paths>),
|
||||
Normal(NormalState),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -734,7 +734,9 @@ impl crate::state::State {
|
|||
let _ = remove_file(&paths.launcher_trigger_file);
|
||||
}
|
||||
|
||||
ensure_os_supported()?;
|
||||
if let Err(e) = ensure_os_supported() {
|
||||
return Ok(Self::OsUnsupported(e));
|
||||
}
|
||||
|
||||
Ok(Self::Normal(paths.into()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue