feat #14740: configurable call detection delays
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -115,13 +115,12 @@ pub fn get_call_brief(state: State<'_, AppState>, id: CallId) -> CmdResult<CallB
|
||||
state.call_brief(id)
|
||||
}
|
||||
|
||||
/// Deletes a finished call's audio and row. If that was the last call the
|
||||
/// prompt was waiting on, closes the prompt; otherwise the prompt reloads
|
||||
/// and shows the next one.
|
||||
/// Deletes a finished call's audio and row. Closes the prompt if no call
|
||||
/// waits for it any more; otherwise the prompt reloads and shows the next.
|
||||
#[tauri::command]
|
||||
pub async fn discard_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
||||
blocking(app, move |app| {
|
||||
if app.state::<AppState>().discard_call(id)? == Some(0) {
|
||||
if app.state::<AppState>().discard_call(id)? == 0 {
|
||||
set_window_visible(app, "prompt", false);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+66
-16
@@ -160,7 +160,10 @@ impl AppState {
|
||||
lock(&self.settings).clone()
|
||||
}
|
||||
|
||||
/// Validates, saves and applies the settings; the detector picks up the
|
||||
/// new allowlist and delays immediately.
|
||||
pub fn save_settings(&self, settings: Settings) -> Result<(), String> {
|
||||
settings.validate()?;
|
||||
settings
|
||||
.save(&self.settings_path)
|
||||
.map_err(|e| format!("Einstellungen konnten nicht gespeichert werden: {e}"))?;
|
||||
@@ -363,13 +366,18 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes a decided call out of the prompt queue. Returns how many calls
|
||||
/// are still queued, or `None` if `id` was not queued.
|
||||
/// Takes a decided call out of the prompt queue. Returns the position
|
||||
/// it had, or `None` if `id` was not queued.
|
||||
pub fn remove_queued_prompt(&self, id: CallId) -> Option<usize> {
|
||||
let mut queue = lock(&self.pending_prompts);
|
||||
let index = queue.iter().position(|&queued| queued == id)?;
|
||||
queue.remove(index);
|
||||
Some(queue.len())
|
||||
Some(index)
|
||||
}
|
||||
|
||||
/// How many calls wait for the end-of-call prompt.
|
||||
pub fn prompts_waiting(&self) -> usize {
|
||||
lock(&self.pending_prompts).len()
|
||||
}
|
||||
|
||||
pub fn call_brief(&self, id: CallId) -> Result<CallBrief, String> {
|
||||
@@ -382,9 +390,9 @@ impl AppState {
|
||||
}
|
||||
|
||||
/// Deletes a finished call: both audio files and the row, and takes it
|
||||
/// out of the prompt queue. Returns what
|
||||
/// [`AppState::remove_queued_prompt`] returns.
|
||||
pub fn discard_call(&self, id: CallId) -> Result<Option<usize>, String> {
|
||||
/// out of the prompt queue. Returns how many calls still wait for the
|
||||
/// prompt.
|
||||
pub fn discard_call(&self, id: CallId) -> Result<usize, String> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
.is_some_and(|cur| cur.call_id == id)
|
||||
@@ -408,10 +416,20 @@ impl AppState {
|
||||
Err(e) => return Err(format!("Audiodatei konnte nicht gelöscht werden: {e}")),
|
||||
}
|
||||
}
|
||||
self.store
|
||||
.delete_call(id)
|
||||
.map_err(|e| format!("Gespräch konnte nicht gelöscht werden: {e}"))?;
|
||||
Ok(self.remove_queued_prompt(id))
|
||||
// Unqueue before deleting the row, so the prompt never sees a queued
|
||||
// call whose row is gone; put it back if the delete fails.
|
||||
let position = self.remove_queued_prompt(id);
|
||||
if let Err(e) = self.store.delete_call(id) {
|
||||
if let Some(index) = position {
|
||||
let mut queue = lock(&self.pending_prompts);
|
||||
if !queue.contains(&id) {
|
||||
let index = index.min(queue.len());
|
||||
queue.insert(index, id);
|
||||
}
|
||||
}
|
||||
return Err(format!("Gespräch konnte nicht gelöscht werden: {e}"));
|
||||
}
|
||||
Ok(self.prompts_waiting())
|
||||
}
|
||||
|
||||
/// Records both configured devices into a temporary directory for five
|
||||
@@ -572,9 +590,9 @@ mod tests {
|
||||
assert_eq!(queued(&f), Some((first, 1)));
|
||||
|
||||
// Deciding the first shows the second.
|
||||
assert_eq!(f.state.discard_call(first), Ok(Some(1)));
|
||||
assert_eq!(f.state.discard_call(first), Ok(1));
|
||||
assert_eq!(queued(&f), Some((second, 0)));
|
||||
assert_eq!(f.state.discard_call(second), Ok(Some(0)));
|
||||
assert_eq!(f.state.discard_call(second), Ok(0));
|
||||
assert_eq!(queued(&f), None);
|
||||
}
|
||||
|
||||
@@ -588,9 +606,9 @@ mod tests {
|
||||
f.state.queue_prompt(id);
|
||||
}
|
||||
|
||||
assert_eq!(f.state.discard_call(b), Ok(Some(2)));
|
||||
assert_eq!(f.state.discard_call(b), Ok(2));
|
||||
assert_eq!(queued(&f), Some((a, 1)));
|
||||
assert_eq!(f.state.remove_queued_prompt(a), Some(1));
|
||||
assert_eq!(f.state.remove_queued_prompt(a), Some(0));
|
||||
assert_eq!(queued(&f), Some((c, 0)));
|
||||
assert_eq!(f.state.remove_queued_prompt(a), None);
|
||||
}
|
||||
@@ -612,7 +630,7 @@ mod tests {
|
||||
let (id, mic, out) = finished_call(&f, "a");
|
||||
f.state.queue_prompt(id);
|
||||
|
||||
assert_eq!(f.state.discard_call(id), Ok(Some(0)));
|
||||
assert_eq!(f.state.discard_call(id), Ok(0));
|
||||
assert!(!mic.exists());
|
||||
assert!(!out.exists());
|
||||
assert_eq!(f.state.store.get_call(id).unwrap(), None);
|
||||
@@ -631,8 +649,40 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Missing track files are not an error.
|
||||
assert_eq!(f.state.discard_call(other), Ok(None));
|
||||
assert_eq!(f.state.discard_call(other), Ok(1));
|
||||
assert_eq!(f.state.store.get_call(other).unwrap(), None);
|
||||
assert_eq!(queued(&f), Some((pending, 0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discarding_an_unqueued_call_reports_an_empty_queue() {
|
||||
// The prompt window hides whenever nothing is left, even if the
|
||||
// discarded call had already dropped out of the queue.
|
||||
let f = fixture();
|
||||
let (id, _, _) = finished_call(&f, "a");
|
||||
assert_eq!(f.state.discard_call(id), Ok(0));
|
||||
assert_eq!(f.state.prompts_waiting(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_detection_delays_are_not_saved() {
|
||||
let f = fixture();
|
||||
let invalid = Settings {
|
||||
end_after_secs: 2,
|
||||
..Settings::default()
|
||||
};
|
||||
assert_eq!(
|
||||
f.state.save_settings(invalid),
|
||||
Err("Ende nach: 3–120 Sekunden".to_string())
|
||||
);
|
||||
assert_eq!(f.state.settings(), Settings::default());
|
||||
assert!(!f.dir.path().join("settings.json").exists());
|
||||
|
||||
let valid = Settings {
|
||||
end_after_secs: 30,
|
||||
..Settings::default()
|
||||
};
|
||||
assert_eq!(f.state.save_settings(valid.clone()), Ok(()));
|
||||
assert_eq!(f.state.settings(), valid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user