Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions crates/citadel-opds/src/credential_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ impl OpdsCredentialStore {
/// Disk is the source of truth; memory mirrors the last successful disk
/// operation.
pub fn status(&self) -> OpdsCredentialStatus {
let credentials = self
.inner
.credentials
.read()
.expect("OPDS credential store poisoned");
let credentials = self.read();
OpdsCredentialStatus {
configured: credentials.is_some(),
username: credentials
Expand All @@ -96,22 +92,14 @@ impl OpdsCredentialStore {
}

pub fn get(&self) -> Option<StoredOpdsCredentials> {
self.inner
.credentials
.read()
.expect("OPDS credential store poisoned")
.clone()
self.read().clone()
}

pub fn set(&self, credentials: StoredOpdsCredentials) -> io::Result<()> {
if let Some(path) = &self.inner.path {
persist(path, &credentials)?;
}
*self
.inner
.credentials
.write()
.expect("OPDS credential store poisoned") = Some(credentials);
*self.write() = Some(credentials);
Ok(())
}

Expand All @@ -123,11 +111,7 @@ impl OpdsCredentialStore {
Err(error) => return Err(error),
}
}
*self
.inner
.credentials
.write()
.expect("OPDS credential store poisoned") = None;
*self.write() = None;
Ok(())
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/citadel-opds/src/password.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! The generated-password chunk shape and algorithm.

use super::words::WORD_POOL;
use rand_core::{OsRng, RngCore};
use serde::{Deserialize, Serialize};
use serde::Serialize;

/// Returned once when credentials are generated; the plaintext is never
/// stored, so this is the only chance to copy it into a reader.
Expand Down
14 changes: 12 additions & 2 deletions src-tauri/src/libs/calibre/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ pub struct CalibreClientConfig {

#[tauri::command]
#[specta::specta]
pub fn init_client(
pub async fn init_client(
handle: tauri::AppHandle,
state: tauri::State<CitadelState>,
state: tauri::State<'_, CitadelState>,
library_path: String,
) -> Result<CalibreClientConfig, String> {
use tauri::Manager;

// Stop BEFORE the swap: the running server reads live state, so draining
// after the swap would serve the new library under the old share. If the
// new library then fails to open, sharing stays off - the right failure
// direction (better a dead share than a wrong one). Re-opening the
// already-active library keeps sharing.
let same_library = state.get_library_path().as_deref() == Some(library_path.as_str());
if !same_library {
handle.state::<citadel_opds::OpdsService>().stop().await;
}

state.init_library(library_path.clone())?;

// Full-resolution covers are served over the asset protocol straight from
Expand Down
Loading