Present iPhone Git actions (#51)

This commit is contained in:
2026-08-14 17:24:41 +02:00
parent fcf649e56d
commit 65eb1da71c
8 changed files with 1054 additions and 90 deletions

View File

@@ -26,7 +26,8 @@ use ironstorage::{
MobileEntrySectionKind as StorageEntrySectionKind,
},
mobile_home::{
self, MobileHomeChangeKind as StorageHomeChangeKind,
self, MobileHomeActionKind as StorageHomeActionKind,
MobileHomeChangeKind as StorageHomeChangeKind,
MobileHomeChangeStatus as StorageHomeChangeStatus, MobileHomeError as StorageHomeError,
MobileHomeErrorKind as StorageHomeErrorKind, MobileHomeFreshness as StorageHomeFreshness,
MobileHomePhase as StorageHomePhase,
@@ -189,6 +190,32 @@ pub enum MobileHomeChangeStatus {
Deleted,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Enum)]
pub enum MobileHomeActionKind {
Commit,
Fetch,
Pull,
Push,
}
impl From<StorageHomeActionKind> for MobileHomeActionKind {
fn from(kind: StorageHomeActionKind) -> Self {
match kind {
StorageHomeActionKind::Commit => Self::Commit,
StorageHomeActionKind::Fetch => Self::Fetch,
StorageHomeActionKind::Pull => Self::Pull,
StorageHomeActionKind::Push => Self::Push,
}
}
}
#[derive(Clone, uniffi::Record)]
pub struct MobileHomeAction {
pub kind: MobileHomeActionKind,
pub title: String,
pub system_image: String,
}
impl From<StorageHomeChangeStatus> for MobileHomeChangeStatus {
fn from(status: StorageHomeChangeStatus) -> Self {
match status {
@@ -205,6 +232,7 @@ pub struct MobileHomeSummaryRow {
pub title: String,
pub detail: String,
pub system_image: String,
pub actions: Vec<MobileHomeAction>,
}
#[derive(Clone, uniffi::Record)]
@@ -225,6 +253,7 @@ pub struct MobileHomeCommit {
pub system_image: String,
pub timestamp: i64,
pub changes: Vec<MobileHomeChange>,
pub actions: Vec<MobileHomeAction>,
}
#[derive(Clone, uniffi::Record)]
@@ -259,6 +288,7 @@ impl From<mobile_home::MobileHomePage> for MobileHomePage {
title: row.title().to_owned(),
detail: row.detail().to_owned(),
system_image: row.system_image().to_owned(),
actions: row.actions().iter().map(mobile_home_action).collect(),
})
.collect(),
incoming: page.incoming().iter().map(mobile_home_commit).collect(),
@@ -293,6 +323,15 @@ fn mobile_home_commit(commit: &mobile_home::MobileHomeCommit) -> MobileHomeCommi
status: change.status().into(),
})
.collect(),
actions: commit.actions().iter().map(mobile_home_action).collect(),
}
}
fn mobile_home_action(action: &mobile_home::MobileHomeAction) -> MobileHomeAction {
MobileHomeAction {
kind: action.kind().into(),
title: action.title().to_owned(),
system_image: action.system_image().to_owned(),
}
}
@@ -302,6 +341,7 @@ pub enum MobileHomePhase {
Authenticating,
Receiving,
Integrating,
Sending,
Finishing,
}
@@ -312,6 +352,7 @@ impl From<StorageHomePhase> for MobileHomePhase {
StorageHomePhase::Authenticating => Self::Authenticating,
StorageHomePhase::Receiving => Self::Receiving,
StorageHomePhase::Integrating => Self::Integrating,
StorageHomePhase::Sending => Self::Sending,
StorageHomePhase::Finishing => Self::Finishing,
}
}
@@ -319,6 +360,7 @@ impl From<StorageHomePhase> for MobileHomePhase {
#[derive(Clone, uniffi::Record)]
pub struct MobileHomeProgress {
pub action: Option<MobileHomeActionKind>,
pub phase: MobileHomePhase,
pub title: String,
pub detail: String,
@@ -331,6 +373,7 @@ pub enum MobileHomeErrorKind {
Authentication,
Conflict,
DirtyLocalChanges,
NoChanges,
Offline,
Interrupted,
SecureStorage,
@@ -346,6 +389,7 @@ impl From<StorageHomeErrorKind> for MobileHomeErrorKind {
StorageHomeErrorKind::Authentication => Self::Authentication,
StorageHomeErrorKind::Conflict => Self::Conflict,
StorageHomeErrorKind::DirtyLocalChanges => Self::DirtyLocalChanges,
StorageHomeErrorKind::NoChanges => Self::NoChanges,
StorageHomeErrorKind::Offline => Self::Offline,
StorageHomeErrorKind::Interrupted => Self::Interrupted,
StorageHomeErrorKind::SecureStorage => Self::SecureStorage,
@@ -394,6 +438,7 @@ impl MobileHomeOperation {
pub fn progress(&self) -> MobileHomeProgress {
let progress = self.operation.progress();
MobileHomeProgress {
action: progress.action().map(Into::into),
phase: progress.phase().into(),
title: progress.title().to_owned(),
detail: progress.detail().to_owned(),
@@ -411,14 +456,25 @@ impl MobileHomeOperation {
.map_err(Into::into)
}
pub fn refresh(&self) -> Result<MobileHomePage, MobileHomeFfiError> {
self.operation.refresh().map(Into::into).map_err(Into::into)
pub fn commit(&self, message: String) -> Result<MobileHomePage, MobileHomeFfiError> {
self.operation
.commit(&message)
.map(Into::into)
.map_err(Into::into)
}
pub fn fetch(&self) -> Result<MobileHomePage, MobileHomeFfiError> {
self.operation.fetch().map(Into::into).map_err(Into::into)
}
pub fn pull(&self) -> Result<MobileHomePage, MobileHomeFfiError> {
self.operation.pull().map(Into::into).map_err(Into::into)
}
pub fn push(&self) -> Result<MobileHomePage, MobileHomeFfiError> {
self.operation.push().map(Into::into).map_err(Into::into)
}
pub fn cancel(&self) {
self.operation.cancel();
}
@@ -1322,7 +1378,7 @@ impl From<StorageAuthenticationError> for MobileAuthenticationFfiError {
#[derive(uniffi::Object)]
pub struct MobileAuthentication {
authentication: ironstorage::mobile_authentication::MobileAuthentication,
authentication: Arc<ironstorage::mobile_authentication::MobileAuthentication>,
}
#[uniffi::export]
@@ -1855,9 +1911,13 @@ pub fn set_selected_mobile_tab(tab: MobileTab) -> Result<(), MobilePreferenceErr
}
#[uniffi::export]
pub fn mobile_home_operation() -> Arc<MobileHomeOperation> {
pub fn mobile_home_operation(
authentication: Arc<MobileAuthentication>,
) -> Arc<MobileHomeOperation> {
Arc::new(MobileHomeOperation {
operation: mobile_home::MobileHomeOperation::default(),
operation: mobile_home::MobileHomeOperation::new(Arc::clone(
&authentication.authentication,
)),
})
}
@@ -1887,7 +1947,7 @@ pub fn mobile_password_search(query: String) -> Result<MobilePasswordPage, Mobil
#[uniffi::export]
pub fn mobile_authentication() -> Result<Arc<MobileAuthentication>, MobileAuthenticationFfiError> {
Ok(Arc::new(MobileAuthentication {
authentication: ironstorage::mobile_authentication::MobileAuthentication::load()?,
authentication: Arc::new(ironstorage::mobile_authentication::MobileAuthentication::load()?),
}))
}
@@ -1931,8 +1991,8 @@ pub fn replace_configured_mobile_application_token(
#[cfg(test)]
mod tests {
use super::{
MobileHomePhase, MobileOnboardingErrorKind, MobileOnboardingFfiError, MobileShellState,
MobileTab,
MobileHomeActionKind, MobileOnboardingErrorKind, MobileOnboardingFfiError,
MobileShellState, MobileTab, StorageHomeActionKind,
};
#[test]
@@ -1976,10 +2036,10 @@ mod tests {
}
#[test]
fn home_operation_exposes_typed_progress_and_cancellation() {
let operation = super::mobile_home_operation();
assert_eq!(operation.progress().phase, MobileHomePhase::Validating);
operation.cancel();
assert_eq!(operation.progress().phase, MobileHomePhase::Validating);
fn home_bridge_preserves_storage_action_kinds() {
assert_eq!(
MobileHomeActionKind::from(StorageHomeActionKind::Push),
MobileHomeActionKind::Push
);
}
}