mirror of
https://github.com/ulyssa/iamb.git
synced 2024-07-14 15:10:25 +03:00
Merge c1edd8a93f
into 497be7f099
This commit is contained in:
commit
8e162d8115
@ -16,6 +16,7 @@ build = "build.rs"
|
||||
|
||||
[features]
|
||||
default = ["bundled"]
|
||||
sled-export = ["dep:temp-dir", "dep:sled"]
|
||||
bundled = ["matrix-sdk/bundled-sqlite", "rustls-tls"]
|
||||
native-tls = ["matrix-sdk/native-tls"]
|
||||
rustls-tls = ["matrix-sdk/rustls-tls"]
|
||||
@ -50,8 +51,8 @@ regex = "^1.5"
|
||||
rpassword = "^7.2"
|
||||
serde = "^1.0"
|
||||
serde_json = "^1.0"
|
||||
sled = "0.34.7"
|
||||
temp-dir = "0.1.12"
|
||||
sled = { version = "0.34.7", optional = true }
|
||||
temp-dir = { version = "0.1.12", optional = true }
|
||||
thiserror = "^1.0.37"
|
||||
toml = "^0.8.12"
|
||||
tracing = "~0.1.36"
|
||||
|
@ -608,6 +608,7 @@ pub enum IambError {
|
||||
FailedKeyImport(#[from] matrix_sdk::encryption::RoomKeyImportError),
|
||||
|
||||
/// A failure related to the cryptographic store.
|
||||
#[cfg(feature = "sled-export")]
|
||||
#[error("Cannot export keys from sled: {0}")]
|
||||
UpgradeSled(#[from] crate::sled_export::SledMigrationError),
|
||||
|
||||
@ -619,7 +620,7 @@ pub enum IambError {
|
||||
#[error("Matrix client error: {0}")]
|
||||
Matrix(#[from] matrix_sdk::Error),
|
||||
|
||||
/// A failure in the sled storage.
|
||||
/// A failure in the storage.
|
||||
#[error("Matrix client storage error: {0}")]
|
||||
Store(#[from] matrix_sdk::StoreError),
|
||||
|
||||
|
@ -748,6 +748,7 @@ pub struct ApplicationSettings {
|
||||
pub layout_json: PathBuf,
|
||||
pub session_json: PathBuf,
|
||||
pub session_json_old: PathBuf,
|
||||
#[cfg(feature = "sled-export")]
|
||||
pub sled_dir: PathBuf,
|
||||
pub sqlite_dir: PathBuf,
|
||||
pub profile_name: String,
|
||||
@ -836,7 +837,9 @@ impl ApplicationSettings {
|
||||
profile_data_dir.push("profiles");
|
||||
profile_data_dir.push(profile_name.as_str());
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
let mut sled_dir = profile_dir.clone();
|
||||
#[cfg(feature = "sled-export")]
|
||||
sled_dir.push("matrix");
|
||||
|
||||
let mut sqlite_dir = profile_data_dir.clone();
|
||||
@ -857,6 +860,7 @@ impl ApplicationSettings {
|
||||
layout_json.push("layout.json");
|
||||
|
||||
let settings = ApplicationSettings {
|
||||
#[cfg(feature = "sled-export")]
|
||||
sled_dir,
|
||||
layout_json,
|
||||
session_json,
|
||||
|
24
src/main.rs
24
src/main.rs
@ -27,11 +27,14 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use clap::Parser;
|
||||
#[cfg(feature = "sled-export")]
|
||||
use matrix_sdk::crypto::encrypt_room_key_export;
|
||||
use matrix_sdk::ruma::api::client::error::ErrorKind;
|
||||
use matrix_sdk::ruma::OwnedUserId;
|
||||
use modalkit::keybindings::InputBindings;
|
||||
#[cfg(feature = "sled-export")]
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
#[cfg(feature = "sled-export")]
|
||||
use temp_dir::TempDir;
|
||||
use tokio::sync::Mutex as AsyncMutex;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
@ -72,11 +75,13 @@ mod keybindings;
|
||||
mod message;
|
||||
mod notifications;
|
||||
mod preview;
|
||||
mod sled_export;
|
||||
mod util;
|
||||
mod windows;
|
||||
mod worker;
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
mod sled_export;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@ -705,6 +710,7 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
fn gen_passphrase() -> String {
|
||||
rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
@ -720,6 +726,7 @@ fn read_response(question: &str) -> String {
|
||||
input
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
fn read_yesno(question: &str) -> Option<char> {
|
||||
read_response(question).chars().next().map(|c| c.to_ascii_lowercase())
|
||||
}
|
||||
@ -732,7 +739,13 @@ async fn login(worker: &Requester, settings: &ApplicationSettings) -> IambResult
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if settings.session_json_old.is_file() && !settings.sled_dir.is_dir() {
|
||||
#[cfg(not(feature = "sled-export"))]
|
||||
let check_old_session = settings.session_json_old.is_file();
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
let check_old_session = settings.session_json_old.is_file() && !settings.sled_dir.is_dir();
|
||||
|
||||
if check_old_session {
|
||||
let session = settings.read_session(&settings.session_json_old)?;
|
||||
worker.login(LoginStyle::SessionRestore(session.into()))?;
|
||||
|
||||
@ -782,6 +795,7 @@ fn print_exit<T: Display, N>(v: T) -> N {
|
||||
|
||||
// We can't access the OlmMachine directly, so write the keys to a temporary
|
||||
// file first, and then import them later.
|
||||
#[cfg(feature = "sled-export")]
|
||||
async fn check_import_keys(
|
||||
settings: &ApplicationSettings,
|
||||
) -> IambResult<Option<(temp_dir::TempDir, String)>> {
|
||||
@ -832,6 +846,7 @@ async fn check_import_keys(
|
||||
Ok(Some((tmpdir, passphrase)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
async fn login_upgrade(
|
||||
keydir: TempDir,
|
||||
passphrase: String,
|
||||
@ -965,6 +980,7 @@ fn restore_tty(enable_enhanced_keys: bool) {
|
||||
|
||||
async fn run(settings: ApplicationSettings) -> IambResult<()> {
|
||||
// Get old keys the first time we run w/ the upgraded SDK.
|
||||
#[cfg(feature = "sled-export")]
|
||||
let import_keys = check_import_keys(&settings).await?;
|
||||
|
||||
// Set up client state.
|
||||
@ -978,12 +994,16 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> {
|
||||
let store = Arc::new(AsyncMutex::new(store));
|
||||
worker.init(store.clone());
|
||||
|
||||
#[cfg(feature = "sled-export")]
|
||||
let res = if let Some((keydir, pass)) = import_keys {
|
||||
login_upgrade(keydir, pass, &worker, &settings, &store).await
|
||||
} else {
|
||||
login_normal(&worker, &settings, &store).await
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "sled-export"))]
|
||||
let res = login_normal(&worker, &settings, &store).await;
|
||||
|
||||
match res {
|
||||
Err(UIError::Application(IambError::Matrix(e))) => {
|
||||
if let Some(ErrorKind::UnknownToken { .. }) = e.client_api_error_kind() {
|
||||
|
@ -204,6 +204,7 @@ pub fn mock_settings() -> ApplicationSettings {
|
||||
layout_json: PathBuf::new(),
|
||||
session_json: PathBuf::new(),
|
||||
session_json_old: PathBuf::new(),
|
||||
#[cfg(feature = "sled-export")]
|
||||
sled_dir: PathBuf::new(),
|
||||
sqlite_dir: PathBuf::new(),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user