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