Implement iPhone and Apple Watch preferences (#53)

This commit is contained in:
2026-08-15 22:37:31 +02:00
parent 81886756a2
commit affdb55519
15 changed files with 1409 additions and 60 deletions

View File

@@ -10,13 +10,15 @@ use std::{
};
use ironstorage::{
config::ConfigError,
config::{ConfigError, MobileAppearance as StorageMobileAppearance},
mobile::{self, MobileShellState as StorageShellState, MobileTab as StorageTab},
mobile_authentication::{
MobileAuthenticationError as StorageAuthenticationError,
MobileAuthenticationErrorKind as StorageAuthenticationErrorKind,
MobileAuthenticationState as StorageAuthenticationState,
MobileEntryCopy as StorageEntryCopy, MobileEntryPresentation as StorageEntryPresentation,
MobilePreferences as StorageMobilePreferences,
MobileWatchPreferenceState as StorageWatchPreferenceState,
},
mobile_entry::{
MobileEntryEditorFieldKind as StorageEntryEditorFieldKind,
@@ -623,6 +625,91 @@ pub struct MobileAuthenticationState {
pub remaining_seconds: u64,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Enum)]
pub enum MobileAppearance {
System,
Light,
Dark,
}
impl From<StorageMobileAppearance> for MobileAppearance {
fn from(appearance: StorageMobileAppearance) -> Self {
match appearance {
StorageMobileAppearance::System => Self::System,
StorageMobileAppearance::Light => Self::Light,
StorageMobileAppearance::Dark => Self::Dark,
}
}
}
impl From<MobileAppearance> for StorageMobileAppearance {
fn from(appearance: MobileAppearance) -> Self {
match appearance {
MobileAppearance::System => Self::System,
MobileAppearance::Light => Self::Light,
MobileAppearance::Dark => Self::Dark,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, uniffi::Enum)]
pub enum MobileWatchPreferenceState {
Unsupported,
NotPaired,
AppNotInstalled,
Ready,
Pending,
}
impl From<StorageWatchPreferenceState> for MobileWatchPreferenceState {
fn from(state: StorageWatchPreferenceState) -> Self {
match state {
StorageWatchPreferenceState::Unsupported => Self::Unsupported,
StorageWatchPreferenceState::NotPaired => Self::NotPaired,
StorageWatchPreferenceState::AppNotInstalled => Self::AppNotInstalled,
StorageWatchPreferenceState::Ready => Self::Ready,
StorageWatchPreferenceState::Pending => Self::Pending,
}
}
}
#[derive(Clone, uniffi::Record)]
pub struct MobilePreferences {
pub repository_title: String,
pub repository_url: String,
pub server_title: String,
pub server_identity: String,
pub application_account: Option<String>,
pub default_key_title: String,
pub default_key_fingerprint: String,
pub authentication_timeout_seconds: u64,
pub biometric_unlock_enabled: bool,
pub appearance: MobileAppearance,
pub watch_state: MobileWatchPreferenceState,
pub watch_title: String,
pub watch_detail: String,
}
impl From<StorageMobilePreferences> for MobilePreferences {
fn from(preferences: StorageMobilePreferences) -> Self {
Self {
repository_title: preferences.repository_title().to_owned(),
repository_url: preferences.repository_url().to_owned(),
server_title: preferences.server_title().to_owned(),
server_identity: preferences.server_identity().to_owned(),
application_account: preferences.application_account().map(str::to_owned),
default_key_title: preferences.default_key_title().to_owned(),
default_key_fingerprint: preferences.default_key_fingerprint().to_owned(),
authentication_timeout_seconds: preferences.authentication_timeout_seconds(),
biometric_unlock_enabled: preferences.biometric_unlock_enabled(),
appearance: preferences.appearance().into(),
watch_state: preferences.watch_state().into(),
watch_title: preferences.watch_title().to_owned(),
watch_detail: preferences.watch_detail().to_owned(),
}
}
}
#[derive(Clone, uniffi::Record)]
pub struct MobileGitIdentity {
pub name: String,
@@ -1400,6 +1487,49 @@ impl MobileAuthentication {
.map_err(Into::into)
}
pub fn mobile_appearance(&self) -> Result<MobileAppearance, MobileAuthenticationFfiError> {
self.authentication
.mobile_appearance()
.map(Into::into)
.map_err(Into::into)
}
pub fn preferences(
&self,
watch_supported: bool,
watch_paired: bool,
watch_app_installed: bool,
) -> Result<MobilePreferences, MobileAuthenticationFfiError> {
self.authentication
.preferences(watch_supported, watch_paired, watch_app_installed)
.map(Into::into)
.map_err(Into::into)
}
pub fn set_authentication_timeout(
&self,
seconds: u64,
) -> Result<(), MobileAuthenticationFfiError> {
self.authentication
.set_authentication_timeout(seconds)
.map_err(Into::into)
}
pub fn set_mobile_appearance(
&self,
appearance: MobileAppearance,
) -> Result<(), MobileAuthenticationFfiError> {
self.authentication
.set_mobile_appearance(appearance.into())
.map_err(Into::into)
}
pub fn remove_application_token(&self) -> Result<(), MobileAuthenticationFfiError> {
self.authentication
.remove_application_token()
.map_err(Into::into)
}
pub fn set_git_identity(
&self,
name: String,