Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a14f50e4c | ||
|
|
8c47388eee | ||
|
|
a74cfa5864 | ||
|
|
8d757fd639 | ||
|
|
c57eb9511d | ||
|
|
7a45d20f46 | ||
|
|
802a6f81fd | ||
|
|
0ae6ed304f | ||
|
|
183c135b1d | ||
|
|
299c93f8d6 | ||
|
|
36cefaab5f | ||
|
|
697f13e13a | ||
|
|
35e560020c | ||
|
|
3a16c76257 | ||
|
|
d0ece263a2 | ||
|
|
a0f89454f9 | ||
|
|
083edf32a2 |
Generated
+8
-1
@@ -445,10 +445,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "call-recorder"
|
name = "call-recorder"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"http-range",
|
||||||
"log",
|
"log",
|
||||||
"recorder-audio",
|
"recorder-audio",
|
||||||
"recorder-core",
|
"recorder-core",
|
||||||
@@ -1803,6 +1804,12 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http-range"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2149c4b4b83390c71fab669730347d578ec6bdf759f2160c581ad8b8819733b4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "httparse"
|
name = "httparse"
|
||||||
version = "1.10.1"
|
version = "1.10.1"
|
||||||
|
|||||||
@@ -0,0 +1,352 @@
|
|||||||
|
//! Mixes the two 16 kHz mono tracks of a call into one mono track for
|
||||||
|
//! playback.
|
||||||
|
//!
|
||||||
|
//! The tracks are summed at full level and passed through a soft clipper,
|
||||||
|
//! so a passage where only one side speaks keeps its original loudness
|
||||||
|
//! while both sides speaking loudly at once never wraps around or clips
|
||||||
|
//! hard. [`mix_wavs`] streams both files in chunks, so even a long call
|
||||||
|
//! never sits in memory.
|
||||||
|
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::{self, BufReader, ErrorKind};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use hound::{SampleFormat, WavReader, WavSpec, WavWriter};
|
||||||
|
|
||||||
|
use super::wav::SAMPLE_RATE;
|
||||||
|
|
||||||
|
/// Samples read per track and step in [`mix_wavs`] (about one second).
|
||||||
|
const CHUNK_SAMPLES: usize = 16_384;
|
||||||
|
/// Up to this level (half of full scale) the sum passes unchanged; above,
|
||||||
|
/// the soft clipper compresses it towards full scale.
|
||||||
|
const KNEE: f32 = 0.5;
|
||||||
|
|
||||||
|
/// The format of both tracks and of the mixed file.
|
||||||
|
fn spec() -> WavSpec {
|
||||||
|
WavSpec {
|
||||||
|
channels: 1,
|
||||||
|
sample_rate: SAMPLE_RATE,
|
||||||
|
bits_per_sample: 16,
|
||||||
|
sample_format: SampleFormat::Int,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mixes `a` and `b` sample by sample and appends the result to `out`.
|
||||||
|
/// The output is as long as the longer input; the shorter one counts as
|
||||||
|
/// silence after its end. Never clips hard: see [`soft_clip`].
|
||||||
|
pub fn mix_samples(a: &[i16], b: &[i16], out: &mut Vec<i16>) {
|
||||||
|
let len = a.len().max(b.len());
|
||||||
|
out.reserve(len);
|
||||||
|
for i in 0..len {
|
||||||
|
let sum = to_f32(a.get(i).copied().unwrap_or(0)) + to_f32(b.get(i).copied().unwrap_or(0));
|
||||||
|
out.push(to_i16(soft_clip(sum)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_f32(sample: i16) -> f32 {
|
||||||
|
sample as f32 / i16::MAX as f32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_i16(sample: f32) -> i16 {
|
||||||
|
(sample.clamp(-1.0, 1.0) * i16::MAX as f32).round() as i16
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Linear up to [`KNEE`]; above, `tanh` bends the level smoothly (same
|
||||||
|
/// slope at the knee) towards, but never beyond, full scale.
|
||||||
|
fn soft_clip(x: f32) -> f32 {
|
||||||
|
let level = x.abs();
|
||||||
|
if level <= KNEE {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
let room = 1.0 - KNEE;
|
||||||
|
x.signum() * (KNEE + room * ((level - KNEE) / room).tanh())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One source track; `None` if the file is missing or holds no audio.
|
||||||
|
type Track = Option<hound::WavIntoSamples<BufReader<File>, i16>>;
|
||||||
|
|
||||||
|
/// Whether the WAV at `path` holds audio to play: it is a 16 kHz mono
|
||||||
|
/// 16-bit PCM track whose header counts at least one sample. The one rule
|
||||||
|
/// both [`mix_wavs`] and the detail view's "audio available" go by.
|
||||||
|
pub fn has_audio(path: &Path) -> bool {
|
||||||
|
open_track(path).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Opens a track for [`mix_wavs`]; `None` unless it [has audio](has_audio).
|
||||||
|
/// Why an existing file is left out is logged.
|
||||||
|
fn open_track(path: &Path) -> Track {
|
||||||
|
if path.as_os_str().is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let reader = match WavReader::open(path) {
|
||||||
|
Ok(reader) => reader,
|
||||||
|
Err(hound::Error::IoError(e)) if e.kind() == ErrorKind::NotFound => return None,
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("left out {}: {e}", path.display());
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if reader.spec() != spec() {
|
||||||
|
log::warn!("left out {}: not 16 kHz mono 16-bit PCM", path.display());
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if reader.len() == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(reader.into_samples())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reads up to [`CHUNK_SAMPLES`] samples of `track` into `buf` (cleared
|
||||||
|
/// first).
|
||||||
|
fn read_chunk(track: &mut Track, buf: &mut Vec<i16>) -> io::Result<()> {
|
||||||
|
buf.clear();
|
||||||
|
let Some(samples) = track else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
for sample in samples.take(CHUNK_SAMPLES) {
|
||||||
|
buf.push(sample.map_err(|e| io::Error::new(ErrorKind::InvalidData, e))?);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mixes the WAV tracks at `a` and `b` (16 kHz mono 16-bit PCM, as written
|
||||||
|
/// by [`super::TrackWriter`]) into a new WAV at `dest` and returns its
|
||||||
|
/// length in samples. A track without audio ([`has_audio`]: missing,
|
||||||
|
/// empty or not in that format) is left out; with neither track holding
|
||||||
|
/// audio nothing is written and the error is [`ErrorKind::NotFound`].
|
||||||
|
///
|
||||||
|
/// Writes `dest` with a `.part` suffix first and renames it at the end, so
|
||||||
|
/// `dest` is never a half-written file.
|
||||||
|
pub fn mix_wavs(a: &Path, b: &Path, dest: &Path) -> io::Result<u64> {
|
||||||
|
let mut track_a = open_track(a);
|
||||||
|
let mut track_b = open_track(b);
|
||||||
|
if track_a.is_none() && track_b.is_none() {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
ErrorKind::NotFound,
|
||||||
|
"no audio in either track",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut part = dest.as_os_str().to_owned();
|
||||||
|
part.push(".part");
|
||||||
|
let part = Path::new(&part);
|
||||||
|
let result = write_mix(&mut track_a, &mut track_b, part);
|
||||||
|
match result {
|
||||||
|
Ok(samples) => {
|
||||||
|
fs::rename(part, dest)?;
|
||||||
|
Ok(samples)
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let _ = fs::remove_file(part);
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_mix(a: &mut Track, b: &mut Track, path: &Path) -> io::Result<u64> {
|
||||||
|
let mut writer = WavWriter::create(path, spec()).map_err(hound_to_io)?;
|
||||||
|
let (mut buf_a, mut buf_b, mut mixed) = (Vec::new(), Vec::new(), Vec::new());
|
||||||
|
let mut written = 0u64;
|
||||||
|
loop {
|
||||||
|
read_chunk(a, &mut buf_a)?;
|
||||||
|
read_chunk(b, &mut buf_b)?;
|
||||||
|
if buf_a.is_empty() && buf_b.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mixed.clear();
|
||||||
|
mix_samples(&buf_a, &buf_b, &mut mixed);
|
||||||
|
for &sample in &mixed {
|
||||||
|
writer.write_sample(sample).map_err(hound_to_io)?;
|
||||||
|
}
|
||||||
|
written += mixed.len() as u64;
|
||||||
|
}
|
||||||
|
writer.finalize().map_err(hound_to_io)?;
|
||||||
|
Ok(written)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hound_to_io(e: hound::Error) -> io::Error {
|
||||||
|
match e {
|
||||||
|
hound::Error::IoError(e) => e,
|
||||||
|
other => io::Error::other(other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::audio::TrackWriter;
|
||||||
|
|
||||||
|
fn mix(a: &[i16], b: &[i16]) -> Vec<i16> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
mix_samples(a, b, &mut out);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn quiet_samples_of_equal_length_are_summed() {
|
||||||
|
assert_eq!(mix(&[100, -200, 0], &[50, 300, -7]), vec![150, 100, -7]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_longer_track_continues_alone() {
|
||||||
|
assert_eq!(mix(&[1, 2], &[10, 20, 30, 40]), vec![11, 22, 30, 40]);
|
||||||
|
assert_eq!(mix(&[10, 20, 30], &[1]), vec![11, 20, 30]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_empty_track_leaves_the_other_unchanged_up_to_the_knee() {
|
||||||
|
let half = (KNEE * i16::MAX as f32) as i16;
|
||||||
|
let track = [0, 1234, -1234, half, -half, i16::MIN + 1];
|
||||||
|
let mut expected = track.to_vec();
|
||||||
|
// Beyond the knee even a single track is compressed (but stays
|
||||||
|
// loud and keeps its sign).
|
||||||
|
let last = mix(&[], &track)[5];
|
||||||
|
expected[5] = last;
|
||||||
|
assert!(last < -28_000, "{last}");
|
||||||
|
assert_eq!(mix(&[], &track), expected);
|
||||||
|
assert_eq!(mix(&track, &[]), expected);
|
||||||
|
assert_eq!(mix(&[], &[]), Vec::<i16>::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn full_scale_on_both_sides_stays_within_full_scale() {
|
||||||
|
let out = mix(
|
||||||
|
&[i16::MAX, i16::MIN, i16::MAX],
|
||||||
|
&[i16::MAX, i16::MIN, i16::MIN],
|
||||||
|
);
|
||||||
|
// Loud, with the right sign, and softly short of full scale.
|
||||||
|
assert!(out[0] > 30_000 && out[0] < i16::MAX, "{}", out[0]);
|
||||||
|
assert!(out[1] < -30_000 && out[1] > -i16::MAX, "{}", out[1]);
|
||||||
|
// Opposite full-scale samples cancel instead of wrapping around.
|
||||||
|
assert!(out[2].abs() <= 1, "{}", out[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_soft_clip_is_monotonic_and_bounded() {
|
||||||
|
let mut last = -1.0f32;
|
||||||
|
for step in -400..=400 {
|
||||||
|
let x = step as f32 / 200.0; // -2.0 ..= 2.0
|
||||||
|
let y = soft_clip(x);
|
||||||
|
assert!(y >= last, "not monotonic at {x}");
|
||||||
|
assert!(y.abs() < 1.0, "{x} -> {y}");
|
||||||
|
last = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_track(path: &Path, samples: &[f32]) {
|
||||||
|
let mut writer = TrackWriter::create(path).unwrap();
|
||||||
|
writer.write(samples).unwrap();
|
||||||
|
writer.finalize().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read(path: &Path) -> Vec<i16> {
|
||||||
|
WavReader::open(path)
|
||||||
|
.unwrap()
|
||||||
|
.into_samples::<i16>()
|
||||||
|
.map(Result::unwrap)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_files_are_mixed_across_several_chunks() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let (a, b, dest) = (
|
||||||
|
dir.path().join("a.wav"),
|
||||||
|
dir.path().join("b.wav"),
|
||||||
|
dir.path().join("m.wav"),
|
||||||
|
);
|
||||||
|
let long = CHUNK_SAMPLES * 2 + 100;
|
||||||
|
write_track(&a, &vec![0.1; long]);
|
||||||
|
write_track(&b, &vec![0.2; CHUNK_SAMPLES + 7]);
|
||||||
|
|
||||||
|
assert_eq!(mix_wavs(&a, &b, &dest).unwrap(), long as u64);
|
||||||
|
|
||||||
|
let mixed = read(&dest);
|
||||||
|
assert_eq!(mixed.len(), long);
|
||||||
|
let both = to_i16(0.1) + to_i16(0.2);
|
||||||
|
assert!((mixed[0] - both).abs() <= 1);
|
||||||
|
assert!((mixed[CHUNK_SAMPLES + 6] - both).abs() <= 1);
|
||||||
|
assert_eq!(mixed[CHUNK_SAMPLES + 7], to_i16(0.1));
|
||||||
|
assert_eq!(mixed[long - 1], to_i16(0.1));
|
||||||
|
assert!(!dir.path().join("m.wav.part").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_missing_or_empty_file_is_left_out() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let (a, empty, dest) = (
|
||||||
|
dir.path().join("a.wav"),
|
||||||
|
dir.path().join("e.wav"),
|
||||||
|
dir.path().join("m.wav"),
|
||||||
|
);
|
||||||
|
write_track(&a, &[0.25; 10]);
|
||||||
|
write_track(&empty, &[]);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
mix_wavs(&dir.path().join("gone.wav"), &a, &dest).unwrap(),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
assert_eq!(read(&dest), vec![to_i16(0.25); 10]);
|
||||||
|
assert_eq!(mix_wavs(&a, &empty, &dest).unwrap(), 10);
|
||||||
|
assert_eq!(read(&dest), vec![to_i16(0.25); 10]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn without_audio_in_either_file_nothing_is_written() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let (empty, dest) = (dir.path().join("e.wav"), dir.path().join("m.wav"));
|
||||||
|
write_track(&empty, &[]);
|
||||||
|
|
||||||
|
let err = mix_wavs(&empty, &dir.path().join("gone.wav"), &dest).unwrap_err();
|
||||||
|
assert_eq!(err.kind(), ErrorKind::NotFound);
|
||||||
|
assert!(!dest.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_file_that_is_not_a_track_is_left_out() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let (a, junk, other, dest) = (
|
||||||
|
dir.path().join("a.wav"),
|
||||||
|
dir.path().join("j.wav"),
|
||||||
|
dir.path().join("o.wav"),
|
||||||
|
dir.path().join("m.wav"),
|
||||||
|
);
|
||||||
|
write_track(&a, &[0.25; 10]);
|
||||||
|
fs::write(&junk, b"not a wav file at all").unwrap();
|
||||||
|
let stereo = WavSpec {
|
||||||
|
channels: 2,
|
||||||
|
..spec()
|
||||||
|
};
|
||||||
|
let mut writer = WavWriter::create(&other, stereo).unwrap();
|
||||||
|
writer.write_sample(1i16).unwrap();
|
||||||
|
writer.write_sample(1i16).unwrap();
|
||||||
|
writer.finalize().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(mix_wavs(&a, &junk, &dest).unwrap(), 10);
|
||||||
|
assert_eq!(mix_wavs(&other, &a, &dest).unwrap(), 10);
|
||||||
|
let err = mix_wavs(&junk, &other, &dest).unwrap_err();
|
||||||
|
assert_eq!(err.kind(), ErrorKind::NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_track_has_audio_only_with_samples_in_the_track_format() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = |name: &str| dir.path().join(name);
|
||||||
|
assert!(!has_audio(&path("gone.wav")), "missing");
|
||||||
|
assert!(!has_audio(Path::new("")), "no path");
|
||||||
|
write_track(&path("empty.wav"), &[]);
|
||||||
|
assert!(!has_audio(&path("empty.wav")), "header only");
|
||||||
|
// Larger than a header, but its header says it holds nothing.
|
||||||
|
let mut bytes = fs::read(path("empty.wav")).unwrap();
|
||||||
|
bytes.extend([0u8; 100]);
|
||||||
|
fs::write(path("unrepaired.wav"), bytes).unwrap();
|
||||||
|
assert!(
|
||||||
|
!has_audio(&path("unrepaired.wav")),
|
||||||
|
"data not in the header"
|
||||||
|
);
|
||||||
|
fs::write(path("junk.wav"), vec![7u8; 100]).unwrap();
|
||||||
|
assert!(!has_audio(&path("junk.wav")), "not a wav");
|
||||||
|
write_track(&path("one.wav"), &[0.1]);
|
||||||
|
assert!(has_audio(&path("one.wav")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,12 @@ mod conditioner;
|
|||||||
mod flac;
|
mod flac;
|
||||||
mod gap;
|
mod gap;
|
||||||
mod level;
|
mod level;
|
||||||
|
mod mix;
|
||||||
mod wav;
|
mod wav;
|
||||||
|
|
||||||
pub use conditioner::Conditioner;
|
pub use conditioner::Conditioner;
|
||||||
pub use flac::encode_flac;
|
pub use flac::encode_flac;
|
||||||
pub use gap::GapFiller;
|
pub use gap::GapFiller;
|
||||||
pub use level::rms_level;
|
pub use level::rms_level;
|
||||||
pub use wav::{repair_wav, TrackWriter};
|
pub use mix::{has_audio, mix_samples, mix_wavs};
|
||||||
|
pub use wav::{repair_wav, TrackWriter, SAMPLE_RATE};
|
||||||
|
|||||||
+275
-12
@@ -6,6 +6,7 @@ use std::collections::BTreeMap;
|
|||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::corrections::correct_segment_text;
|
||||||
use crate::merge;
|
use crate::merge;
|
||||||
use crate::model::{Call, CallId, CallStatus, Segment, Speaker};
|
use crate::model::{Call, CallId, CallStatus, Segment, Speaker};
|
||||||
|
|
||||||
@@ -18,6 +19,15 @@ pub struct CallListItem {
|
|||||||
/// Whole seconds from start to end; 0 while recording.
|
/// Whole seconds from start to end; 0 while recording.
|
||||||
pub duration_secs: i64,
|
pub duration_secs: i64,
|
||||||
pub status: CallStatus,
|
pub status: CallStatus,
|
||||||
|
/// What the status pill shows and whether the row needs the user's
|
||||||
|
/// attention — see [`ListState`]. Computed from `status` and
|
||||||
|
/// [`uploaded_here`] so the UI does not re-implement the rule.
|
||||||
|
pub list_state: ListState,
|
||||||
|
/// Whether this row needs the user to act on it (the dot in
|
||||||
|
/// `CallList.svelte` and the sidebar header's "N offen" count). Equal
|
||||||
|
/// to `list_state.needs_action()`, kept as its own field so the UI
|
||||||
|
/// does not need to know `ListState`'s variants to filter by it.
|
||||||
|
pub needs_action: bool,
|
||||||
pub interrupted: bool,
|
pub interrupted: bool,
|
||||||
/// The name the user gave the call, if any.
|
/// The name the user gave the call, if any.
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
@@ -28,21 +38,73 @@ pub struct CallListItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CallListItem {
|
impl CallListItem {
|
||||||
pub fn of(call: &Call) -> Self {
|
/// `backend_url` is this build's backend (`crate::backend::BACKEND_URL`
|
||||||
|
/// in the app): an upload recorded for a different one is shown as not
|
||||||
|
/// uploaded at all ([`uploaded_here`]) — e.g. a transcript sent to the
|
||||||
|
/// test backend must not look done to a release build reading the same
|
||||||
|
/// row. Nothing is deleted; the fields are just not shown as set.
|
||||||
|
pub fn of(call: &Call, backend_url: &str) -> Self {
|
||||||
|
let uploaded = uploaded_here(call, backend_url);
|
||||||
|
let list_state = ListState::of(call.status, uploaded);
|
||||||
Self {
|
Self {
|
||||||
id: call.id,
|
id: call.id,
|
||||||
app: call.app.clone(),
|
app: call.app.clone(),
|
||||||
started_at: call.started_at,
|
started_at: call.started_at,
|
||||||
duration_secs: duration_secs(call),
|
duration_secs: duration_secs(call),
|
||||||
status: call.status,
|
status: call.status,
|
||||||
|
list_state,
|
||||||
|
needs_action: list_state.needs_action(),
|
||||||
interrupted: call.interrupted,
|
interrupted: call.interrupted,
|
||||||
title: call.title.clone(),
|
title: call.title.clone(),
|
||||||
crm_transcript_id: call.crm_transcript_id.clone(),
|
crm_transcript_id: if uploaded {
|
||||||
uploaded_at: call.uploaded_at,
|
call.crm_transcript_id.clone()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
uploaded_at: if uploaded { call.uploaded_at } else { None },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What the call list row (and the detail header's pill) shows about a
|
||||||
|
/// call's status. Mirrors [`CallStatus`] one-to-one, except that `Done`
|
||||||
|
/// splits in two: a call is only ever shown as done ("fertig") once its
|
||||||
|
/// transcript has actually reached *this build's* backend ([`uploaded_here`]);
|
||||||
|
/// otherwise — never uploaded, or uploaded to a different backend — it is
|
||||||
|
/// `ReadyToUpload` ("bereit zum Hochladen"), because from this build's
|
||||||
|
/// point of view the CRM has not seen it yet.
|
||||||
|
#[derive(Serialize, Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum ListState {
|
||||||
|
Recording,
|
||||||
|
AwaitingDecision,
|
||||||
|
Processing,
|
||||||
|
Failed,
|
||||||
|
Done,
|
||||||
|
ReadyToUpload,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListState {
|
||||||
|
fn of(status: CallStatus, uploaded_here: bool) -> Self {
|
||||||
|
match status {
|
||||||
|
CallStatus::Recording => ListState::Recording,
|
||||||
|
CallStatus::AwaitingDecision => ListState::AwaitingDecision,
|
||||||
|
CallStatus::Processing => ListState::Processing,
|
||||||
|
CallStatus::Failed => ListState::Failed,
|
||||||
|
CallStatus::Done if uploaded_here => ListState::Done,
|
||||||
|
CallStatus::Done => ListState::ReadyToUpload,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether a row in this state needs the user to act on it: not yet
|
||||||
|
/// transcribed, or transcribed but not uploaded here. Excludes
|
||||||
|
/// `Failed` (already shown in red) and the transient
|
||||||
|
/// `Recording`/`Processing` states.
|
||||||
|
pub fn needs_action(self) -> bool {
|
||||||
|
matches!(self, ListState::AwaitingDecision | ListState::ReadyToUpload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Whole seconds from `started_at` to `ended_at`; 0 while the call has not
|
/// Whole seconds from `started_at` to `ended_at`; 0 while the call has not
|
||||||
/// ended (and never negative).
|
/// ended (and never negative).
|
||||||
pub fn duration_secs(call: &Call) -> i64 {
|
pub fn duration_secs(call: &Call) -> i64 {
|
||||||
@@ -50,6 +112,16 @@ pub fn duration_secs(call: &Call) -> i64 {
|
|||||||
.map_or(0, |end| (end - call.started_at).num_seconds().max(0))
|
.map_or(0, |end| (end - call.started_at).num_seconds().max(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether `call`'s upload belongs to `backend_url`: its
|
||||||
|
/// `crm_transcript_id` is set *and* `crm_base_url` is exactly this
|
||||||
|
/// backend. An upload recorded for a different one (e.g. the test backend,
|
||||||
|
/// read by a release build) counts as not uploaded: the CRM this
|
||||||
|
/// `backend_url` talks to has never seen the transcript, so the UI offers
|
||||||
|
/// the normal upload control again instead of claiming it is done.
|
||||||
|
pub fn uploaded_here(call: &Call, backend_url: &str) -> bool {
|
||||||
|
call.crm_transcript_id.is_some() && call.crm_base_url.as_deref() == Some(backend_url)
|
||||||
|
}
|
||||||
|
|
||||||
/// The selected call's header data: its list row plus the error of a
|
/// The selected call's header data: its list row plus the error of a
|
||||||
/// failed run and when it was transcribed (only a transcribed call can be
|
/// failed run and when it was transcribed (only a transcribed call can be
|
||||||
/// uploaded).
|
/// uploaded).
|
||||||
@@ -100,16 +172,30 @@ pub struct CallDetail {
|
|||||||
/// Whether the transcript is being uploaded right now. Set by the app,
|
/// Whether the transcript is being uploaded right now. Set by the app,
|
||||||
/// which tracks its uploads; `false` from [`CallDetail::of`].
|
/// which tracks its uploads; `false` from [`CallDetail::of`].
|
||||||
pub uploading: bool,
|
pub uploading: bool,
|
||||||
|
/// Whether the call's audio is still on disk to be played
|
||||||
|
/// ([`crate::playback::audio_available`]). Set by the app; `false` from
|
||||||
|
/// [`CallDetail::of`], which does not look at the files.
|
||||||
|
pub audio_available: bool,
|
||||||
|
/// Whether retention deleted the call's audio (as opposed to the files
|
||||||
|
/// being missing for another reason).
|
||||||
|
pub audio_deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallDetail {
|
impl CallDetail {
|
||||||
/// `segments` are the stored ones; `merges` the stored speaker merges
|
/// `segments` are the stored ones; `merges` the stored speaker merges
|
||||||
/// (source key → target key).
|
/// (source key → target key); `backend_url` is this build's backend
|
||||||
|
/// (see [`CallListItem::of`]); `language` is the call-language setting
|
||||||
|
/// in effect now (not necessarily what the call was transcribed with),
|
||||||
|
/// used to apply [`correct_segment_text`] to each segment's text —
|
||||||
|
/// non-destructively, so it also corrects transcripts from before the
|
||||||
|
/// correction existed.
|
||||||
pub fn of(
|
pub fn of(
|
||||||
call: &Call,
|
call: &Call,
|
||||||
segments: &[Segment],
|
segments: &[Segment],
|
||||||
speaker_names: BTreeMap<String, String>,
|
speaker_names: BTreeMap<String, String>,
|
||||||
merges: &BTreeMap<String, String>,
|
merges: &BTreeMap<String, String>,
|
||||||
|
backend_url: &str,
|
||||||
|
language: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let segments = merge::apply_merges(segments, merges)
|
let segments = merge::apply_merges(segments, merges)
|
||||||
.iter()
|
.iter()
|
||||||
@@ -118,18 +204,20 @@ impl CallDetail {
|
|||||||
label: merge::label(&segment.speaker, &speaker_names),
|
label: merge::label(&segment.speaker, &speaker_names),
|
||||||
start: segment.start,
|
start: segment.start,
|
||||||
end: segment.end,
|
end: segment.end,
|
||||||
text: segment.text.clone(),
|
text: correct_segment_text(&segment.text, language),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Self {
|
Self {
|
||||||
call: CallHeader {
|
call: CallHeader {
|
||||||
item: CallListItem::of(call),
|
item: CallListItem::of(call, backend_url),
|
||||||
error: call.error.clone(),
|
error: call.error.clone(),
|
||||||
transcribed_at: call.transcribed_at,
|
transcribed_at: call.transcribed_at,
|
||||||
},
|
},
|
||||||
segments,
|
segments,
|
||||||
merges: merge_views(merges, &speaker_names),
|
merges: merge_views(merges, &speaker_names),
|
||||||
uploading: false,
|
uploading: false,
|
||||||
|
audio_available: false,
|
||||||
|
audio_deleted: call.audio_deleted,
|
||||||
speaker_names,
|
speaker_names,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,6 +322,11 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::model::Speaker;
|
use crate::model::Speaker;
|
||||||
|
|
||||||
|
/// This build's backend, for `CallListItem::of`/`CallDetail::of`.
|
||||||
|
const BACKEND: &str = "https://backend.example";
|
||||||
|
/// A different backend, for the "uploaded elsewhere" cases.
|
||||||
|
const OTHER_BACKEND: &str = "https://other.example";
|
||||||
|
|
||||||
fn at(h: u32, m: u32, s: u32) -> DateTime<Local> {
|
fn at(h: u32, m: u32, s: u32) -> DateTime<Local> {
|
||||||
Local.with_ymd_and_hms(2026, 11, 5, h, m, s).unwrap()
|
Local.with_ymd_and_hms(2026, 11, 5, h, m, s).unwrap()
|
||||||
}
|
}
|
||||||
@@ -253,6 +346,7 @@ mod tests {
|
|||||||
audio_deleted: false,
|
audio_deleted: false,
|
||||||
title: None,
|
title: None,
|
||||||
crm_transcript_id: None,
|
crm_transcript_id: None,
|
||||||
|
crm_base_url: None,
|
||||||
uploaded_at: None,
|
uploaded_at: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,13 +377,15 @@ mod tests {
|
|||||||
c.status = CallStatus::AwaitingDecision;
|
c.status = CallStatus::AwaitingDecision;
|
||||||
c.interrupted = true;
|
c.interrupted = true;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
CallListItem::of(&c),
|
CallListItem::of(&c, BACKEND),
|
||||||
CallListItem {
|
CallListItem {
|
||||||
id: 7,
|
id: 7,
|
||||||
app: "Microsoft Teams".into(),
|
app: "Microsoft Teams".into(),
|
||||||
started_at: at(10, 14, 0),
|
started_at: at(10, 14, 0),
|
||||||
duration_secs: 60,
|
duration_secs: 60,
|
||||||
status: CallStatus::AwaitingDecision,
|
status: CallStatus::AwaitingDecision,
|
||||||
|
list_state: ListState::AwaitingDecision,
|
||||||
|
needs_action: true,
|
||||||
interrupted: true,
|
interrupted: true,
|
||||||
title: None,
|
title: None,
|
||||||
crm_transcript_id: None,
|
crm_transcript_id: None,
|
||||||
@@ -299,13 +395,109 @@ mod tests {
|
|||||||
|
|
||||||
c.title = Some("Angebot Rioja".into());
|
c.title = Some("Angebot Rioja".into());
|
||||||
c.crm_transcript_id = Some("4711".into());
|
c.crm_transcript_id = Some("4711".into());
|
||||||
|
c.crm_base_url = Some(BACKEND.into());
|
||||||
c.uploaded_at = Some(at(11, 0, 0));
|
c.uploaded_at = Some(at(11, 0, 0));
|
||||||
let item = CallListItem::of(&c);
|
let item = CallListItem::of(&c, BACKEND);
|
||||||
assert_eq!(item.title.as_deref(), Some("Angebot Rioja"));
|
assert_eq!(item.title.as_deref(), Some("Angebot Rioja"));
|
||||||
assert_eq!(item.crm_transcript_id.as_deref(), Some("4711"));
|
assert_eq!(item.crm_transcript_id.as_deref(), Some("4711"));
|
||||||
assert_eq!(item.uploaded_at, Some(at(11, 0, 0)));
|
assert_eq!(item.uploaded_at, Some(at(11, 0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn uploaded_here_needs_a_transcript_id_and_a_matching_backend() {
|
||||||
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
assert!(!uploaded_here(&c, BACKEND), "never uploaded");
|
||||||
|
|
||||||
|
c.crm_transcript_id = Some("4711".into());
|
||||||
|
c.crm_base_url = Some(OTHER_BACKEND.into());
|
||||||
|
assert!(
|
||||||
|
!uploaded_here(&c, BACKEND),
|
||||||
|
"uploaded, but to a different backend"
|
||||||
|
);
|
||||||
|
|
||||||
|
c.crm_base_url = Some(BACKEND.into());
|
||||||
|
assert!(uploaded_here(&c, BACKEND));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn done_is_fertig_only_once_uploaded_to_this_backend() {
|
||||||
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
c.status = CallStatus::Done;
|
||||||
|
|
||||||
|
// Never uploaded.
|
||||||
|
assert_eq!(
|
||||||
|
CallListItem::of(&c, BACKEND).list_state,
|
||||||
|
ListState::ReadyToUpload
|
||||||
|
);
|
||||||
|
|
||||||
|
// Uploaded, but to a different backend.
|
||||||
|
c.crm_transcript_id = Some("4711".into());
|
||||||
|
c.crm_base_url = Some(OTHER_BACKEND.into());
|
||||||
|
assert_eq!(
|
||||||
|
CallListItem::of(&c, BACKEND).list_state,
|
||||||
|
ListState::ReadyToUpload
|
||||||
|
);
|
||||||
|
|
||||||
|
// Uploaded to this build's backend.
|
||||||
|
c.crm_base_url = Some(BACKEND.into());
|
||||||
|
assert_eq!(CallListItem::of(&c, BACKEND).list_state, ListState::Done);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn needs_action_marks_awaiting_and_ready_to_upload_only() {
|
||||||
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
|
||||||
|
c.status = CallStatus::AwaitingDecision;
|
||||||
|
assert!(CallListItem::of(&c, BACKEND).needs_action, "awaiting");
|
||||||
|
|
||||||
|
c.status = CallStatus::Done;
|
||||||
|
assert!(
|
||||||
|
CallListItem::of(&c, BACKEND).needs_action,
|
||||||
|
"done, never uploaded"
|
||||||
|
);
|
||||||
|
|
||||||
|
for status in [
|
||||||
|
CallStatus::Processing,
|
||||||
|
CallStatus::Failed,
|
||||||
|
CallStatus::Recording,
|
||||||
|
] {
|
||||||
|
c.status = status;
|
||||||
|
assert!(
|
||||||
|
!CallListItem::of(&c, BACKEND).needs_action,
|
||||||
|
"{status:?} must not show the dot"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.status = CallStatus::Done;
|
||||||
|
c.crm_transcript_id = Some("4711".into());
|
||||||
|
c.crm_base_url = Some(BACKEND.into());
|
||||||
|
assert!(
|
||||||
|
!CallListItem::of(&c, BACKEND).needs_action,
|
||||||
|
"done and uploaded here"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_upload_to_another_backend_is_hidden_from_the_list_item() {
|
||||||
|
// Uploaded to OTHER_BACKEND; this build's backend is BACKEND: the
|
||||||
|
// row still has crm_transcript_id/uploaded_at, but the view must
|
||||||
|
// not show them, so the UI offers the normal upload control again.
|
||||||
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
c.crm_transcript_id = Some("4711".into());
|
||||||
|
c.crm_base_url = Some(OTHER_BACKEND.into());
|
||||||
|
c.uploaded_at = Some(at(11, 0, 0));
|
||||||
|
|
||||||
|
let item = CallListItem::of(&c, BACKEND);
|
||||||
|
assert_eq!(item.crm_transcript_id, None);
|
||||||
|
assert_eq!(item.uploaded_at, None);
|
||||||
|
|
||||||
|
// The same row, read by a build whose backend actually matches:
|
||||||
|
// shown normally.
|
||||||
|
let item = CallListItem::of(&c, OTHER_BACKEND);
|
||||||
|
assert_eq!(item.crm_transcript_id.as_deref(), Some("4711"));
|
||||||
|
assert_eq!(item.uploaded_at, Some(at(11, 0, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn detail_labels_segments_with_renames_and_defaults() {
|
fn detail_labels_segments_with_renames_and_defaults() {
|
||||||
let segments = [
|
let segments = [
|
||||||
@@ -322,6 +514,8 @@ mod tests {
|
|||||||
&segments,
|
&segments,
|
||||||
names.clone(),
|
names.clone(),
|
||||||
&BTreeMap::new(),
|
&BTreeMap::new(),
|
||||||
|
BACKEND,
|
||||||
|
"de",
|
||||||
);
|
);
|
||||||
|
|
||||||
let lines: Vec<_> = detail
|
let lines: Vec<_> = detail
|
||||||
@@ -366,7 +560,14 @@ mod tests {
|
|||||||
("remote:10", "remote:4"),
|
("remote:10", "remote:4"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let detail = CallDetail::of(&call(Some(at(10, 15, 0))), &segments, names, &merges);
|
let detail = CallDetail::of(
|
||||||
|
&call(Some(at(10, 15, 0))),
|
||||||
|
&segments,
|
||||||
|
names,
|
||||||
|
&merges,
|
||||||
|
BACKEND,
|
||||||
|
"de",
|
||||||
|
);
|
||||||
|
|
||||||
let lines: Vec<_> = detail
|
let lines: Vec<_> = detail
|
||||||
.segments
|
.segments
|
||||||
@@ -417,8 +618,15 @@ mod tests {
|
|||||||
c.transcribed_at = Some(at(10, 20, 0));
|
c.transcribed_at = Some(at(10, 20, 0));
|
||||||
let merges = keys(&[("remote:2", "remote:1")]);
|
let merges = keys(&[("remote:2", "remote:1")]);
|
||||||
|
|
||||||
let value =
|
let value = serde_json::to_value(CallDetail::of(
|
||||||
serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges)).unwrap();
|
&c,
|
||||||
|
&[],
|
||||||
|
BTreeMap::new(),
|
||||||
|
&merges,
|
||||||
|
BACKEND,
|
||||||
|
"de",
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
value,
|
value,
|
||||||
@@ -429,6 +637,8 @@ mod tests {
|
|||||||
"started_at": serde_json::to_value(at(10, 14, 0)).unwrap(),
|
"started_at": serde_json::to_value(at(10, 14, 0)).unwrap(),
|
||||||
"duration_secs": 60,
|
"duration_secs": 60,
|
||||||
"status": "failed",
|
"status": "failed",
|
||||||
|
"list_state": "failed",
|
||||||
|
"needs_action": false,
|
||||||
"interrupted": false,
|
"interrupted": false,
|
||||||
"title": "Reklamation",
|
"title": "Reklamation",
|
||||||
"crm_transcript_id": null,
|
"crm_transcript_id": null,
|
||||||
@@ -445,12 +655,30 @@ mod tests {
|
|||||||
"into_label": "Sprecher 1",
|
"into_label": "Sprecher 1",
|
||||||
}],
|
}],
|
||||||
"uploading": false,
|
"uploading": false,
|
||||||
|
"audio_available": false,
|
||||||
|
"audio_deleted": false,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
|
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
|
||||||
CallDetail::of(c, segments, keys(names), &keys(&[("remote:2", "remote:1")]))
|
detail_with_language(c, segments, names, "de")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail_with_language(
|
||||||
|
c: &Call,
|
||||||
|
segments: &[Segment],
|
||||||
|
names: &[(&str, &str)],
|
||||||
|
language: &str,
|
||||||
|
) -> CallDetail {
|
||||||
|
CallDetail::of(
|
||||||
|
c,
|
||||||
|
segments,
|
||||||
|
keys(names),
|
||||||
|
&keys(&[("remote:2", "remote:1")]),
|
||||||
|
BACKEND,
|
||||||
|
language,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -511,4 +739,39 @@ mod tests {
|
|||||||
}
|
}
|
||||||
assert_eq!(NO_TRANSCRIPT, "Kein Transkript zum Hochladen");
|
assert_eq!(NO_TRANSCRIPT, "Kein Transkript zum Hochladen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_whole_segment_mistranscribed_as_english_is_corrected_in_the_detail_view() {
|
||||||
|
let c = call(Some(at(10, 15, 0)));
|
||||||
|
let segments = [
|
||||||
|
segment(Speaker::Me, 0.0, "Cheers!"),
|
||||||
|
segment(Speaker::Remote(3), 3.0, "Perfect."),
|
||||||
|
segment(Speaker::Remote(1), 6.0, "Cheers, see you later."),
|
||||||
|
];
|
||||||
|
|
||||||
|
let detail = detail_with(&c, &segments, &[]);
|
||||||
|
|
||||||
|
let texts: Vec<_> = detail.segments.iter().map(|s| s.text.as_str()).collect();
|
||||||
|
assert_eq!(texts, ["Tschüss!", "Perfekt.", "Cheers, see you later."]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn corrections_are_not_applied_outside_german_calls() {
|
||||||
|
let c = call(Some(at(10, 15, 0)));
|
||||||
|
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||||
|
|
||||||
|
let detail = detail_with_language(&c, &segments, &[], "en");
|
||||||
|
|
||||||
|
assert_eq!(detail.segments[0].text, "Cheers!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_upload_text_uses_the_corrected_segment_text() {
|
||||||
|
let c = call(Some(at(10, 46, 0)));
|
||||||
|
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||||
|
|
||||||
|
let text = detail_with(&c, &segments, &[]).upload_text().unwrap();
|
||||||
|
|
||||||
|
assert!(text.ends_with("Ich: Tschüss!"), "upload text was: {text}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
//! A short, hard-coded list of German short utterances that the
|
||||||
|
//! transcription service sometimes mistranscribes as English when they
|
||||||
|
//! stand alone in an otherwise German call ("Tschüss" → "Cheers!",
|
||||||
|
//! "Perfekt" → "Perfect."). Applied non-destructively wherever a segment's
|
||||||
|
//! text is shown or uploaded (see [`crate::call_view::CallDetail::of`]),
|
||||||
|
//! never to the stored segments themselves — fixing the list later fixes
|
||||||
|
//! already-transcribed calls too.
|
||||||
|
//!
|
||||||
|
//! Not user-editable (yet): a fixed code constant, checked only against a
|
||||||
|
//! segment's *entire* text, so it never touches a short mistranscription
|
||||||
|
//! embedded in a longer sentence.
|
||||||
|
|
||||||
|
/// (mistranscribed English word, correct German word) pairs.
|
||||||
|
const CORRECTIONS: &[(&str, &str)] = &[("Cheers", "Tschüss"), ("Perfect", "Perfekt")];
|
||||||
|
|
||||||
|
/// Returns `text`'s correction if the call's `language` is German (`"de"`)
|
||||||
|
/// and `text` — ignoring surrounding whitespace and one run of trailing
|
||||||
|
/// `. ! ? ,` — case-insensitively equals one of [`CORRECTIONS`]'s source
|
||||||
|
/// words in full; the original trailing punctuation, if any, is kept (e.g.
|
||||||
|
/// "Cheers!" → "Tschüss!"). Otherwise `text` is returned unchanged,
|
||||||
|
/// including when it merely *contains* a source word ("Cheers, see you").
|
||||||
|
pub fn correct_segment_text(text: &str, language: &str) -> String {
|
||||||
|
if language != "de" {
|
||||||
|
return text.to_string();
|
||||||
|
}
|
||||||
|
let trimmed = text.trim();
|
||||||
|
let core = trimmed.trim_end_matches(['.', '!', '?', ',']);
|
||||||
|
let punctuation = &trimmed[core.len()..];
|
||||||
|
match CORRECTIONS
|
||||||
|
.iter()
|
||||||
|
.find(|(wrong, _)| core.eq_ignore_ascii_case(wrong))
|
||||||
|
{
|
||||||
|
Some((_, right)) => format!("{right}{punctuation}"),
|
||||||
|
None => text.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_whole_mistranscribed_utterance_is_corrected_case_insensitively() {
|
||||||
|
assert_eq!(correct_segment_text("Cheers!", "de"), "Tschüss!");
|
||||||
|
assert_eq!(correct_segment_text("cheers", "de"), "Tschüss");
|
||||||
|
assert_eq!(correct_segment_text("CHEERS!", "de"), "Tschüss!");
|
||||||
|
assert_eq!(correct_segment_text("Perfect.", "de"), "Perfekt.");
|
||||||
|
assert_eq!(correct_segment_text("perfect?", "de"), "Perfekt?");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn surrounding_whitespace_is_ignored_for_matching() {
|
||||||
|
assert_eq!(correct_segment_text(" Cheers! ", "de"), "Tschüss!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_mistranscription_inside_a_longer_sentence_is_untouched() {
|
||||||
|
assert_eq!(
|
||||||
|
correct_segment_text("Cheers, see you", "de"),
|
||||||
|
"Cheers, see you"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
correct_segment_text("That was perfect.", "de"),
|
||||||
|
"That was perfect."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn not_applied_outside_german_calls() {
|
||||||
|
assert_eq!(correct_segment_text("Cheers!", "en"), "Cheers!");
|
||||||
|
assert_eq!(correct_segment_text("Cheers!", "auto"), "Cheers!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn text_without_a_match_is_returned_unchanged() {
|
||||||
|
assert_eq!(
|
||||||
|
correct_segment_text("Hallo zusammen.", "de"),
|
||||||
|
"Hallo zusammen."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,13 @@ pub mod audio;
|
|||||||
pub mod backend;
|
pub mod backend;
|
||||||
pub mod call_view;
|
pub mod call_view;
|
||||||
pub mod capture;
|
pub mod capture;
|
||||||
|
pub mod corrections;
|
||||||
pub mod detect;
|
pub mod detect;
|
||||||
pub mod http;
|
pub mod http;
|
||||||
pub mod merge;
|
pub mod merge;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod pipeline;
|
pub mod pipeline;
|
||||||
|
pub mod playback;
|
||||||
pub mod recorder;
|
pub mod recorder;
|
||||||
pub mod retention;
|
pub mod retention;
|
||||||
pub mod secrets;
|
pub mod secrets;
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ pub struct Call {
|
|||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
/// The id the CRM gave the transcript at its last upload.
|
/// The id the CRM gave the transcript at its last upload.
|
||||||
pub crm_transcript_id: Option<String>,
|
pub crm_transcript_id: Option<String>,
|
||||||
|
/// The backend ([`crate::backend`]'s base URL) `crm_transcript_id` was
|
||||||
|
/// uploaded to; `None` if never uploaded. A build whose own backend
|
||||||
|
/// differs (e.g. release reading a row a test build uploaded) does not
|
||||||
|
/// count this as uploaded — see `call_view::uploaded_here`.
|
||||||
|
pub crm_base_url: Option<String>,
|
||||||
/// When the transcript was last uploaded.
|
/// When the transcript was last uploaded.
|
||||||
pub uploaded_at: Option<DateTime<Local>>,
|
pub uploaded_at: Option<DateTime<Local>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ pub struct PipelineOptions {
|
|||||||
/// ISO 639-1 code, or `"auto"`.
|
/// ISO 639-1 code, or `"auto"`.
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: String,
|
pub deepscript_model: String,
|
||||||
|
/// Custom words/names submitted with both tracks (DeepScript's
|
||||||
|
/// `vocabulary` field).
|
||||||
|
pub vocabulary: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Everything a pipeline run can fail with.
|
/// Everything a pipeline run can fail with.
|
||||||
@@ -140,6 +143,7 @@ async fn transcribe(
|
|||||||
language: opts.language.clone(),
|
language: opts.language.clone(),
|
||||||
model: opts.deepscript_model.clone(),
|
model: opts.deepscript_model.clone(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: opts.vocabulary.clone(),
|
||||||
};
|
};
|
||||||
let (mic_opts, out_opts) = (track_opts(true), track_opts(false));
|
let (mic_opts, out_opts) = (track_opts(true), track_opts(false));
|
||||||
let (mic_job, out_job) = tokio::join!(
|
let (mic_job, out_job) = tokio::join!(
|
||||||
@@ -431,6 +435,7 @@ mod tests {
|
|||||||
PipelineOptions {
|
PipelineOptions {
|
||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
deepscript_model: "premium".to_string(),
|
deepscript_model: "premium".to_string(),
|
||||||
|
vocabulary: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,6 +552,7 @@ mod tests {
|
|||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
model: "premium".to_string(),
|
model: "premium".to_string(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: Vec::new(),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
fake.submitted(),
|
fake.submitted(),
|
||||||
@@ -557,6 +563,27 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn pipeline_forwards_the_vocabulary_to_both_tracks() {
|
||||||
|
let f = fixture();
|
||||||
|
let fake = FakeTranscriber::returning(vec![], vec![]);
|
||||||
|
let opts = PipelineOptions {
|
||||||
|
vocabulary: vec!["Tschüss".to_string(), "Euvino".to_string()],
|
||||||
|
..opts()
|
||||||
|
};
|
||||||
|
|
||||||
|
process_call(&f.store, &fake, f.id, &opts, &f.work_dir())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
for (_, submitted) in fake.submitted() {
|
||||||
|
assert_eq!(
|
||||||
|
submitted.vocabulary,
|
||||||
|
vec!["Tschüss".to_string(), "Euvino".to_string()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pipeline_transcription_failure_sets_failed_keeps_audio() {
|
async fn pipeline_transcription_failure_sets_failed_keeps_audio() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
|
|||||||
@@ -0,0 +1,356 @@
|
|||||||
|
//! Playback of a call in the detail view while its audio is still on disk:
|
||||||
|
//! both tracks are mixed into one cached mono WAV
|
||||||
|
//! (`<playback dir>/<id>.wav`), which the app serves to the main window
|
||||||
|
//! only (its `playback` URI scheme). The cache is rebuilt only when a track
|
||||||
|
//! is newer than it, and removed with the call's audio and when the player
|
||||||
|
//! lets go of it.
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{self, ErrorKind};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::audio::{has_audio, mix_wavs, SAMPLE_RATE};
|
||||||
|
use crate::model::{Call, CallId, CallStatus};
|
||||||
|
|
||||||
|
/// The call's audio was deleted (by retention).
|
||||||
|
pub const AUDIO_GONE: &str = "Audio nicht mehr vorhanden";
|
||||||
|
/// Neither track holds audio (files missing or empty), though nothing
|
||||||
|
/// deleted them.
|
||||||
|
pub const AUDIO_MISSING: &str = "Audio nicht vorhanden";
|
||||||
|
/// Mixing failed; the details (with file paths) only go to the log.
|
||||||
|
pub const PREPARE_FAILED: &str = "Audio konnte nicht vorbereitet werden.";
|
||||||
|
pub const RECORDING: &str = "Das Gespräch wird gerade aufgenommen";
|
||||||
|
pub const PROCESSING: &str = "Das Gespräch wird gerade verarbeitet – Wiedergabe danach möglich";
|
||||||
|
|
||||||
|
/// What the UI needs besides the call id (from which it builds the
|
||||||
|
/// `playback` URL): the mix's length.
|
||||||
|
#[derive(Serialize, Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub struct PlaybackInfo {
|
||||||
|
pub duration_secs: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why `call` cannot be played, if it cannot: its tracks are still being
|
||||||
|
/// written (recording) or read for transcription (processing), or its
|
||||||
|
/// audio was deleted.
|
||||||
|
pub fn refusal(call: &Call) -> Option<&'static str> {
|
||||||
|
match call.status {
|
||||||
|
CallStatus::Recording => Some(RECORDING),
|
||||||
|
CallStatus::Processing => Some(PROCESSING),
|
||||||
|
_ if call.audio_deleted => Some(AUDIO_GONE),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `call` still has audio to play: not deleted, and at least one
|
||||||
|
/// track [has audio](has_audio) — the same rule the mix goes by.
|
||||||
|
pub fn audio_available(call: &Call) -> bool {
|
||||||
|
!call.audio_deleted && (has_audio(&call.mic_path) || has_audio(&call.out_path))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether a cached mix last written at `cache` can be reused for tracks
|
||||||
|
/// last written at `sources` (`None`: that track does not exist). It can if
|
||||||
|
/// it exists and is newer than every existing track; with no track left
|
||||||
|
/// there is nothing it could still stand for.
|
||||||
|
pub fn is_fresh(cache: Option<SystemTime>, sources: &[Option<SystemTime>]) -> bool {
|
||||||
|
let Some(cache) = cache else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
let mut any = false;
|
||||||
|
for source in sources.iter().flatten() {
|
||||||
|
if *source >= cache {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
any
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where call `id`'s mix is cached in the playback directory `dir`.
|
||||||
|
pub fn cache_path(dir: &Path, id: CallId) -> PathBuf {
|
||||||
|
dir.join(format!("{id}.wav"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns call `call`'s mix in the playback directory `dir`, building it
|
||||||
|
/// first unless a fresh one is cached ([`is_fresh`]). Refused (see
|
||||||
|
/// [`refusal`]) while the call records or is processed and once its audio
|
||||||
|
/// is gone; a cached mix of a call whose audio is gone is removed. Errors
|
||||||
|
/// are fit for the UI: they never contain a file path.
|
||||||
|
pub fn prepare(call: &Call, dir: &Path) -> Result<PlaybackInfo, String> {
|
||||||
|
let path = cache_path(dir, call.id);
|
||||||
|
if let Some(msg) = refusal(call) {
|
||||||
|
if msg == AUDIO_GONE {
|
||||||
|
remove_cached(dir, call.id);
|
||||||
|
}
|
||||||
|
return Err(msg.to_string());
|
||||||
|
}
|
||||||
|
let sources = [modified(&call.mic_path), modified(&call.out_path)];
|
||||||
|
if is_fresh(modified(&path), &sources) {
|
||||||
|
match duration_secs(&path) {
|
||||||
|
Ok(duration_secs) => return Ok(PlaybackInfo { duration_secs }),
|
||||||
|
Err(e) => log::warn!("call {}: rebuilding unreadable playback file: {e}", call.id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mixed =
|
||||||
|
fs::create_dir_all(dir).and_then(|()| mix_wavs(&call.mic_path, &call.out_path, &path));
|
||||||
|
match mixed {
|
||||||
|
Ok(samples) => Ok(PlaybackInfo {
|
||||||
|
duration_secs: samples as f64 / SAMPLE_RATE as f64,
|
||||||
|
}),
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => {
|
||||||
|
remove_cached(dir, call.id);
|
||||||
|
Err(AUDIO_MISSING.to_string())
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("call {}: could not mix for playback: {e}", call.id);
|
||||||
|
Err(PREPARE_FAILED.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes call `id`'s cached mix, if any (with the call or its audio).
|
||||||
|
/// Failures are logged: the playback directory is emptied at every start.
|
||||||
|
pub fn remove_cached(dir: &Path, id: CallId) {
|
||||||
|
let path = cache_path(dir, id);
|
||||||
|
match fs::remove_file(&path) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => {}
|
||||||
|
Err(e) => log::warn!("could not remove {}: {e}", path.display()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes every cached mix (at startup, so customer audio never lingers
|
||||||
|
/// in the cache).
|
||||||
|
pub fn clear_cache(dir: &Path) -> io::Result<()> {
|
||||||
|
match fs::remove_dir_all(dir) {
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => Ok(()),
|
||||||
|
other => other,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modified(path: &Path) -> Option<SystemTime> {
|
||||||
|
fs::metadata(path).and_then(|m| m.modified()).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn duration_secs(path: &Path) -> Result<f64, hound::Error> {
|
||||||
|
let reader = hound::WavReader::open(path)?;
|
||||||
|
Ok(reader.duration() as f64 / reader.spec().sample_rate as f64)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use chrono::Local;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::audio::TrackWriter;
|
||||||
|
|
||||||
|
fn call(dir: &Path, status: CallStatus) -> Call {
|
||||||
|
Call {
|
||||||
|
id: 7,
|
||||||
|
app: "Microsoft Teams".to_string(),
|
||||||
|
started_at: Local::now(),
|
||||||
|
ended_at: Some(Local::now()),
|
||||||
|
status,
|
||||||
|
interrupted: false,
|
||||||
|
error: None,
|
||||||
|
mic_path: dir.join("7-mic.wav"),
|
||||||
|
out_path: dir.join("7-out.wav"),
|
||||||
|
transcribed_at: None,
|
||||||
|
audio_deleted: false,
|
||||||
|
title: None,
|
||||||
|
crm_transcript_id: None,
|
||||||
|
crm_base_url: None,
|
||||||
|
uploaded_at: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_track(path: &Path, samples: &[f32]) {
|
||||||
|
let mut writer = TrackWriter::create(path).unwrap();
|
||||||
|
writer.write(samples).unwrap();
|
||||||
|
writer.finalize().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A call with one second on the mic and half a second on the output.
|
||||||
|
fn recorded_call(dir: &Path, status: CallStatus) -> Call {
|
||||||
|
let call = call(dir, status);
|
||||||
|
write_track(&call.mic_path, &vec![0.1; 16_000]);
|
||||||
|
write_track(&call.out_path, &vec![0.2; 8_000]);
|
||||||
|
call
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_modified(path: &Path, time: SystemTime) {
|
||||||
|
File::options()
|
||||||
|
.write(true)
|
||||||
|
.open(path)
|
||||||
|
.unwrap()
|
||||||
|
.set_modified(time)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_cache_newer_than_every_track_is_fresh() {
|
||||||
|
let t = SystemTime::UNIX_EPOCH + Duration::from_secs(1_000);
|
||||||
|
let s = Duration::from_secs(1);
|
||||||
|
assert!(is_fresh(Some(t), &[Some(t - s), Some(t - s)]));
|
||||||
|
assert!(is_fresh(Some(t), &[None, Some(t - s)]));
|
||||||
|
assert!(!is_fresh(Some(t), &[Some(t - s), Some(t + s)]));
|
||||||
|
assert!(!is_fresh(Some(t), &[Some(t), Some(t - s)]), "same time");
|
||||||
|
assert!(!is_fresh(None, &[Some(t - s), Some(t - s)]), "no cache");
|
||||||
|
assert!(!is_fresh(Some(t), &[None, None]), "no tracks");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recording_processing_and_deleted_calls_are_refused() {
|
||||||
|
let dir = Path::new("/nonexistent");
|
||||||
|
assert_eq!(refusal(&call(dir, CallStatus::Recording)), Some(RECORDING));
|
||||||
|
assert_eq!(
|
||||||
|
refusal(&call(dir, CallStatus::Processing)),
|
||||||
|
Some(PROCESSING)
|
||||||
|
);
|
||||||
|
let mut deleted = call(dir, CallStatus::Done);
|
||||||
|
deleted.audio_deleted = true;
|
||||||
|
assert_eq!(refusal(&deleted), Some(AUDIO_GONE));
|
||||||
|
for status in [
|
||||||
|
CallStatus::AwaitingDecision,
|
||||||
|
CallStatus::Done,
|
||||||
|
CallStatus::Failed,
|
||||||
|
] {
|
||||||
|
assert_eq!(refusal(&call(dir, status)), None, "{status:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn audio_is_available_while_a_track_holds_audio() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let mut c = call(dir.path(), CallStatus::Done);
|
||||||
|
assert!(!audio_available(&c), "no files");
|
||||||
|
write_track(&c.out_path, &[]);
|
||||||
|
assert!(!audio_available(&c), "header only");
|
||||||
|
write_track(&c.mic_path, &[0.1; 10]);
|
||||||
|
assert!(audio_available(&c));
|
||||||
|
c.audio_deleted = true;
|
||||||
|
assert!(!audio_available(&c), "deleted by retention");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_mix_is_built_once_and_reused() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
let c = recorded_call(dir.path(), CallStatus::Done);
|
||||||
|
|
||||||
|
let info = prepare(&c, &playback).unwrap();
|
||||||
|
let mix = playback.join("7.wav");
|
||||||
|
assert!(mix.exists());
|
||||||
|
assert!((info.duration_secs - 1.0).abs() < 1e-9);
|
||||||
|
|
||||||
|
// Marked as written long ago: a rebuild would show a new time.
|
||||||
|
let old = SystemTime::now() - Duration::from_secs(60);
|
||||||
|
set_modified(&c.mic_path, old - Duration::from_secs(60));
|
||||||
|
set_modified(&c.out_path, old - Duration::from_secs(60));
|
||||||
|
set_modified(&mix, old);
|
||||||
|
assert_eq!(prepare(&c, &playback).unwrap(), info);
|
||||||
|
assert_eq!(modified(&mix), Some(old), "reused, not rebuilt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_mix_is_rebuilt_when_a_track_is_newer() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
let c = recorded_call(dir.path(), CallStatus::AwaitingDecision);
|
||||||
|
prepare(&c, &playback).unwrap();
|
||||||
|
let mix = cache_path(&playback, c.id);
|
||||||
|
let old = SystemTime::now() - Duration::from_secs(60);
|
||||||
|
set_modified(&mix, old);
|
||||||
|
|
||||||
|
// Two seconds now; the file is newer than the cache.
|
||||||
|
write_track(&c.mic_path, &vec![0.1; 32_000]);
|
||||||
|
let second = prepare(&c, &playback).unwrap();
|
||||||
|
assert!((second.duration_secs - 2.0).abs() < 1e-9);
|
||||||
|
assert_ne!(modified(&mix), Some(old));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_call_with_one_track_plays_that_track() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let c = call(dir.path(), CallStatus::Failed);
|
||||||
|
write_track(&c.out_path, &vec![0.2; 4_000]);
|
||||||
|
let info = prepare(&c, &dir.path().join("playback")).unwrap();
|
||||||
|
assert!((info.duration_secs - 0.25).abs() < 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_refused_call_builds_nothing() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
for status in [CallStatus::Recording, CallStatus::Processing] {
|
||||||
|
let c = recorded_call(dir.path(), status);
|
||||||
|
assert!(prepare(&c, &playback).is_err());
|
||||||
|
assert!(!cache_path(&playback, c.id).exists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deleted_audio_removes_the_cached_mix() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
let mut c = recorded_call(dir.path(), CallStatus::Done);
|
||||||
|
prepare(&c, &playback).unwrap();
|
||||||
|
let mix = cache_path(&playback, c.id);
|
||||||
|
|
||||||
|
// Retention deleted the audio.
|
||||||
|
fs::remove_file(&c.mic_path).unwrap();
|
||||||
|
fs::remove_file(&c.out_path).unwrap();
|
||||||
|
c.audio_deleted = true;
|
||||||
|
assert_eq!(prepare(&c, &playback), Err(AUDIO_GONE.to_string()));
|
||||||
|
assert!(!mix.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_files_remove_the_cached_mix() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
let c = recorded_call(dir.path(), CallStatus::Done);
|
||||||
|
prepare(&c, &playback).unwrap();
|
||||||
|
let mix = cache_path(&playback, c.id);
|
||||||
|
|
||||||
|
fs::remove_file(&c.mic_path).unwrap();
|
||||||
|
fs::remove_file(&c.out_path).unwrap();
|
||||||
|
assert_eq!(prepare(&c, &playback), Err(AUDIO_MISSING.to_string()));
|
||||||
|
assert!(!mix.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_failed_mix_reports_no_file_paths() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let c = recorded_call(dir.path(), CallStatus::Done);
|
||||||
|
// The playback directory cannot be created: a file is in the way.
|
||||||
|
let blocked = dir.path().join("playback");
|
||||||
|
fs::write(&blocked, b"").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(prepare(&c, &blocked), Err(PREPARE_FAILED.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_cache_is_removed_per_call_and_cleared_as_a_whole() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let playback = dir.path().join("playback");
|
||||||
|
let c = recorded_call(dir.path(), CallStatus::Done);
|
||||||
|
prepare(&c, &playback).unwrap();
|
||||||
|
fs::write(playback.join("8.wav"), b"other").unwrap();
|
||||||
|
|
||||||
|
remove_cached(&playback, c.id);
|
||||||
|
assert!(!cache_path(&playback, c.id).exists());
|
||||||
|
assert!(playback.join("8.wav").exists());
|
||||||
|
remove_cached(&playback, c.id); // already gone: no error
|
||||||
|
|
||||||
|
clear_cache(&playback).unwrap();
|
||||||
|
assert!(!playback.exists());
|
||||||
|
clear_cache(&playback).unwrap(); // already gone: no error
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,6 +90,7 @@ mod tests {
|
|||||||
audio_deleted: false,
|
audio_deleted: false,
|
||||||
title: None,
|
title: None,
|
||||||
crm_transcript_id: None,
|
crm_transcript_id: None,
|
||||||
|
crm_base_url: None,
|
||||||
uploaded_at: None,
|
uploaded_at: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+181
-6
@@ -27,6 +27,27 @@ pub const START_AFTER_SECS: RangeInclusive<u64> = 1..=30;
|
|||||||
/// splits a call, e.g. when the headset is switched.
|
/// splits a call, e.g. when the headset is switched.
|
||||||
pub const END_AFTER_SECS: RangeInclusive<u64> = 3..=120;
|
pub const END_AFTER_SECS: RangeInclusive<u64> = 3..=120;
|
||||||
|
|
||||||
|
/// The only `deepscript_model` values the settings UI offers (DeepScript's
|
||||||
|
/// OpenAPI spec also lists `"standard"`, not offered here). An older
|
||||||
|
/// settings.json with `"standard"` or anything else falls back to the
|
||||||
|
/// default on load (see [`Settings::load`]) rather than failing.
|
||||||
|
pub const DEEPSCRIPT_MODELS: [&str; 2] = ["premium", "premium_jade"];
|
||||||
|
|
||||||
|
/// Default custom-vocabulary terms: short standalone German words/names
|
||||||
|
/// DeepScript otherwise tends to mistranscribe or drop.
|
||||||
|
const DEFAULT_VOCABULARY: [&str; 5] = ["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"];
|
||||||
|
|
||||||
|
/// Hard cap on the vocabulary list sent with every DeepScript submission.
|
||||||
|
/// DeepScript's OpenAPI spec does not document a limit for the
|
||||||
|
/// per-transcription `vocabulary` field itself (only for its separate,
|
||||||
|
/// *saved* vocabularies, capped there at 500 words — see
|
||||||
|
/// `POST /v1/vocabularies`); these two numbers are ours, chosen to keep
|
||||||
|
/// that field small.
|
||||||
|
pub const MAX_VOCABULARY_TERMS: usize = 200;
|
||||||
|
/// Hard cap on one vocabulary term's length (characters), for the same
|
||||||
|
/// reason as [`MAX_VOCABULARY_TERMS`].
|
||||||
|
pub const MAX_VOCABULARY_TERM_LEN: usize = 60;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
@@ -35,6 +56,12 @@ pub struct Settings {
|
|||||||
pub output_device: Option<String>,
|
pub output_device: Option<String>,
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: String,
|
pub deepscript_model: String,
|
||||||
|
/// Custom words/names submitted with every transcription (DeepScript's
|
||||||
|
/// `vocabulary` field), e.g. names and product terms that are often
|
||||||
|
/// misheard. Normalized on load and on every edit (see
|
||||||
|
/// [`normalize_vocabulary`]): trimmed, blanks dropped, deduplicated
|
||||||
|
/// case-insensitively, order kept.
|
||||||
|
pub vocabulary: Vec<String>,
|
||||||
pub retention_days: u32,
|
pub retention_days: u32,
|
||||||
pub autostart: bool,
|
pub autostart: bool,
|
||||||
pub start_after_secs: u64,
|
pub start_after_secs: u64,
|
||||||
@@ -57,6 +84,7 @@ impl Default for Settings {
|
|||||||
output_device: None,
|
output_device: None,
|
||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
deepscript_model: "premium".to_string(),
|
deepscript_model: "premium".to_string(),
|
||||||
|
vocabulary: DEFAULT_VOCABULARY.iter().map(|s| s.to_string()).collect(),
|
||||||
retention_days: 7,
|
retention_days: 7,
|
||||||
autostart: true,
|
autostart: true,
|
||||||
start_after_secs: 3,
|
start_after_secs: 3,
|
||||||
@@ -85,13 +113,35 @@ impl Settings {
|
|||||||
END_AFTER_SECS.end()
|
END_AFTER_SECS.end()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if !DEEPSCRIPT_MODELS.contains(&self.deepscript_model.as_str()) {
|
||||||
|
return Err(format!(
|
||||||
|
"Transkriptionsmodell: nur {} möglich",
|
||||||
|
DEEPSCRIPT_MODELS.join(" oder ")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if self.vocabulary.len() > MAX_VOCABULARY_TERMS {
|
||||||
|
return Err(format!(
|
||||||
|
"Vokabular: höchstens {MAX_VOCABULARY_TERMS} Begriffe"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if let Some(term) = self
|
||||||
|
.vocabulary
|
||||||
|
.iter()
|
||||||
|
.find(|term| term.chars().count() > MAX_VOCABULARY_TERM_LEN)
|
||||||
|
{
|
||||||
|
return Err(format!(
|
||||||
|
"Vokabular: „{term}“ ist länger als {MAX_VOCABULARY_TERM_LEN} Zeichen"
|
||||||
|
));
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The settings after the user saved `edited` over these: checked, with
|
/// The settings after the user saved `edited` over these: normalized
|
||||||
/// the backend login (which only the app changes) kept, so a settings
|
/// (see [`normalize_vocabulary`]), checked, with the backend login
|
||||||
/// page loaded before a login cannot undo it.
|
/// (which only the app changes) kept, so a settings page loaded before
|
||||||
|
/// a login cannot undo it.
|
||||||
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
||||||
|
edited.vocabulary = normalize_vocabulary(edited.vocabulary);
|
||||||
edited.validate()?;
|
edited.validate()?;
|
||||||
edited.backend_username = self.backend_username.clone();
|
edited.backend_username = self.backend_username.clone();
|
||||||
edited.backend_key_expires_at = self.backend_key_expires_at;
|
edited.backend_key_expires_at = self.backend_key_expires_at;
|
||||||
@@ -100,12 +150,20 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the settings file. A missing or unreadable file yields the
|
/// Reads the settings file. A missing or unreadable file yields the
|
||||||
/// defaults; fields missing from the file take their default value.
|
/// defaults; fields missing from the file take their default value. A
|
||||||
|
/// `deepscript_model` outside [`DEEPSCRIPT_MODELS`] (e.g. an older
|
||||||
|
/// file's `"standard"`) falls back to the default instead of failing;
|
||||||
|
/// `vocabulary` is normalized (see [`normalize_vocabulary`]).
|
||||||
pub fn load(path: &Path) -> Settings {
|
pub fn load(path: &Path) -> Settings {
|
||||||
fs::read_to_string(path)
|
let mut settings: Settings = fs::read_to_string(path)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|json| serde_json::from_str(&json).ok())
|
.and_then(|json| serde_json::from_str(&json).ok())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default();
|
||||||
|
if !DEEPSCRIPT_MODELS.contains(&settings.deepscript_model.as_str()) {
|
||||||
|
settings.deepscript_model = Settings::default().deepscript_model;
|
||||||
|
}
|
||||||
|
settings.vocabulary = normalize_vocabulary(settings.vocabulary);
|
||||||
|
settings
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the settings file (creating its directory), replacing the old
|
/// Writes the settings file (creating its directory), replacing the old
|
||||||
@@ -121,6 +179,23 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trims each term, drops blanks, and deduplicates case-insensitively while
|
||||||
|
/// keeping the first occurrence's spelling and order.
|
||||||
|
fn normalize_vocabulary(terms: Vec<String>) -> Vec<String> {
|
||||||
|
let mut seen = std::collections::HashSet::new();
|
||||||
|
terms
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|term| {
|
||||||
|
let trimmed = term.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
seen.insert(trimmed.to_lowercase())
|
||||||
|
.then(|| trimmed.to_string())
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -143,6 +218,10 @@ mod tests {
|
|||||||
assert_eq!(s.output_device, None);
|
assert_eq!(s.output_device, None);
|
||||||
assert_eq!(s.language, "de");
|
assert_eq!(s.language, "de");
|
||||||
assert_eq!(s.deepscript_model, "premium");
|
assert_eq!(s.deepscript_model, "premium");
|
||||||
|
assert_eq!(
|
||||||
|
s.vocabulary,
|
||||||
|
vec!["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"]
|
||||||
|
);
|
||||||
assert_eq!(s.retention_days, 7);
|
assert_eq!(s.retention_days, 7);
|
||||||
assert!(s.autostart);
|
assert!(s.autostart);
|
||||||
assert_eq!(s.start_after_secs, 3);
|
assert_eq!(s.start_after_secs, 3);
|
||||||
@@ -170,6 +249,32 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_older_files_model_and_a_missing_vocabulary_fall_back_to_the_default() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("settings.json");
|
||||||
|
fs::write(&path, r#"{"deepscript_model": "standard"}"#).unwrap();
|
||||||
|
assert_eq!(Settings::load(&path), Settings::default());
|
||||||
|
|
||||||
|
fs::write(&path, r#"{"deepscript_model": "nonsense"}"#).unwrap();
|
||||||
|
assert_eq!(Settings::load(&path), Settings::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn loading_normalizes_the_stored_vocabulary() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("settings.json");
|
||||||
|
fs::write(
|
||||||
|
&path,
|
||||||
|
r#"{"vocabulary": [" Tschüss ", "", "TSCHÜSS", " ", "Euvino"]}"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Settings::load(&path).vocabulary,
|
||||||
|
vec!["Tschüss".to_string(), "Euvino".to_string()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn logged_in() -> Settings {
|
fn logged_in() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
backend_username: Some("hinrichs".into()),
|
backend_username: Some("hinrichs".into()),
|
||||||
@@ -249,6 +354,76 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn validate_rejects_a_model_outside_the_offered_two() {
|
||||||
|
for model in ["standard", "nonsense", ""] {
|
||||||
|
let s = Settings {
|
||||||
|
deepscript_model: model.to_string(),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
s.validate(),
|
||||||
|
Err("Transkriptionsmodell: nur premium oder premium_jade möglich".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for model in ["premium", "premium_jade"] {
|
||||||
|
let s = Settings {
|
||||||
|
deepscript_model: model.to_string(),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
assert_eq!(s.validate(), Ok(()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn validate_rejects_too_many_vocabulary_terms() {
|
||||||
|
let s = Settings {
|
||||||
|
vocabulary: (0..=MAX_VOCABULARY_TERMS).map(|n| n.to_string()).collect(),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
s.validate(),
|
||||||
|
Err(format!(
|
||||||
|
"Vokabular: höchstens {MAX_VOCABULARY_TERMS} Begriffe"
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn validate_rejects_a_too_long_vocabulary_term() {
|
||||||
|
let s = Settings {
|
||||||
|
vocabulary: vec!["a".repeat(MAX_VOCABULARY_TERM_LEN + 1)],
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
s.validate(),
|
||||||
|
Err(format!(
|
||||||
|
"Vokabular: „{}“ ist länger als {MAX_VOCABULARY_TERM_LEN} Zeichen",
|
||||||
|
"a".repeat(MAX_VOCABULARY_TERM_LEN + 1)
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_edit_normalizes_the_vocabulary_before_validating_and_saving() {
|
||||||
|
let edited = Settings {
|
||||||
|
vocabulary: vec![
|
||||||
|
" Tschüss ".to_string(),
|
||||||
|
"".to_string(),
|
||||||
|
"TSCHÜSS".to_string(),
|
||||||
|
"Kisling".to_string(),
|
||||||
|
],
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let saved = logged_in().edited(edited).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
saved.vocabulary,
|
||||||
|
vec!["Tschüss".to_string(), "Kisling".to_string()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn settings_load_missing_file_returns_default() {
|
fn settings_load_missing_file_returns_default() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
+121
-22
@@ -120,9 +120,19 @@ ALTER TABLE calls ADD COLUMN crm_transcript_id TEXT;
|
|||||||
ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||||
";
|
";
|
||||||
|
|
||||||
|
/// Version 4: which backend an upload belongs to, so a build whose own
|
||||||
|
/// backend differs (see `crate::backend`) does not show someone else's
|
||||||
|
/// upload as done (`call_view::uploaded_here`). Every upload before this
|
||||||
|
/// version only ever went to the test backend (production never had the
|
||||||
|
/// API yet): backfilled here, so existing rows keep meaning what they did.
|
||||||
|
const SCHEMA_V4_SQL: &str = "
|
||||||
|
ALTER TABLE calls ADD COLUMN crm_base_url TEXT;
|
||||||
|
UPDATE calls SET crm_base_url = 'https://test.euvinopro.eu' WHERE crm_transcript_id IS NOT NULL;
|
||||||
|
";
|
||||||
|
|
||||||
/// Schema steps by `PRAGMA user_version`: entry `i` takes a database from
|
/// Schema steps by `PRAGMA user_version`: entry `i` takes a database from
|
||||||
/// version `i` to `i + 1`. A new database runs all of them.
|
/// version `i` to `i + 1`. A new database runs all of them.
|
||||||
const MIGRATIONS: &[&str] = &[SCHEMA_V1_SQL, SCHEMA_V2_SQL, SCHEMA_V3_SQL];
|
const MIGRATIONS: &[&str] = &[SCHEMA_V1_SQL, SCHEMA_V2_SQL, SCHEMA_V3_SQL, SCHEMA_V4_SQL];
|
||||||
|
|
||||||
/// SQLite-backed store for calls and everything derived from them.
|
/// SQLite-backed store for calls and everything derived from them.
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
@@ -361,18 +371,21 @@ impl Store {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Records that the transcript was uploaded to the CRM at `at`, which
|
/// Records that the transcript was uploaded to `crm_base_url` at `at`,
|
||||||
/// gave it `crm_transcript_id`; replaces an earlier upload's record.
|
/// which gave it `crm_transcript_id`; replaces an earlier upload's
|
||||||
|
/// record (even one of another backend — one upload slot per call, see
|
||||||
|
/// `call_view::uploaded_here`).
|
||||||
pub fn set_uploaded(
|
pub fn set_uploaded(
|
||||||
&self,
|
&self,
|
||||||
id: CallId,
|
id: CallId,
|
||||||
crm_transcript_id: &str,
|
crm_transcript_id: &str,
|
||||||
|
crm_base_url: &str,
|
||||||
at: DateTime<Local>,
|
at: DateTime<Local>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let conn = self.conn.lock().unwrap();
|
let conn = self.conn.lock().unwrap();
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"UPDATE calls SET crm_transcript_id = ?1, uploaded_at = ?2 WHERE id = ?3",
|
"UPDATE calls SET crm_transcript_id = ?1, crm_base_url = ?2, uploaded_at = ?3 WHERE id = ?4",
|
||||||
params![crm_transcript_id, dt_to_str(at), id],
|
params![crm_transcript_id, crm_base_url, dt_to_str(at), id],
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -536,9 +549,9 @@ fn ids_with_status(conn: &rusqlite::Connection, status: CallStatus) -> Result<Ve
|
|||||||
Ok(ids)
|
Ok(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SELECT_ALL_CALLS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at FROM calls";
|
const SELECT_ALL_CALLS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url FROM calls";
|
||||||
|
|
||||||
const SELECT_CALL_COLUMNS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at FROM calls WHERE id = ?1";
|
const SELECT_CALL_COLUMNS_SQL: &str = "SELECT id, app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, title, crm_transcript_id, uploaded_at, crm_base_url FROM calls WHERE id = ?1";
|
||||||
|
|
||||||
fn row_to_call(row: &Row) -> Result<Call> {
|
fn row_to_call(row: &Row) -> Result<Call> {
|
||||||
let id: CallId = row.get(0)?;
|
let id: CallId = row.get(0)?;
|
||||||
@@ -555,6 +568,7 @@ fn row_to_call(row: &Row) -> Result<Call> {
|
|||||||
let title: Option<String> = row.get(11)?;
|
let title: Option<String> = row.get(11)?;
|
||||||
let crm_transcript_id: Option<String> = row.get(12)?;
|
let crm_transcript_id: Option<String> = row.get(12)?;
|
||||||
let uploaded_at: Option<String> = row.get(13)?;
|
let uploaded_at: Option<String> = row.get(13)?;
|
||||||
|
let crm_base_url: Option<String> = row.get(14)?;
|
||||||
|
|
||||||
Ok(Call {
|
Ok(Call {
|
||||||
id,
|
id,
|
||||||
@@ -570,6 +584,7 @@ fn row_to_call(row: &Row) -> Result<Call> {
|
|||||||
audio_deleted,
|
audio_deleted,
|
||||||
title,
|
title,
|
||||||
crm_transcript_id,
|
crm_transcript_id,
|
||||||
|
crm_base_url,
|
||||||
uploaded_at: opt_dt_from_str(uploaded_at)?,
|
uploaded_at: opt_dt_from_str(uploaded_at)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -692,6 +707,14 @@ CREATE TABLE speaker_merges (
|
|||||||
into_key TEXT NOT NULL,
|
into_key TEXT NOT NULL,
|
||||||
PRIMARY KEY (call_id, from_key)
|
PRIMARY KEY (call_id, from_key)
|
||||||
);
|
);
|
||||||
|
";
|
||||||
|
|
||||||
|
/// The schema of user_version 3, exactly as release 0.2.0 created it
|
||||||
|
/// (copied from `SCHEMA_V3_SQL` at `HEAD`): version 2 plus these
|
||||||
|
/// statements.
|
||||||
|
const RELEASED_V3_STEP_SQL: &str = "
|
||||||
|
ALTER TABLE calls ADD COLUMN crm_transcript_id TEXT;
|
||||||
|
ALTER TABLE calls ADD COLUMN uploaded_at TEXT;
|
||||||
";
|
";
|
||||||
|
|
||||||
fn user_version(path: &Path) -> i64 {
|
fn user_version(path: &Path) -> i64 {
|
||||||
@@ -715,17 +738,19 @@ CREATE TABLE speaker_merges (
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_new_database_starts_at_version_3() {
|
fn a_new_database_starts_at_version_4() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
let path = dir.path().join("calls.sqlite");
|
let path = dir.path().join("calls.sqlite");
|
||||||
let store = Store::open(&path).unwrap();
|
let store = Store::open(&path).unwrap();
|
||||||
let id = new_call(&store);
|
let id = new_call(&store);
|
||||||
store.set_title(id, Some("Angebot")).unwrap();
|
store.set_title(id, Some("Angebot")).unwrap();
|
||||||
store.set_speaker_merge(id, "remote:2", "remote:1").unwrap();
|
store.set_speaker_merge(id, "remote:2", "remote:1").unwrap();
|
||||||
store.set_uploaded(id, "4711", Local::now()).unwrap();
|
store
|
||||||
|
.set_uploaded(id, "4711", "https://backend.example", Local::now())
|
||||||
|
.unwrap();
|
||||||
drop(store);
|
drop(store);
|
||||||
|
|
||||||
assert_eq!(user_version(&path), 3);
|
assert_eq!(user_version(&path), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -782,7 +807,7 @@ CREATE TABLE speaker_merges (
|
|||||||
store.set_title(1, Some("Lieferung März")).unwrap();
|
store.set_title(1, Some("Lieferung März")).unwrap();
|
||||||
store.set_speaker_merge(1, "remote:2", "remote:1").unwrap();
|
store.set_speaker_merge(1, "remote:2", "remote:1").unwrap();
|
||||||
drop(store);
|
drop(store);
|
||||||
assert_eq!(user_version(&path), 3);
|
assert_eq!(user_version(&path), 4);
|
||||||
let store = Store::open(&path).unwrap();
|
let store = Store::open(&path).unwrap();
|
||||||
let call = store.get_call(1).unwrap().unwrap();
|
let call = store.get_call(1).unwrap().unwrap();
|
||||||
assert_eq!(call.title.as_deref(), Some("Lieferung März"));
|
assert_eq!(call.title.as_deref(), Some("Lieferung März"));
|
||||||
@@ -832,41 +857,115 @@ CREATE TABLE speaker_merges (
|
|||||||
|
|
||||||
// The new columns work, and opening again changes nothing.
|
// The new columns work, and opening again changes nothing.
|
||||||
let uploaded = Local::now();
|
let uploaded = Local::now();
|
||||||
store.set_uploaded(1, "crm-1", uploaded).unwrap();
|
store
|
||||||
|
.set_uploaded(1, "crm-1", "https://backend.example", uploaded)
|
||||||
|
.unwrap();
|
||||||
drop(store);
|
drop(store);
|
||||||
assert_eq!(user_version(&path), 3);
|
assert_eq!(user_version(&path), 4);
|
||||||
let store = Store::open(&path).unwrap();
|
let store = Store::open(&path).unwrap();
|
||||||
let call = store.get_call(1).unwrap().unwrap();
|
let call = store.get_call(1).unwrap().unwrap();
|
||||||
assert_eq!(call.crm_transcript_id.as_deref(), Some("crm-1"));
|
assert_eq!(call.crm_transcript_id.as_deref(), Some("crm-1"));
|
||||||
|
assert_eq!(
|
||||||
|
call.crm_base_url.as_deref(),
|
||||||
|
Some("https://backend.example")
|
||||||
|
);
|
||||||
assert_eq!(call.uploaded_at, Some(uploaded));
|
assert_eq!(call.uploaded_at, Some(uploaded));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn an_upload_is_recorded_and_replaced_by_the_next() {
|
fn a_version_3_database_is_upgraded_backfilling_the_test_backend_for_uploads() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("calls.sqlite");
|
||||||
|
let started = "2026-11-05T10:14:00+01:00";
|
||||||
|
{
|
||||||
|
let conn = rusqlite::Connection::open(&path).unwrap();
|
||||||
|
conn.execute_batch(RELEASED_V1_SCHEMA_SQL).unwrap();
|
||||||
|
conn.execute_batch(RELEASED_V2_STEP_SQL).unwrap();
|
||||||
|
conn.execute_batch(RELEASED_V3_STEP_SQL).unwrap();
|
||||||
|
conn.execute_batch("PRAGMA user_version = 3;").unwrap();
|
||||||
|
// An already-uploaded call (every pre-v4 upload went to the
|
||||||
|
// test backend; production never had the API).
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO calls \
|
||||||
|
(app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, account_id, title, crm_transcript_id, uploaded_at) \
|
||||||
|
VALUES ('Microsoft Teams', ?1, ?1, 'done', 0, NULL, '/rec/1-mic.wav', '/rec/1-out.wav', ?1, 0, NULL, NULL, 'crm-1', ?1)",
|
||||||
|
rusqlite::params![started],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
// A call that was never uploaded.
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO calls \
|
||||||
|
(app, started_at, ended_at, status, interrupted, error, mic_path, out_path, transcribed_at, audio_deleted, account_id, title, crm_transcript_id, uploaded_at) \
|
||||||
|
VALUES ('MicroSIP', ?1, NULL, 'awaiting_decision', 0, NULL, '/rec/2-mic.wav', '/rec/2-out.wav', NULL, 0, NULL, NULL, NULL, NULL)",
|
||||||
|
rusqlite::params![started],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let store = Store::open(&path).unwrap();
|
||||||
|
|
||||||
|
let uploaded = store.get_call(1).unwrap().expect("call kept");
|
||||||
|
assert_eq!(uploaded.crm_transcript_id.as_deref(), Some("crm-1"));
|
||||||
|
assert_eq!(
|
||||||
|
uploaded.crm_base_url.as_deref(),
|
||||||
|
Some("https://test.euvinopro.eu")
|
||||||
|
);
|
||||||
|
|
||||||
|
let not_uploaded = store.get_call(2).unwrap().expect("call kept");
|
||||||
|
assert_eq!(not_uploaded.crm_transcript_id, None);
|
||||||
|
assert_eq!(not_uploaded.crm_base_url, None);
|
||||||
|
|
||||||
|
assert_eq!(user_version(&path), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_upload_is_recorded_and_replaced_by_the_next_even_for_another_backend() {
|
||||||
let store = Store::open_in_memory().unwrap();
|
let store = Store::open_in_memory().unwrap();
|
||||||
let id = new_call(&store);
|
let id = new_call(&store);
|
||||||
let other = new_call(&store);
|
let other = new_call(&store);
|
||||||
let first = Local::now();
|
let first = Local::now();
|
||||||
let second = first + chrono::Duration::minutes(5);
|
let second = first + chrono::Duration::minutes(5);
|
||||||
|
|
||||||
store.set_uploaded(id, "4711", first).unwrap();
|
store
|
||||||
|
.set_uploaded(id, "4711", "https://test.euvinopro.eu", first)
|
||||||
|
.unwrap();
|
||||||
let call = store.get_call(id).unwrap().unwrap();
|
let call = store.get_call(id).unwrap().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(call.crm_transcript_id.as_deref(), call.uploaded_at),
|
(
|
||||||
(Some("4711"), Some(first))
|
call.crm_transcript_id.as_deref(),
|
||||||
|
call.crm_base_url.as_deref(),
|
||||||
|
call.uploaded_at
|
||||||
|
),
|
||||||
|
(Some("4711"), Some("https://test.euvinopro.eu"), Some(first))
|
||||||
);
|
);
|
||||||
|
|
||||||
store.set_uploaded(id, "4712", second).unwrap();
|
// One upload slot per call: a later upload, even to a different
|
||||||
|
// backend, replaces it rather than keeping both.
|
||||||
|
store
|
||||||
|
.set_uploaded(id, "4712", "https://backend.euvinopro.eu", second)
|
||||||
|
.unwrap();
|
||||||
let listed = store.list_calls().unwrap();
|
let listed = store.list_calls().unwrap();
|
||||||
let call = listed.iter().find(|c| c.id == id).unwrap();
|
let call = listed.iter().find(|c| c.id == id).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(call.crm_transcript_id.as_deref(), call.uploaded_at),
|
(
|
||||||
(Some("4712"), Some(second))
|
call.crm_transcript_id.as_deref(),
|
||||||
|
call.crm_base_url.as_deref(),
|
||||||
|
call.uploaded_at
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Some("4712"),
|
||||||
|
Some("https://backend.euvinopro.eu"),
|
||||||
|
Some(second)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
let untouched = store.get_call(other).unwrap().unwrap();
|
let untouched = store.get_call(other).unwrap().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(untouched.crm_transcript_id, untouched.uploaded_at),
|
(
|
||||||
(None, None)
|
untouched.crm_transcript_id,
|
||||||
|
untouched.crm_base_url,
|
||||||
|
untouched.uploaded_at
|
||||||
|
),
|
||||||
|
(None, None, None)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,15 @@ impl Transcriber for DeepScript {
|
|||||||
value: "1".to_string(),
|
value: "1".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if !opts.vocabulary.is_empty() {
|
||||||
|
parts.push(Part::Text {
|
||||||
|
name: "vocabulary".to_string(),
|
||||||
|
// The documented format: "JSON array of custom words, or
|
||||||
|
// comma-separated string."
|
||||||
|
value: serde_json::to_string(&opts.vocabulary)
|
||||||
|
.expect("Vec<String> always serializes"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let req = HttpRequest {
|
let req = HttpRequest {
|
||||||
method: Method::Post,
|
method: Method::Post,
|
||||||
@@ -385,6 +394,7 @@ mod tests {
|
|||||||
language: language.to_string(),
|
language: language.to_string(),
|
||||||
model: model.to_string(),
|
model: model.to_string(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,6 +449,57 @@ mod tests {
|
|||||||
transport.assert_done();
|
transport.assert_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn submit_sends_vocabulary_as_a_json_array_string() {
|
||||||
|
let transport = Arc::new(FakeTransport::new());
|
||||||
|
transport.expect(
|
||||||
|
Method::Post,
|
||||||
|
&format!("{BASE}/transcriptions"),
|
||||||
|
202,
|
||||||
|
r#"{"data":{"id":"job-voc","status":"queued","model":"premium","originalFileName":"mic.flac","createdOn":"2026-01-01T00:00:00Z"}}"#,
|
||||||
|
);
|
||||||
|
let ds = deep_script(&transport);
|
||||||
|
let mut vocab_opts = opts("premium", "de", true);
|
||||||
|
vocab_opts.vocabulary = vec!["Tschüss".to_string(), "Euvino".to_string()];
|
||||||
|
|
||||||
|
ds.submit(Path::new("mic.flac"), &vocab_opts).await.unwrap();
|
||||||
|
|
||||||
|
let requests = transport.requests();
|
||||||
|
let HttpBody::Multipart(parts) = &requests[0].body else {
|
||||||
|
panic!("expected multipart body");
|
||||||
|
};
|
||||||
|
assert!(parts.contains(&Part::Text {
|
||||||
|
name: "vocabulary".to_string(),
|
||||||
|
value: r#"["Tschüss","Euvino"]"#.to_string(),
|
||||||
|
}));
|
||||||
|
transport.assert_done();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn submit_omits_vocabulary_when_empty() {
|
||||||
|
let transport = Arc::new(FakeTransport::new());
|
||||||
|
transport.expect(
|
||||||
|
Method::Post,
|
||||||
|
&format!("{BASE}/transcriptions"),
|
||||||
|
202,
|
||||||
|
r#"{"data":{"id":"job-novoc","status":"queued","model":"premium","originalFileName":"mic.flac","createdOn":"2026-01-01T00:00:00Z"}}"#,
|
||||||
|
);
|
||||||
|
let ds = deep_script(&transport);
|
||||||
|
|
||||||
|
ds.submit(Path::new("mic.flac"), &opts("premium", "de", true))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let requests = transport.requests();
|
||||||
|
let HttpBody::Multipart(parts) = &requests[0].body else {
|
||||||
|
panic!("expected multipart body");
|
||||||
|
};
|
||||||
|
assert!(!parts
|
||||||
|
.iter()
|
||||||
|
.any(|p| matches!(p, Part::Text { name, .. } if name == "vocabulary")));
|
||||||
|
transport.assert_done();
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn submit_without_hint_for_output_track() {
|
async fn submit_without_hint_for_output_track() {
|
||||||
let transport = Arc::new(FakeTransport::new());
|
let transport = Arc::new(FakeTransport::new());
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ pub struct TranscribeOptions {
|
|||||||
/// the user) — the output track may have several, so this is left
|
/// the user) — the output track may have several, so this is left
|
||||||
/// unset there.
|
/// unset there.
|
||||||
pub single_speaker: bool,
|
pub single_speaker: bool,
|
||||||
|
/// Custom words/names to bias the transcription towards (DeepScript's
|
||||||
|
/// `vocabulary` field); empty omits the field entirely.
|
||||||
|
pub vocabulary: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads an audio file to a remote speech-to-text service, waits for the
|
/// Uploads an audio file to a remote speech-to-text service, waits for the
|
||||||
|
|||||||
+4
-4
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.4",
|
||||||
"pub_date": "2026-11-06T14:19:53Z",
|
"pub_date": "2026-11-10T11:50:14Z",
|
||||||
"platforms": {
|
"platforms": {
|
||||||
"windows-x86_64": {
|
"windows-x86_64": {
|
||||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUtlUG9ZajRMcmFHb0dxNG1OM1lWZEExbzhsSjYzdUJxY1NrY2xERmRGbGJEV3c0UWRjdmVuaHFtWXlzYVU2alFJY0k4V1hoZ1FWdDVNV0xkclRQV2c0PQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzkzOTc0NzYxCWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMi4wX3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjIuMApna2tpeVdYMkhDU2d4ZjAwVTJaQjBBMG0yL010V2xIc3Awc0QzOXJsK2lmUi9oM1hwWmlvL2dNdFQzVzQrTys1ZnNmZHpXM0JicTRzd1d2MXp5YjhEQT09Cg==",
|
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUJzeVppQWszcm5oN2s1Q2xIenE4U0lUWkhKbEVhVncyZkhtZzFPeFdjajVqOXRuZCswSVhhVHlhenJhL2Z5UzYwbFFRWUVQbDJPZmtWZm5MUkNvV1FZPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzk0MzExMzkxCWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMi40X3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjIuNApmOGpXV2pWb1Fsem9lUlpVYmtoSFdlU2ovSGtYdDNINnlSa3A2Qm5WL0VDeDdVdldLWnlzb3hxOEtCRm1BUEtnYXNNaUk2ZUhZUCt3Vm9Ua0tLeGhDUT09Cg==",
|
||||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.2.0/Gespraechsrekorder_0.2.0_x64-setup.exe"
|
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.2.4/Gespraechsrekorder_0.2.4_x64-setup.exe"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "call-recorder"
|
name = "call-recorder"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
description = "Gesprächsrekorder desktop app"
|
description = "Gesprächsrekorder desktop app"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -30,3 +30,4 @@ tauri-plugin-updater = "2"
|
|||||||
tauri-plugin-opener = "2"
|
tauri-plugin-opener = "2"
|
||||||
tokio = { version = "1", features = ["sync"] }
|
tokio = { version = "1", features = ["sync"] }
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
http-range = "0.1.6"
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ use crate::state::AppState;
|
|||||||
|
|
||||||
// The backend this build talks to: the one place to change it. It is not a
|
// The backend this build talks to: the one place to change it. It is not a
|
||||||
// setting; a key created on one backend is never sent to another.
|
// setting; a key created on one backend is never sent to another.
|
||||||
/// Release builds. Switch to "https://backend.euvinopro.eu" here, then
|
/// Release builds: the production euvino admin backend.
|
||||||
/// release, once that backend is live.
|
pub(crate) const RELEASE_BACKEND_URL: &str = "https://backend.euvinopro.eu";
|
||||||
const RELEASE_BACKEND_URL: &str = "https://test.euvinopro.eu";
|
/// Debug builds (`cargo tauri dev`) always use the test backend, never the
|
||||||
/// Debug builds (`cargo tauri dev`) always use the test backend.
|
/// production one. `pub(crate)`: `state.rs` tests the exact test-backend →
|
||||||
const DEV_BACKEND_URL: &str = "https://test.euvinopro.eu";
|
/// release-backend transition against this value (a key bound to one must
|
||||||
|
/// never work for the other).
|
||||||
|
pub(crate) const DEV_BACKEND_URL: &str = "https://test.euvinopro.eu";
|
||||||
/// The backend of this build (no trailing slash).
|
/// The backend of this build (no trailing slash).
|
||||||
pub const BACKEND_URL: &str = if cfg!(debug_assertions) {
|
pub const BACKEND_URL: &str = if cfg!(debug_assertions) {
|
||||||
DEV_BACKEND_URL
|
DEV_BACKEND_URL
|
||||||
@@ -235,7 +237,22 @@ async fn upload(app: &AppHandle, state: &AppState, id: CallId) -> CmdResult<()>
|
|||||||
.await
|
.await
|
||||||
.inspect_err(|e| log::warn!("call {id}: upload failed: {e}"))?;
|
.inspect_err(|e| log::warn!("call {id}: upload failed: {e}"))?;
|
||||||
log::info!("call {id}: transcript uploaded (CRM id {crm_id})");
|
log::info!("call {id}: transcript uploaded (CRM id {crm_id})");
|
||||||
state.mark_uploaded(id, &crm_id)
|
if let Err(e) = state.mark_uploaded(id, &crm_id) {
|
||||||
|
// The CRM already has it: a retry must never send it again, even
|
||||||
|
// though the row itself still shows no crm_transcript_id.
|
||||||
|
state.note_upload_confirmed_but_unsaved(id);
|
||||||
|
log::error!("call {id}: uploaded (CRM id {crm_id}) but could not save locally: {e}");
|
||||||
|
return Err(unsaved_upload_message(&crm_id, &e));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Message for an upload that reached the CRM (`crm_id`) but whose local
|
||||||
|
/// record (`mark_uploaded`) failed with `e`: names the CRM id so the user
|
||||||
|
/// can find it there, and says plainly not to upload the call again (the
|
||||||
|
/// app also refuses on its own, see `AppState::note_upload_confirmed_but_unsaved`).
|
||||||
|
fn unsaved_upload_message(crm_id: &str, e: &str) -> String {
|
||||||
|
format!("Hochgeladen (ID {crm_id}), aber lokal nicht gespeichert: {e} – nicht erneut hochladen")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Login`] through the login window, for the upload.
|
/// [`Login`] through the login window, for the upload.
|
||||||
@@ -446,6 +463,17 @@ mod tests {
|
|||||||
assert!(!url.ends_with('/'), "{url}");
|
assert!(!url.ends_with('/'), "{url}");
|
||||||
assert!(url.starts_with("https://"), "{url}");
|
assert!(url.starts_with("https://"), "{url}");
|
||||||
}
|
}
|
||||||
|
// Release and dev talk to different backends: a key from one must
|
||||||
|
// never be usable on the other (see AppState::backend_key).
|
||||||
|
assert_ne!(RELEASE_BACKEND_URL, DEV_BACKEND_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_unsaved_upload_message_names_the_crm_id_and_warns_against_retrying() {
|
||||||
|
assert_eq!(
|
||||||
|
unsaved_upload_message("4711", "disk full"),
|
||||||
|
"Hochgeladen (ID 4711), aber lokal nicht gespeichert: disk full – nicht erneut hochladen"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ use tauri_plugin_autostart::ManagerExt;
|
|||||||
|
|
||||||
use crate::processing;
|
use crate::processing;
|
||||||
use crate::state::{
|
use crate::state::{
|
||||||
AppState, CallBrief, DeviceLevels, DiscardError, Ended, PendingPrompt, RecordingState,
|
AppState, CallBrief, DeviceLevels, DiscardError, Ended, PendingPrompt, PreparedPlayback,
|
||||||
|
RecordingState,
|
||||||
};
|
};
|
||||||
|
|
||||||
const LEVELS_INTERVAL: Duration = Duration::from_millis(100);
|
const LEVELS_INTERVAL: Duration = Duration::from_millis(100);
|
||||||
@@ -208,6 +209,25 @@ pub fn rename_call(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mixes the call's two tracks into one file to play in the detail view
|
||||||
|
/// (or reuses the cached mix); the main window plays it from the
|
||||||
|
/// `playback` scheme ([`crate::playback`]).
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn prepare_playback(app: AppHandle, id: CallId) -> CmdResult<PreparedPlayback> {
|
||||||
|
blocking(app, move |app| app.state::<AppState>().prepare_playback(id)).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The player is done with the mix of `lease`: it is removed from disk
|
||||||
|
/// unless a newer player of the same call holds it.
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn release_playback(app: AppHandle, id: CallId, lease: u64) -> CmdResult<()> {
|
||||||
|
blocking(app, move |app| {
|
||||||
|
app.state::<AppState>().release_playback(id, lease);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
/// Deletes a finished call's audio and row. Closes the prompt if no call
|
/// 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.
|
/// waits for it any more; otherwise the prompt reloads and shows the next.
|
||||||
/// While its DeepScript jobs are still on record, nothing is deleted and a
|
/// While its DeepScript jobs are still on record, nothing is deleted and a
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
mod backend;
|
mod backend;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod detection;
|
mod detection;
|
||||||
|
mod playback;
|
||||||
mod processing;
|
mod processing;
|
||||||
mod state;
|
mod state;
|
||||||
mod tray;
|
mod tray;
|
||||||
@@ -43,6 +44,21 @@ pub fn run() {
|
|||||||
.open_js_links_on_click(false)
|
.open_js_links_on_click(false)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
|
// A call's mix for the player: only for the main window, whatever
|
||||||
|
// other webviews (the remote backend login) ask for.
|
||||||
|
.register_asynchronous_uri_scheme_protocol(playback::SCHEME, |ctx, request, responder| {
|
||||||
|
let webview = ctx.webview_label().to_string();
|
||||||
|
let dir = ctx
|
||||||
|
.app_handle()
|
||||||
|
.try_state::<AppState>()
|
||||||
|
.map(|state| state.playback_dir().to_path_buf());
|
||||||
|
tauri::async_runtime::spawn_blocking(move || {
|
||||||
|
responder.respond(match dir {
|
||||||
|
Some(dir) => playback::respond(&webview, &request, &dir),
|
||||||
|
None => playback::unavailable(),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
// Release builds log to a file in the app log directory (on
|
// Release builds log to a file in the app log directory (on
|
||||||
// Windows %LOCALAPPDATA%\eu.euvino.callrecorder\logs), debug
|
// Windows %LOCALAPPDATA%\eu.euvino.callrecorder\logs), debug
|
||||||
@@ -72,6 +88,8 @@ pub fn run() {
|
|||||||
|
|
||||||
let data_dir = app.path().app_data_dir()?;
|
let data_dir = app.path().app_data_dir()?;
|
||||||
let config_dir = app.path().app_config_dir()?;
|
let config_dir = app.path().app_config_dir()?;
|
||||||
|
// Served to the main window only, by the `playback` scheme.
|
||||||
|
let playback_dir = app.path().app_cache_dir()?.join("playback");
|
||||||
std::fs::create_dir_all(&data_dir)?;
|
std::fs::create_dir_all(&data_dir)?;
|
||||||
let store = Store::open(&data_dir.join("calls.sqlite"))?;
|
let store = Store::open(&data_dir.join("calls.sqlite"))?;
|
||||||
let recovery = pipeline::recover_on_startup(&store)?;
|
let recovery = pipeline::recover_on_startup(&store)?;
|
||||||
@@ -82,6 +100,7 @@ pub fn run() {
|
|||||||
Box::new(KeyringSecrets),
|
Box::new(KeyringSecrets),
|
||||||
config_dir.join("settings.json"),
|
config_dir.join("settings.json"),
|
||||||
data_dir.join("recordings"),
|
data_dir.join("recordings"),
|
||||||
|
playback_dir,
|
||||||
);
|
);
|
||||||
let leftover_jobs = state.store.calls_with_remote_jobs().unwrap_or_else(|e| {
|
let leftover_jobs = state.store.calls_with_remote_jobs().unwrap_or_else(|e| {
|
||||||
log::error!("could not read leftover remote jobs: {e}");
|
log::error!("could not read leftover remote jobs: {e}");
|
||||||
@@ -96,6 +115,8 @@ pub fn run() {
|
|||||||
std::thread::spawn(KeyringSecrets::remove_unused_keys);
|
std::thread::spawn(KeyringSecrets::remove_unused_keys);
|
||||||
// Before anything can start a run.
|
// Before anything can start a run.
|
||||||
processing::clear_upload_dir(app.handle());
|
processing::clear_upload_dir(app.handle());
|
||||||
|
// Before any window can ask for a mix.
|
||||||
|
state.clear_playback_cache();
|
||||||
app.manage(state);
|
app.manage(state);
|
||||||
app.manage(PendingUpdate::default());
|
app.manage(PendingUpdate::default());
|
||||||
app.manage(UpdateSchedule::default());
|
app.manage(UpdateSchedule::default());
|
||||||
@@ -154,6 +175,8 @@ pub fn run() {
|
|||||||
commands::merge_speakers,
|
commands::merge_speakers,
|
||||||
commands::unmerge_speaker,
|
commands::unmerge_speaker,
|
||||||
commands::rename_call,
|
commands::rename_call,
|
||||||
|
commands::prepare_playback,
|
||||||
|
commands::release_playback,
|
||||||
backend::backend_server,
|
backend::backend_server,
|
||||||
backend::backend_status,
|
backend::backend_status,
|
||||||
backend::backend_login,
|
backend::backend_login,
|
||||||
|
|||||||
@@ -0,0 +1,293 @@
|
|||||||
|
//! The `playback` URI scheme: serves a call's cached mix
|
||||||
|
//! ([`recorder_core::playback`]) to the main window, and to no other
|
||||||
|
//! webview — the backend-login window shows a remote page, which must
|
||||||
|
//! never read customer audio.
|
||||||
|
//!
|
||||||
|
//! The URL carries only the call id: `playback://localhost/<id>` on Linux
|
||||||
|
//! and macOS, `http://playback.localhost/<id>` on Windows (what the UI's
|
||||||
|
//! `convertFileSrc(id, 'playback')` builds). Range requests are answered
|
||||||
|
//! so the player can seek without loading the whole file.
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, ErrorKind, Read, Seek, SeekFrom};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use http_range::HttpRange;
|
||||||
|
use recorder_core::model::CallId;
|
||||||
|
use recorder_core::playback::cache_path;
|
||||||
|
use tauri::http::header::{
|
||||||
|
ACCEPT_RANGES, ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS, CACHE_CONTROL,
|
||||||
|
CONTENT_LENGTH, CONTENT_RANGE, CONTENT_TYPE, RANGE,
|
||||||
|
};
|
||||||
|
use tauri::http::{response, Method, Request, Response, StatusCode};
|
||||||
|
|
||||||
|
/// The scheme's name (see the module docs for its URLs).
|
||||||
|
pub const SCHEME: &str = "playback";
|
||||||
|
/// The only webview the scheme answers.
|
||||||
|
pub const PLAYER_WEBVIEW: &str = "main";
|
||||||
|
/// The most bytes one range response carries (like Tauri's asset protocol).
|
||||||
|
const MAX_RANGE_LEN: u64 = 1024 * 1024;
|
||||||
|
|
||||||
|
/// Answers `request` from webview `webview` with call `<id>`'s mix in the
|
||||||
|
/// playback directory `dir`: 403 for any webview but the main window, 404
|
||||||
|
/// for anything but a plain numeric id or a mix that is not there, 206 for
|
||||||
|
/// a satisfiable range (at most [`MAX_RANGE_LEN`] bytes), 416 otherwise.
|
||||||
|
pub fn respond(webview: &str, request: &Request<Vec<u8>>, dir: &Path) -> Response<Vec<u8>> {
|
||||||
|
if webview != PLAYER_WEBVIEW {
|
||||||
|
log::warn!("playback refused to webview {webview}");
|
||||||
|
return empty(StatusCode::FORBIDDEN);
|
||||||
|
}
|
||||||
|
let method = request.method();
|
||||||
|
if method != Method::GET && method != Method::HEAD {
|
||||||
|
return empty(StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
}
|
||||||
|
let Some(id) = call_id(request.uri().path()) else {
|
||||||
|
return empty(StatusCode::NOT_FOUND);
|
||||||
|
};
|
||||||
|
let range = request
|
||||||
|
.headers()
|
||||||
|
.get(RANGE)
|
||||||
|
.map(|value| value.to_str().unwrap_or_default());
|
||||||
|
match serve(&cache_path(dir, id), range, method == Method::HEAD) {
|
||||||
|
Ok(response) => response,
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => empty(StatusCode::NOT_FOUND),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("call {id}: could not serve the playback file: {e}");
|
||||||
|
empty(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The answer while the app state is not set up yet (no window can play
|
||||||
|
/// before it is, so this is never expected).
|
||||||
|
pub fn unavailable() -> Response<Vec<u8>> {
|
||||||
|
empty(StatusCode::SERVICE_UNAVAILABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The call id of a request path: exactly `/<digits>`.
|
||||||
|
fn call_id(path: &str) -> Option<CallId> {
|
||||||
|
let digits = path.strip_prefix('/')?;
|
||||||
|
if digits.is_empty() || !digits.bytes().all(|b| b.is_ascii_digit()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
digits.parse().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn serve(path: &Path, range: Option<&str>, head: bool) -> io::Result<Response<Vec<u8>>> {
|
||||||
|
let mut file = File::open(path)?;
|
||||||
|
let len = file.metadata()?.len();
|
||||||
|
let builder = headers();
|
||||||
|
let Some(range) = range else {
|
||||||
|
let mut body = Vec::new();
|
||||||
|
if !head {
|
||||||
|
file.read_to_end(&mut body)?;
|
||||||
|
}
|
||||||
|
return Ok(build(builder.header(CONTENT_LENGTH, len), body));
|
||||||
|
};
|
||||||
|
// A media element asks for one range at a time; of several, the first.
|
||||||
|
let Some(range) = HttpRange::parse(range, len)
|
||||||
|
.ok()
|
||||||
|
.and_then(|r| r.first().copied())
|
||||||
|
else {
|
||||||
|
return Ok(build(
|
||||||
|
builder
|
||||||
|
.status(StatusCode::RANGE_NOT_SATISFIABLE)
|
||||||
|
.header(CONTENT_RANGE, format!("bytes */{len}")),
|
||||||
|
Vec::new(),
|
||||||
|
));
|
||||||
|
};
|
||||||
|
let start = range.start;
|
||||||
|
let count = range.length.min(MAX_RANGE_LEN);
|
||||||
|
let mut body = Vec::new();
|
||||||
|
if !head {
|
||||||
|
file.seek(SeekFrom::Start(start))?;
|
||||||
|
file.take(count).read_to_end(&mut body)?;
|
||||||
|
}
|
||||||
|
Ok(build(
|
||||||
|
builder
|
||||||
|
.status(StatusCode::PARTIAL_CONTENT)
|
||||||
|
.header(
|
||||||
|
CONTENT_RANGE,
|
||||||
|
format!("bytes {start}-{}/{len}", start + count - 1),
|
||||||
|
)
|
||||||
|
.header(CONTENT_LENGTH, count),
|
||||||
|
body,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Headers of every answer that carries the mix. Any origin may read it:
|
||||||
|
/// only the main window's own page can reach the scheme at all (the
|
||||||
|
/// webview check above), and on Linux it fetches the mix cross-origin.
|
||||||
|
fn headers() -> response::Builder {
|
||||||
|
Response::builder()
|
||||||
|
.header(CONTENT_TYPE, "audio/wav")
|
||||||
|
.header(CACHE_CONTROL, "no-store")
|
||||||
|
.header(ACCEPT_RANGES, "bytes")
|
||||||
|
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
|
||||||
|
.header(ACCESS_CONTROL_EXPOSE_HEADERS, "content-range")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build(builder: response::Builder, body: Vec<u8>) -> Response<Vec<u8>> {
|
||||||
|
builder
|
||||||
|
.body(body)
|
||||||
|
.unwrap_or_else(|_| empty(StatusCode::INTERNAL_SERVER_ERROR))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn empty(status: StatusCode) -> Response<Vec<u8>> {
|
||||||
|
let mut response = Response::new(Vec::new());
|
||||||
|
*response.status_mut() = status;
|
||||||
|
response
|
||||||
|
.headers_mut()
|
||||||
|
.insert(CACHE_CONTROL, "no-store".parse().unwrap());
|
||||||
|
response
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// A playback directory with a 10-byte "mix" for call 7.
|
||||||
|
fn dir() -> tempfile::TempDir {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
fs::write(cache_path(dir.path(), 7), b"0123456789").unwrap();
|
||||||
|
dir
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get(uri: &str, range: Option<&str>) -> Request<Vec<u8>> {
|
||||||
|
let mut builder = Request::builder().uri(uri);
|
||||||
|
if let Some(range) = range {
|
||||||
|
builder = builder.header(RANGE, range);
|
||||||
|
}
|
||||||
|
builder.body(Vec::new()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn only_the_main_window_gets_the_mix() {
|
||||||
|
let dir = dir();
|
||||||
|
let request = get("playback://localhost/7", None);
|
||||||
|
for webview in ["backend-login", "prompt", "recorder", "", "Main"] {
|
||||||
|
let response = respond(webview, &request, dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::FORBIDDEN, "{webview}");
|
||||||
|
assert!(response.body().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = respond("main", &request, dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
|
assert_eq!(response.body(), b"0123456789");
|
||||||
|
assert_eq!(response.headers()[CONTENT_TYPE], "audio/wav");
|
||||||
|
assert_eq!(response.headers()[CACHE_CONTROL], "no-store");
|
||||||
|
assert_eq!(response.headers()[CONTENT_LENGTH], "10");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn both_platform_url_forms_name_the_call() {
|
||||||
|
let dir = dir();
|
||||||
|
for uri in ["playback://localhost/7", "http://playback.localhost/7"] {
|
||||||
|
let response = respond("main", &get(uri, None), dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::OK, "{uri}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nothing_but_a_numeric_call_id_is_served() {
|
||||||
|
let dir = dir();
|
||||||
|
fs::write(dir.path().join("secret.wav"), b"x").unwrap();
|
||||||
|
fs::write(dir.path().join("7.wav.part"), b"x").unwrap();
|
||||||
|
for path in [
|
||||||
|
"/",
|
||||||
|
"/7.wav",
|
||||||
|
"/secret",
|
||||||
|
"/../7",
|
||||||
|
"/%2e%2e%2f7",
|
||||||
|
"/7/",
|
||||||
|
"/7.wav.part",
|
||||||
|
"/-7",
|
||||||
|
"/+7",
|
||||||
|
"/%EF%BC%97",
|
||||||
|
"/99999999999999999999999",
|
||||||
|
"/8",
|
||||||
|
] {
|
||||||
|
let request = get(&format!("playback://localhost{path}"), None);
|
||||||
|
let response = respond("main", &request, dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::NOT_FOUND, "{path}");
|
||||||
|
}
|
||||||
|
assert_eq!(call_id("/7"), Some(7));
|
||||||
|
assert_eq!(call_id("/0012"), Some(12));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_range_is_served_partially() {
|
||||||
|
let dir = dir();
|
||||||
|
let response = respond(
|
||||||
|
"main",
|
||||||
|
&get("playback://localhost/7", Some("bytes=2-5")),
|
||||||
|
dir.path(),
|
||||||
|
);
|
||||||
|
assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
|
||||||
|
assert_eq!(response.body(), b"2345");
|
||||||
|
assert_eq!(response.headers()[CONTENT_RANGE], "bytes 2-5/10");
|
||||||
|
assert_eq!(response.headers()[CONTENT_LENGTH], "4");
|
||||||
|
|
||||||
|
let open_ended = respond(
|
||||||
|
"main",
|
||||||
|
&get("playback://localhost/7", Some("bytes=8-")),
|
||||||
|
dir.path(),
|
||||||
|
);
|
||||||
|
assert_eq!(open_ended.body(), b"89");
|
||||||
|
assert_eq!(open_ended.headers()[CONTENT_RANGE], "bytes 8-9/10");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_range_beyond_the_end_is_not_satisfiable() {
|
||||||
|
let dir = dir();
|
||||||
|
let response = respond(
|
||||||
|
"main",
|
||||||
|
&get("playback://localhost/7", Some("bytes=20-30")),
|
||||||
|
dir.path(),
|
||||||
|
);
|
||||||
|
assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE);
|
||||||
|
assert_eq!(response.headers()[CONTENT_RANGE], "bytes */10");
|
||||||
|
assert!(response.body().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_long_range_is_cut_to_the_maximum() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let len = MAX_RANGE_LEN as usize * 2 + 3;
|
||||||
|
fs::write(cache_path(dir.path(), 1), vec![1u8; len]).unwrap();
|
||||||
|
let response = respond(
|
||||||
|
"main",
|
||||||
|
&get("playback://localhost/1", Some("bytes=1-")),
|
||||||
|
dir.path(),
|
||||||
|
);
|
||||||
|
assert_eq!(response.body().len(), MAX_RANGE_LEN as usize);
|
||||||
|
assert_eq!(
|
||||||
|
response.headers()[CONTENT_RANGE],
|
||||||
|
format!("bytes 1-{}/{len}", MAX_RANGE_LEN).as_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn head_has_no_body_and_other_methods_are_refused() {
|
||||||
|
let dir = dir();
|
||||||
|
let head = Request::builder()
|
||||||
|
.method(Method::HEAD)
|
||||||
|
.uri("playback://localhost/7")
|
||||||
|
.body(Vec::new())
|
||||||
|
.unwrap();
|
||||||
|
let response = respond("main", &head, dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
|
assert_eq!(response.headers()[CONTENT_LENGTH], "10");
|
||||||
|
assert!(response.body().is_empty());
|
||||||
|
|
||||||
|
let post = Request::builder()
|
||||||
|
.method(Method::POST)
|
||||||
|
.uri("playback://localhost/7")
|
||||||
|
.body(Vec::new())
|
||||||
|
.unwrap();
|
||||||
|
let response = respond("main", &post, dir.path());
|
||||||
|
assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
|||||||
let opts = PipelineOptions {
|
let opts = PipelineOptions {
|
||||||
language: settings.language,
|
language: settings.language,
|
||||||
deepscript_model: settings.deepscript_model,
|
deepscript_model: settings.deepscript_model,
|
||||||
|
vocabulary: settings.vocabulary,
|
||||||
};
|
};
|
||||||
// A fresh client per run, so a key changed in the settings applies to
|
// A fresh client per run, so a key changed in the settings applies to
|
||||||
// the next run.
|
// the next run.
|
||||||
|
|||||||
+462
-23
@@ -2,11 +2,12 @@
|
|||||||
//!
|
//!
|
||||||
//! Holds the store, the settings, the secret store, the HTTP transport, the
|
//! Holds the store, the settings, the secret store, the HTTP transport, the
|
||||||
//! recording that is currently running, the call detector, the calls
|
//! recording that is currently running, the call detector, the calls
|
||||||
//! awaiting a decision in the end-of-call prompt and the calls being
|
//! awaiting a decision in the end-of-call prompt, the calls being
|
||||||
//! processed. Everything here is independent of windows and
|
//! processed and the cached mixes for playback. Everything here is
|
||||||
//! events; the command layer turns results into UI updates.
|
//! independent of windows and events; the command layer turns results into
|
||||||
|
//! UI updates.
|
||||||
|
|
||||||
use std::collections::{HashSet, VecDeque};
|
use std::collections::{HashMap, HashSet, VecDeque};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -23,6 +24,7 @@ use recorder_core::capture::{CaptureSource, OutputTarget};
|
|||||||
use recorder_core::detect::{CallDetector, DetectorEvent, MicSession};
|
use recorder_core::detect::{CallDetector, DetectorEvent, MicSession};
|
||||||
use recorder_core::http::{HttpTransport, ReqwestTransport};
|
use recorder_core::http::{HttpTransport, ReqwestTransport};
|
||||||
use recorder_core::model::{Call, CallId, CallStatus, Speaker};
|
use recorder_core::model::{Call, CallId, CallStatus, Speaker};
|
||||||
|
use recorder_core::playback;
|
||||||
use recorder_core::recorder::Recorder;
|
use recorder_core::recorder::Recorder;
|
||||||
use recorder_core::secrets::{SecretStore, Service};
|
use recorder_core::secrets::{SecretStore, Service};
|
||||||
use recorder_core::settings::Settings;
|
use recorder_core::settings::Settings;
|
||||||
@@ -37,6 +39,7 @@ const MANUAL_APP: &str = "Manuell";
|
|||||||
const TEST_DURATION: Duration = Duration::from_secs(5);
|
const TEST_DURATION: Duration = Duration::from_secs(5);
|
||||||
const TEST_POLL: Duration = Duration::from_millis(50);
|
const TEST_POLL: Duration = Duration::from_millis(50);
|
||||||
const ALREADY_PROCESSING: &str = "Wird bereits verarbeitet";
|
const ALREADY_PROCESSING: &str = "Wird bereits verarbeitet";
|
||||||
|
const ALREADY_UPLOADING: &str = "Wird bereits hochgeladen";
|
||||||
|
|
||||||
/// Why [`AppState::discard_call`] refused.
|
/// Why [`AppState::discard_call`] refused.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -146,6 +149,12 @@ pub struct AppState {
|
|||||||
settings: Mutex<Settings>,
|
settings: Mutex<Settings>,
|
||||||
settings_path: PathBuf,
|
settings_path: PathBuf,
|
||||||
recordings_dir: PathBuf,
|
recordings_dir: PathBuf,
|
||||||
|
/// Where the mixes for playback are cached (`<app cache>/playback`),
|
||||||
|
/// served to the main window by [`crate::playback`].
|
||||||
|
playback_dir: PathBuf,
|
||||||
|
/// The leases on cached mixes. Held while a mix is built or removed,
|
||||||
|
/// so a call deleted meanwhile never leaves its mix behind.
|
||||||
|
playback: Mutex<PlaybackLeases>,
|
||||||
current: Mutex<Option<CurrentRecording>>,
|
current: Mutex<Option<CurrentRecording>>,
|
||||||
detector: Mutex<CallDetector>,
|
detector: Mutex<CallDetector>,
|
||||||
/// Stopped calls awaiting the end-of-call prompt's decision, oldest
|
/// Stopped calls awaiting the end-of-call prompt's decision, oldest
|
||||||
@@ -164,6 +173,29 @@ pub struct AppState {
|
|||||||
backend_key_lock: Mutex<()>,
|
backend_key_lock: Mutex<()>,
|
||||||
/// Calls whose transcript is being uploaded; one upload per call.
|
/// Calls whose transcript is being uploaded; one upload per call.
|
||||||
uploading: Mutex<HashSet<CallId>>,
|
uploading: Mutex<HashSet<CallId>>,
|
||||||
|
/// Calls whose transcript reached the CRM but could not be recorded
|
||||||
|
/// locally (`mark_uploaded` failed after a successful upload):
|
||||||
|
/// `claim_upload` refuses these for the rest of this run, so a retry
|
||||||
|
/// never creates a second copy at the CRM. In-memory only; a restart
|
||||||
|
/// forgets it (the row's `crm_transcript_id` is still empty then).
|
||||||
|
upload_confirmed_unsaved: Mutex<HashSet<CallId>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A mix ready to play, from [`AppState::prepare_playback`].
|
||||||
|
#[derive(Serialize, Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub struct PreparedPlayback {
|
||||||
|
pub duration_secs: f64,
|
||||||
|
/// Hand back to [`AppState::release_playback`] when the player is done.
|
||||||
|
pub lease: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Which player holds each cached mix: the lease of the latest
|
||||||
|
/// [`AppState::prepare_playback`] per call. A player that lets go of an
|
||||||
|
/// older lease (it was replaced by a newer one meanwhile) removes nothing.
|
||||||
|
#[derive(Default)]
|
||||||
|
struct PlaybackLeases {
|
||||||
|
next: u64,
|
||||||
|
latest: HashMap<CallId, u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An upload reserved with [`AppState::claim_upload`]; released when
|
/// An upload reserved with [`AppState::claim_upload`]; released when
|
||||||
@@ -194,6 +226,7 @@ impl AppState {
|
|||||||
secrets: Box<dyn SecretStore>,
|
secrets: Box<dyn SecretStore>,
|
||||||
settings_path: PathBuf,
|
settings_path: PathBuf,
|
||||||
recordings_dir: PathBuf,
|
recordings_dir: PathBuf,
|
||||||
|
playback_dir: PathBuf,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let settings = Settings::load(&settings_path);
|
let settings = Settings::load(&settings_path);
|
||||||
let detector = CallDetector::new(detector_config(&settings));
|
let detector = CallDetector::new(detector_config(&settings));
|
||||||
@@ -204,6 +237,8 @@ impl AppState {
|
|||||||
settings: Mutex::new(settings),
|
settings: Mutex::new(settings),
|
||||||
settings_path,
|
settings_path,
|
||||||
recordings_dir,
|
recordings_dir,
|
||||||
|
playback_dir,
|
||||||
|
playback: Mutex::new(PlaybackLeases::default()),
|
||||||
current: Mutex::new(None),
|
current: Mutex::new(None),
|
||||||
detector: Mutex::new(detector),
|
detector: Mutex::new(detector),
|
||||||
pending_prompts: Mutex::new(VecDeque::new()),
|
pending_prompts: Mutex::new(VecDeque::new()),
|
||||||
@@ -217,6 +252,7 @@ impl AppState {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
backend_key_lock: Mutex::new(()),
|
backend_key_lock: Mutex::new(()),
|
||||||
uploading: Mutex::new(HashSet::new()),
|
uploading: Mutex::new(HashSet::new()),
|
||||||
|
upload_confirmed_unsaved: Mutex::new(HashSet::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,17 +378,28 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reserves call `id` for one upload; released when the claim is
|
/// Reserves call `id` for one upload; released when the claim is
|
||||||
/// dropped. A second upload of the same call is refused meanwhile, and a
|
/// dropped. A second upload of the same call is refused meanwhile, and
|
||||||
/// call that already carries a CRM transcript id is refused outright:
|
/// so is a call already uploaded to *this build's* backend
|
||||||
/// the CRM must never get a duplicate. Both checks happen while
|
/// ([`call_view::uploaded_here`]) — or one the CRM confirmed but whose
|
||||||
/// `uploading` is locked, so a second upload can never slip in between
|
/// id could not be saved locally, see
|
||||||
/// this check and the one upload it allows.
|
/// [`AppState::note_upload_confirmed_but_unsaved`]: the CRM this build
|
||||||
|
/// talks to must never get a duplicate. An upload recorded for another
|
||||||
|
/// backend (e.g. the test backend, read by a release build) is not
|
||||||
|
/// "uploaded" here and is claimed like any other call. All three checks
|
||||||
|
/// happen while `uploading` is locked, so a second upload can never
|
||||||
|
/// slip in between this check and the one upload it allows.
|
||||||
pub fn claim_upload(&self, id: CallId) -> Result<UploadClaim<'_>, String> {
|
pub fn claim_upload(&self, id: CallId) -> Result<UploadClaim<'_>, String> {
|
||||||
let mut uploading = lock(&self.uploading);
|
let mut uploading = lock(&self.uploading);
|
||||||
if uploading.contains(&id) {
|
if uploading.contains(&id) {
|
||||||
return Err("Wird bereits hochgeladen".to_string());
|
return Err(ALREADY_UPLOADING.to_string());
|
||||||
}
|
}
|
||||||
if self.find_call(id)?.crm_transcript_id.is_some() {
|
if lock(&self.upload_confirmed_unsaved).contains(&id) {
|
||||||
|
return Err("Bereits hochgeladen".to_string());
|
||||||
|
}
|
||||||
|
// An upload recorded for another backend (e.g. the test backend,
|
||||||
|
// read by a release build) does not count: the CRM this build
|
||||||
|
// talks to has never seen this transcript.
|
||||||
|
if call_view::uploaded_here(&self.find_call(id)?, &self.backend_url) {
|
||||||
return Err("Bereits hochgeladen".to_string());
|
return Err("Bereits hochgeladen".to_string());
|
||||||
}
|
}
|
||||||
uploading.insert(id);
|
uploading.insert(id);
|
||||||
@@ -364,6 +411,14 @@ impl AppState {
|
|||||||
lock(&self.uploading).contains(&id)
|
lock(&self.uploading).contains(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Records that call `id`'s transcript reached the CRM, but saving that
|
||||||
|
/// locally (`mark_uploaded`) failed: [`AppState::claim_upload`] refuses
|
||||||
|
/// this call for the rest of the run, so a retry can never send the CRM
|
||||||
|
/// a second copy. In-memory only; see the field's doc comment.
|
||||||
|
pub fn note_upload_confirmed_but_unsaved(&self, id: CallId) {
|
||||||
|
lock(&self.upload_confirmed_unsaved).insert(id);
|
||||||
|
}
|
||||||
|
|
||||||
/// Changes and saves settings the app manages itself; saves only if
|
/// Changes and saves settings the app manages itself; saves only if
|
||||||
/// something changed.
|
/// something changed.
|
||||||
fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> {
|
fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> {
|
||||||
@@ -607,7 +662,10 @@ impl AppState {
|
|||||||
/// All calls for the main window's list, newest first.
|
/// All calls for the main window's list, newest first.
|
||||||
pub fn call_list(&self) -> Result<Vec<CallListItem>, String> {
|
pub fn call_list(&self) -> Result<Vec<CallListItem>, String> {
|
||||||
let calls = self.store.list_calls().map_err(|e| e.to_string())?;
|
let calls = self.store.list_calls().map_err(|e| e.to_string())?;
|
||||||
Ok(calls.iter().map(CallListItem::of).collect())
|
Ok(calls
|
||||||
|
.iter()
|
||||||
|
.map(|call| CallListItem::of(call, &self.backend_url))
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The selected call with its transcript (speaker merges applied),
|
/// The selected call with its transcript (speaker merges applied),
|
||||||
@@ -617,11 +675,77 @@ impl AppState {
|
|||||||
let segments = self.store.segments(id).map_err(|e| e.to_string())?;
|
let segments = self.store.segments(id).map_err(|e| e.to_string())?;
|
||||||
let names = self.store.speaker_names(id).map_err(|e| e.to_string())?;
|
let names = self.store.speaker_names(id).map_err(|e| e.to_string())?;
|
||||||
let merges = self.store.speaker_merges(id).map_err(|e| e.to_string())?;
|
let merges = self.store.speaker_merges(id).map_err(|e| e.to_string())?;
|
||||||
let mut detail = CallDetail::of(&call, &segments, names, &merges);
|
let mut detail = CallDetail::of(
|
||||||
|
&call,
|
||||||
|
&segments,
|
||||||
|
names,
|
||||||
|
&merges,
|
||||||
|
&self.backend_url,
|
||||||
|
&self.settings().language,
|
||||||
|
);
|
||||||
detail.uploading = self.is_uploading(id);
|
detail.uploading = self.is_uploading(id);
|
||||||
|
detail.audio_available = playback::audio_available(&call);
|
||||||
Ok(detail)
|
Ok(detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mixes call `id`'s tracks for playback (or reuses the cached mix,
|
||||||
|
/// see [`playback::prepare`]) under a new lease. Refused while the call
|
||||||
|
/// is recorded or processed, and once its audio is gone.
|
||||||
|
pub fn prepare_playback(&self, id: CallId) -> Result<PreparedPlayback, String> {
|
||||||
|
if lock(&self.current)
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|cur| cur.call_id == id)
|
||||||
|
{
|
||||||
|
return Err(playback::RECORDING.to_string());
|
||||||
|
}
|
||||||
|
let mut leases = lock(&self.playback);
|
||||||
|
// Read under the lock: a call deleted before it is not mixed, one
|
||||||
|
// deleted meanwhile has its mix removed once the lock is free.
|
||||||
|
let call = self.find_call(id)?;
|
||||||
|
let info = playback::prepare(&call, &self.playback_dir)?;
|
||||||
|
leases.next += 1;
|
||||||
|
let lease = leases.next;
|
||||||
|
leases.latest.insert(id, lease);
|
||||||
|
Ok(PreparedPlayback {
|
||||||
|
duration_secs: info.duration_secs,
|
||||||
|
lease,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The player of `lease` is done with call `id`'s mix: removes it,
|
||||||
|
/// unless a newer lease (another player of the same call) holds it.
|
||||||
|
pub fn release_playback(&self, id: CallId, lease: u64) {
|
||||||
|
let mut leases = lock(&self.playback);
|
||||||
|
if leases.latest.get(&id) == Some(&lease) {
|
||||||
|
leases.latest.remove(&id);
|
||||||
|
playback::remove_cached(&self.playback_dir, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes call `id`'s cached mix whoever holds it: with the call, and
|
||||||
|
/// once its audio is deleted. The retention job, when it deletes a
|
||||||
|
/// call's audio, calls this too.
|
||||||
|
pub fn remove_playback(&self, id: CallId) {
|
||||||
|
let mut leases = lock(&self.playback);
|
||||||
|
leases.latest.remove(&id);
|
||||||
|
playback::remove_cached(&self.playback_dir, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where the mixes are cached ([`crate::playback`] serves them).
|
||||||
|
pub fn playback_dir(&self) -> &Path {
|
||||||
|
&self.playback_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Empties the playback cache (at startup), so mixed customer audio
|
||||||
|
/// never lingers from an earlier run.
|
||||||
|
pub fn clear_playback_cache(&self) {
|
||||||
|
let dir = &self.playback_dir;
|
||||||
|
match playback::clear_cache(dir) {
|
||||||
|
Ok(()) => log::info!("cleared the playback cache {}", dir.display()),
|
||||||
|
Err(e) => log::warn!("could not empty {}: {e}", dir.display()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Renames a speaker of call `id`; a blank `name` restores the default
|
/// Renames a speaker of call `id`; a blank `name` restores the default
|
||||||
/// label ("Ich", "Sprecher N").
|
/// label ("Ich", "Sprecher N").
|
||||||
pub fn rename_speaker(&self, id: CallId, speaker_key: &str, name: &str) -> Result<(), String> {
|
pub fn rename_speaker(&self, id: CallId, speaker_key: &str, name: &str) -> Result<(), String> {
|
||||||
@@ -672,7 +796,7 @@ impl AppState {
|
|||||||
pub fn mark_uploaded(&self, id: CallId, crm_transcript_id: &str) -> Result<(), String> {
|
pub fn mark_uploaded(&self, id: CallId, crm_transcript_id: &str) -> Result<(), String> {
|
||||||
self.find_call(id)?;
|
self.find_call(id)?;
|
||||||
self.store
|
self.store
|
||||||
.set_uploaded(id, crm_transcript_id, Local::now())
|
.set_uploaded(id, crm_transcript_id, &self.backend_url, Local::now())
|
||||||
.map_err(|e| format!("Upload konnte nicht vermerkt werden: {e}"))
|
.map_err(|e| format!("Upload konnte nicht vermerkt werden: {e}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,11 +807,15 @@ impl AppState {
|
|||||||
.ok_or_else(|| "Gespräch nicht gefunden".to_string())
|
.ok_or_else(|| "Gespräch nicht gefunden".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a finished call: both audio files and the row, and takes it
|
/// Deletes a finished (or still undecided/failed) call: both audio files
|
||||||
/// out of the prompt queue. Returns how many calls still wait for the
|
/// and the row, cascading to its segments, speaker names, merges and
|
||||||
/// prompt. A call that is being processed, or whose DeepScript jobs
|
/// recorded remote jobs — this is also how a transcribed (`Done`) call's
|
||||||
/// are still on record ([`DiscardError::CleanupPending`]), is not
|
/// "Löschen" removes it. Takes it out of the prompt queue and returns how
|
||||||
/// deleted.
|
/// many calls still wait for it. Refused while the call is being
|
||||||
|
/// recorded, processed ([`AppState::claim_processing`]/
|
||||||
|
/// [`AppState::reserve_processing`] or status `Processing`), uploaded
|
||||||
|
/// ([`AppState::claim_upload`]), or while its DeepScript jobs are still
|
||||||
|
/// on record ([`DiscardError::CleanupPending`]).
|
||||||
pub fn discard_call(&self, id: CallId) -> Result<usize, DiscardError> {
|
pub fn discard_call(&self, id: CallId) -> Result<usize, DiscardError> {
|
||||||
if lock(&self.current)
|
if lock(&self.current)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -695,11 +823,17 @@ impl AppState {
|
|||||||
{
|
{
|
||||||
return Err("Das Gespräch wird gerade aufgenommen".to_string().into());
|
return Err("Das Gespräch wird gerade aufgenommen".to_string().into());
|
||||||
}
|
}
|
||||||
// Held until the call is gone, so no run can claim it meanwhile.
|
// Both held until the call is gone, so neither a pipeline run nor an
|
||||||
|
// upload can claim it meanwhile (same uploading -> store lock order
|
||||||
|
// as `claim_upload`, so this can never deadlock against it).
|
||||||
let processing = lock(&self.processing);
|
let processing = lock(&self.processing);
|
||||||
if processing.contains(&id) {
|
if processing.contains(&id) {
|
||||||
return Err(ALREADY_PROCESSING.to_string().into());
|
return Err(ALREADY_PROCESSING.to_string().into());
|
||||||
}
|
}
|
||||||
|
let uploading = lock(&self.uploading);
|
||||||
|
if uploading.contains(&id) {
|
||||||
|
return Err(ALREADY_UPLOADING.to_string().into());
|
||||||
|
}
|
||||||
let call = self
|
let call = self
|
||||||
.store
|
.store
|
||||||
.get_call(id)
|
.get_call(id)
|
||||||
@@ -713,7 +847,8 @@ impl AppState {
|
|||||||
return Err(DiscardError::CleanupPending);
|
return Err(DiscardError::CleanupPending);
|
||||||
}
|
}
|
||||||
// Files first: if one cannot be deleted, the row stays so the user
|
// Files first: if one cannot be deleted, the row stays so the user
|
||||||
// can try again instead of leaving orphaned audio behind.
|
// can try again instead of leaving orphaned audio behind. Already
|
||||||
|
// gone (e.g. removed by retention) is not an error.
|
||||||
for path in [&call.mic_path, &call.out_path] {
|
for path in [&call.mic_path, &call.out_path] {
|
||||||
if path.as_os_str().is_empty() {
|
if path.as_os_str().is_empty() {
|
||||||
continue;
|
continue;
|
||||||
@@ -739,7 +874,9 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
return Err(format!("Gespräch konnte nicht gelöscht werden: {e}").into());
|
return Err(format!("Gespräch konnte nicht gelöscht werden: {e}").into());
|
||||||
}
|
}
|
||||||
|
drop(uploading);
|
||||||
drop(processing);
|
drop(processing);
|
||||||
|
self.remove_playback(id);
|
||||||
Ok(self.prompts_waiting())
|
Ok(self.prompts_waiting())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -918,6 +1055,7 @@ mod tests {
|
|||||||
Box::new(MemorySecrets::default()),
|
Box::new(MemorySecrets::default()),
|
||||||
dir.path().join("settings.json"),
|
dir.path().join("settings.json"),
|
||||||
dir.path().join("recordings"),
|
dir.path().join("recordings"),
|
||||||
|
dir.path().join("playback"),
|
||||||
);
|
);
|
||||||
Fixture { state, dir }
|
Fixture { state, dir }
|
||||||
}
|
}
|
||||||
@@ -1118,6 +1256,60 @@ mod tests {
|
|||||||
assert!(f.state.reserve_processing(id));
|
assert!(f.state.reserve_processing(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_transcribed_call_is_deleted_like_any_other() {
|
||||||
|
let f = fixture();
|
||||||
|
let (id, mic, out) = finished_call(&f, "a");
|
||||||
|
f.state
|
||||||
|
.store
|
||||||
|
.set_status(id, CallStatus::Done, None)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_call_being_uploaded_is_not_discarded() {
|
||||||
|
let f = fixture();
|
||||||
|
let (id, mic, out) = finished_call(&f, "a");
|
||||||
|
f.state
|
||||||
|
.store
|
||||||
|
.set_status(id, CallStatus::Done, None)
|
||||||
|
.unwrap();
|
||||||
|
let claim = f.state.claim_upload(id).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
f.state.discard_call(id),
|
||||||
|
Err(DiscardError::Other("Wird bereits hochgeladen".to_string()))
|
||||||
|
);
|
||||||
|
assert!(mic.exists());
|
||||||
|
assert!(out.exists());
|
||||||
|
assert!(f.state.store.get_call(id).unwrap().is_some());
|
||||||
|
|
||||||
|
// Once the upload is done, the delete goes through.
|
||||||
|
drop(claim);
|
||||||
|
assert_eq!(f.state.discard_call(id), Ok(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_call_already_uploaded_here_is_deleted_without_touching_the_crm() {
|
||||||
|
let f = fixture();
|
||||||
|
let (id, mic, out) = finished_call(&f, "a");
|
||||||
|
f.state
|
||||||
|
.store
|
||||||
|
.set_status(id, CallStatus::Done, None)
|
||||||
|
.unwrap();
|
||||||
|
f.state.mark_uploaded(id, "4711").unwrap();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_cleanup_reserves_a_call_of_any_status() {
|
fn a_cleanup_reserves_a_call_of_any_status() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
@@ -1518,6 +1710,42 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The real transition the review asked to lock in: a key created while
|
||||||
|
/// this install talked to the test backend must not work once the same
|
||||||
|
/// install is a release build talking to the production backend — it is
|
||||||
|
/// discarded and a fresh login is required, exactly like any other
|
||||||
|
/// backend mismatch above, but with the two real build-time constants
|
||||||
|
/// instead of a placeholder domain.
|
||||||
|
#[test]
|
||||||
|
fn a_key_from_the_test_backend_does_not_work_for_a_release_build() {
|
||||||
|
let mut f = fixture();
|
||||||
|
// A build on the test backend (what `cargo tauri dev` is), whatever
|
||||||
|
// profile this test itself runs in.
|
||||||
|
f.state.backend_url = crate::backend::DEV_BACKEND_URL.to_string();
|
||||||
|
f.state
|
||||||
|
.store_backend_key(
|
||||||
|
&new_key("euv_test"),
|
||||||
|
crate::backend::DEV_BACKEND_URL,
|
||||||
|
Some("hinrichs".into()),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(f.state.backend_key().is_some());
|
||||||
|
|
||||||
|
// Same keyring entry and settings file; now read as a release build
|
||||||
|
// would (a different `backend_url`, nothing else changed).
|
||||||
|
f.state.backend_url = crate::backend::RELEASE_BACKEND_URL.to_string();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
f.state.backend_key(),
|
||||||
|
None,
|
||||||
|
"a test-backend key must not work for the release backend"
|
||||||
|
);
|
||||||
|
assert_eq!(f.state.secrets.get(Service::Backend), None);
|
||||||
|
let settings = f.state.settings();
|
||||||
|
assert_eq!(settings.backend_username, None);
|
||||||
|
assert_eq!(settings.backend_key_base_url, None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_backend_login_is_refreshed_from_the_key_info() {
|
fn the_backend_login_is_refreshed_from_the_key_info() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
@@ -1602,10 +1830,17 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn the_backend_is_fixed_per_build() {
|
fn the_backend_is_fixed_per_build() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
assert_eq!(f.state.backend_url(), "https://test.euvinopro.eu");
|
// Debug builds (`cargo tauri dev`, `cargo test`) use the test
|
||||||
|
// backend, release builds the production one.
|
||||||
|
let expected = if cfg!(debug_assertions) {
|
||||||
|
"https://test.euvinopro.eu"
|
||||||
|
} else {
|
||||||
|
"https://backend.euvinopro.eu"
|
||||||
|
};
|
||||||
|
assert_eq!(f.state.backend_url(), expected);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
f.state.backend_client().login_url(),
|
f.state.backend_client().login_url(),
|
||||||
"https://test.euvinopro.eu/euvadm"
|
format!("{expected}/euvadm")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1643,6 +1878,57 @@ mod tests {
|
|||||||
assert!(!f.state.is_uploading(id));
|
assert!(!f.state.is_uploading(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The real case the review asked to lock in: a call uploaded to the
|
||||||
|
/// test backend is refused for upload by a build whose own backend is
|
||||||
|
/// the test backend (the normal case, above), but uploadable again by a
|
||||||
|
/// build whose backend is the production one — the CRM at that backend
|
||||||
|
/// has never seen this transcript.
|
||||||
|
#[test]
|
||||||
|
fn an_upload_to_another_backend_is_not_counted_as_uploaded_here() {
|
||||||
|
let mut f = fixture();
|
||||||
|
let (id, _, _) = finished_call(&f, "a");
|
||||||
|
// A build on the test backend (what `cargo tauri dev` is), whatever
|
||||||
|
// profile this test itself runs in: mark_uploaded records it.
|
||||||
|
f.state.backend_url = crate::backend::DEV_BACKEND_URL.to_string();
|
||||||
|
f.state.mark_uploaded(id, "4711").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
f.state.find_call(id).unwrap().crm_base_url.as_deref(),
|
||||||
|
Some(crate::backend::DEV_BACKEND_URL)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
f.state.claim_upload(id).err(),
|
||||||
|
Some("Bereits hochgeladen".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
// The same row, now read as a release build would be: a different
|
||||||
|
// backend, nothing else changed.
|
||||||
|
f.state.backend_url = crate::backend::RELEASE_BACKEND_URL.to_string();
|
||||||
|
assert!(f.state.claim_upload(id).is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_upload_confirmed_but_unsaved_is_never_retried() {
|
||||||
|
// The CRM has the transcript, but mark_uploaded failed: the row
|
||||||
|
// itself still shows no crm_transcript_id.
|
||||||
|
let f = fixture();
|
||||||
|
let (id, _, _) = finished_call(&f, "a");
|
||||||
|
f.state.note_upload_confirmed_but_unsaved(id);
|
||||||
|
|
||||||
|
assert!(f
|
||||||
|
.state
|
||||||
|
.call_detail(id)
|
||||||
|
.unwrap()
|
||||||
|
.call
|
||||||
|
.item
|
||||||
|
.crm_transcript_id
|
||||||
|
.is_none());
|
||||||
|
assert_eq!(
|
||||||
|
f.state.claim_upload(id).err(),
|
||||||
|
Some("Bereits hochgeladen".to_string())
|
||||||
|
);
|
||||||
|
assert!(!f.state.is_uploading(id));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn an_upload_is_recorded_on_the_call() {
|
fn an_upload_is_recorded_on_the_call() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
@@ -1652,6 +1938,7 @@ mod tests {
|
|||||||
|
|
||||||
let call = f.state.store.get_call(id).unwrap().unwrap();
|
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||||
assert_eq!(call.crm_transcript_id.as_deref(), Some("4711"));
|
assert_eq!(call.crm_transcript_id.as_deref(), Some("4711"));
|
||||||
|
assert_eq!(call.crm_base_url.as_deref(), Some(BASE));
|
||||||
assert!(call.uploaded_at.is_some());
|
assert!(call.uploaded_at.is_some());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
f.state.mark_uploaded(id + 1, "1"),
|
f.state.mark_uploaded(id + 1, "1"),
|
||||||
@@ -1699,4 +1986,156 @@ mod tests {
|
|||||||
OutputTarget::Device("id-Lautsprecher".into())
|
OutputTarget::Device("id-Lautsprecher".into())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A finished call whose tracks hold real audio: one second on the mic,
|
||||||
|
/// half a second on the output.
|
||||||
|
fn playable_call(f: &Fixture, name: &str) -> CallId {
|
||||||
|
let (id, mic, out) = finished_call(f, name);
|
||||||
|
for (path, samples) in [(&mic, 16_000), (&out, 8_000)] {
|
||||||
|
let mut writer = recorder_core::audio::TrackWriter::create(path).unwrap();
|
||||||
|
writer.write(&vec![0.1; samples]).unwrap();
|
||||||
|
writer.finalize().unwrap();
|
||||||
|
}
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
|
fn playback_file(f: &Fixture, id: CallId) -> PathBuf {
|
||||||
|
f.dir.path().join("playback").join(format!("{id}.wav"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_finished_call_is_mixed_into_the_playback_cache() {
|
||||||
|
let f = fixture();
|
||||||
|
let id = playable_call(&f, "a");
|
||||||
|
assert!(f.state.call_detail(id).unwrap().audio_available);
|
||||||
|
|
||||||
|
let prepared = f.state.prepare_playback(id).unwrap();
|
||||||
|
assert!((prepared.duration_secs - 1.0).abs() < 1e-9);
|
||||||
|
assert!(playback_file(&f, id).exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_player_holding_the_latest_lease_removes_the_mix() {
|
||||||
|
let f = fixture();
|
||||||
|
let id = playable_call(&f, "a");
|
||||||
|
let first = f.state.prepare_playback(id).unwrap().lease;
|
||||||
|
// The call was shown again before the first player let go.
|
||||||
|
let second = f.state.prepare_playback(id).unwrap().lease;
|
||||||
|
assert_ne!(first, second);
|
||||||
|
|
||||||
|
f.state.release_playback(id, first);
|
||||||
|
assert!(
|
||||||
|
playback_file(&f, id).exists(),
|
||||||
|
"the second player still plays"
|
||||||
|
);
|
||||||
|
f.state.release_playback(id, second);
|
||||||
|
assert!(!playback_file(&f, id).exists());
|
||||||
|
f.state.release_playback(id, second); // already gone: no error
|
||||||
|
|
||||||
|
// A lease of one call never removes another call's mix.
|
||||||
|
let other = playable_call(&f, "b");
|
||||||
|
let lease = f.state.prepare_playback(other).unwrap().lease;
|
||||||
|
f.state.release_playback(id, lease);
|
||||||
|
assert!(playback_file(&f, other).exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_files_are_no_audio_but_not_deleted_audio() {
|
||||||
|
let f = fixture();
|
||||||
|
let (id, mic, out) = finished_call(&f, "a"); // a few junk bytes each
|
||||||
|
let detail = f.state.call_detail(id).unwrap();
|
||||||
|
assert!(!detail.audio_available);
|
||||||
|
assert!(!detail.audio_deleted);
|
||||||
|
fs::remove_file(mic).unwrap();
|
||||||
|
fs::remove_file(out).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(id),
|
||||||
|
Err(playback::AUDIO_MISSING.to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn recording_and_processing_calls_are_not_played() {
|
||||||
|
let f = fixture();
|
||||||
|
let dir = f.dir.path();
|
||||||
|
let recording = f
|
||||||
|
.state
|
||||||
|
.store
|
||||||
|
.create_call(
|
||||||
|
"Microsoft Teams",
|
||||||
|
at(10, 0, 0),
|
||||||
|
&dir.join("r-mic.wav"),
|
||||||
|
&dir.join("r-out.wav"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(recording),
|
||||||
|
Err(playback::RECORDING.to_string())
|
||||||
|
);
|
||||||
|
|
||||||
|
let processing = playable_call(&f, "p");
|
||||||
|
f.state
|
||||||
|
.store
|
||||||
|
.set_status(processing, CallStatus::Processing, None)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(processing),
|
||||||
|
Err(playback::PROCESSING.to_string())
|
||||||
|
);
|
||||||
|
assert!(!playback_file(&f, processing).exists());
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(999),
|
||||||
|
Err("Gespräch nicht gefunden".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deleted_audio_is_not_played_and_its_mix_is_removed() {
|
||||||
|
let f = fixture();
|
||||||
|
let id = playable_call(&f, "a");
|
||||||
|
f.state.prepare_playback(id).unwrap();
|
||||||
|
|
||||||
|
// What the retention sweep does to a transcribed call's audio.
|
||||||
|
let call = f.state.store.get_call(id).unwrap().unwrap();
|
||||||
|
fs::remove_file(&call.mic_path).unwrap();
|
||||||
|
fs::remove_file(&call.out_path).unwrap();
|
||||||
|
f.state.store.mark_audio_deleted(id).unwrap();
|
||||||
|
|
||||||
|
let detail = f.state.call_detail(id).unwrap();
|
||||||
|
assert!(!detail.audio_available);
|
||||||
|
assert!(detail.audio_deleted);
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(id),
|
||||||
|
Err(playback::AUDIO_GONE.to_string())
|
||||||
|
);
|
||||||
|
assert!(!playback_file(&f, id).exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deleting_a_call_removes_its_mix() {
|
||||||
|
let f = fixture();
|
||||||
|
let id = playable_call(&f, "a");
|
||||||
|
let other = playable_call(&f, "b");
|
||||||
|
f.state.prepare_playback(id).unwrap();
|
||||||
|
f.state.prepare_playback(other).unwrap();
|
||||||
|
|
||||||
|
f.state.discard_call(id).unwrap();
|
||||||
|
assert!(!playback_file(&f, id).exists());
|
||||||
|
assert!(playback_file(&f, other).exists());
|
||||||
|
assert_eq!(
|
||||||
|
f.state.prepare_playback(id),
|
||||||
|
Err("Gespräch nicht gefunden".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_playback_cache_is_emptied_at_startup() {
|
||||||
|
let f = fixture();
|
||||||
|
let id = playable_call(&f, "a");
|
||||||
|
f.state.prepare_playback(id).unwrap();
|
||||||
|
|
||||||
|
f.state.clear_playback_cache();
|
||||||
|
assert!(!f.dir.path().join("playback").exists());
|
||||||
|
f.state.clear_playback_cache(); // nothing left: no error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+163
-23
@@ -13,6 +13,7 @@
|
|||||||
//! there (see [`can_self_update`]).
|
//! there (see [`can_self_update`]).
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::future::Future;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
@@ -47,6 +48,17 @@ const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15 * 60);
|
|||||||
const MIB: u64 = 1024 * 1024;
|
const MIB: u64 = 1024 * 1024;
|
||||||
/// Why the banner cannot install yet; the banner shows the same hint.
|
/// Why the banner cannot install yet; the banner shows the same hint.
|
||||||
const BUSY: &str = "Nach der laufenden Aufnahme/Verarbeitung möglich";
|
const BUSY: &str = "Nach der laufenden Aufnahme/Verarbeitung möglich";
|
||||||
|
/// The feed's key for the one installable release this app ever builds for
|
||||||
|
/// itself (see `UpdaterBuilder::target`). Asked explicitly on platforms
|
||||||
|
/// that cannot self-update, since the feed has no entry of their own and
|
||||||
|
/// the updater's automatic target lookup would otherwise fail with
|
||||||
|
/// `TargetsNotFound` even when a newer version exists.
|
||||||
|
const WINDOWS_TARGET: &str = "windows-x86_64";
|
||||||
|
/// Why installing is refused outright on this platform (`install_update`'s
|
||||||
|
/// own guard, in case a future feed ever gets a non-Windows entry and
|
||||||
|
/// `check` started finding updates there too).
|
||||||
|
const LINUX_CANNOT_INSTALL: &str =
|
||||||
|
"Updates werden unter Linux nicht automatisch installiert – bitte das .deb neu installieren.";
|
||||||
|
|
||||||
/// The newest update found, and whether one is being installed.
|
/// The newest update found, and whether one is being installed.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -64,9 +76,10 @@ pub struct UpdateInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Answer of `check_for_update_now`: what a check (background or manual)
|
/// Answer of `check_for_update_now`: what a check (background or manual)
|
||||||
/// found. `Available` leaves the same state `get_update` reads and fires
|
/// found. On Windows, `Available` also leaves the same state `get_update`
|
||||||
/// the same `update-available` event as the background loop, so the main
|
/// reads and fires the same `update-available` event as the background
|
||||||
/// window's banner shows it too.
|
/// loop, so the main window's banner shows it too; elsewhere it only
|
||||||
|
/// reports the version (see `check_outcome`).
|
||||||
#[derive(Serialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Clone, Debug, PartialEq)]
|
||||||
#[serde(tag = "status", rename_all = "lowercase")]
|
#[serde(tag = "status", rename_all = "lowercase")]
|
||||||
pub enum UpdateCheckResult {
|
pub enum UpdateCheckResult {
|
||||||
@@ -116,15 +129,42 @@ impl UpdateSchedule {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs one check attempt right now: serialized against any other check
|
/// Runs one check attempt right now, unconditionally: for a manual
|
||||||
/// (background or manual) via `running`, and recorded for the
|
/// check, which the user asked for regardless of whether one is due.
|
||||||
/// scheduler exactly like a background attempt.
|
/// Serialized against any other check (background or manual) via
|
||||||
|
/// `running`, and recorded for the scheduler exactly like a background
|
||||||
|
/// attempt.
|
||||||
async fn run(&self, app: &AppHandle) -> UpdateCheckResult {
|
async fn run(&self, app: &AppHandle) -> UpdateCheckResult {
|
||||||
|
self.attempt(false, || check(app))
|
||||||
|
.await
|
||||||
|
.expect("an unconditional attempt always runs")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// For the background loop: like [`UpdateSchedule::run`], but only if a
|
||||||
|
/// check is still due once `running` is held (see `attempt`).
|
||||||
|
async fn run_if_due(&self, app: &AppHandle) {
|
||||||
|
self.attempt(true, || check(app)).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One serialized, recorded check attempt: takes `running`, then (if
|
||||||
|
/// `only_if_due`) re-checks `is_due` before calling `check`. Without
|
||||||
|
/// that re-check, a background tick that found a check due but then
|
||||||
|
/// had to wait behind a manual check (or another tick) would run its
|
||||||
|
/// own check right after, although the one it waited for just made the
|
||||||
|
/// next one not due any more. `None`: skipped, nothing recorded.
|
||||||
|
async fn attempt<F, Fut>(&self, only_if_due: bool, check: F) -> Option<UpdateCheckResult>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> Fut,
|
||||||
|
Fut: Future<Output = UpdateCheckResult>,
|
||||||
|
{
|
||||||
let _serialize = self.running.lock().await;
|
let _serialize = self.running.lock().await;
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let result = check(app).await;
|
if only_if_due && !self.is_due(now) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let result = check().await;
|
||||||
self.record(now, !matches!(result, UpdateCheckResult::Error { .. }));
|
self.record(now, !matches!(result, UpdateCheckResult::Error { .. }));
|
||||||
result
|
Some(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,8 +186,11 @@ pub fn spawn(app: AppHandle) {
|
|||||||
}
|
}
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
|
// Cheap early exit so most wake-ups never touch `running`; the due
|
||||||
|
// check that decides whether a check actually runs happens again
|
||||||
|
// inside `run_if_due`, once `running` is held (see its doc comment).
|
||||||
if app.state::<UpdateSchedule>().is_due(now) {
|
if app.state::<UpdateSchedule>().is_due(now) {
|
||||||
tauri::async_runtime::block_on(app.state::<UpdateSchedule>().run(&app));
|
tauri::async_runtime::block_on(app.state::<UpdateSchedule>().run_if_due(&app));
|
||||||
}
|
}
|
||||||
thread::sleep(WAKE_INTERVAL);
|
thread::sleep(WAKE_INTERVAL);
|
||||||
});
|
});
|
||||||
@@ -176,32 +219,62 @@ fn check_due(last_attempt: Option<SystemTime>, failures: u32, now: SystemTime) -
|
|||||||
/// background loop and a manual check (`check_for_update_now`) both run.
|
/// background loop and a manual check (`check_for_update_now`) both run.
|
||||||
/// A failed check (offline, no release yet) is expected; only logged here,
|
/// A failed check (offline, no release yet) is expected; only logged here,
|
||||||
/// and shown to the user only by a manual check (via the returned message).
|
/// and shown to the user only by a manual check (via the returned message).
|
||||||
|
///
|
||||||
|
/// The feed only ever has a `windows-x86_64` entry (Debian builds never
|
||||||
|
/// self-update, see `RELEASING.md`). On Windows the automatic target lookup
|
||||||
|
/// finds it on its own; on any other platform it is asked for explicitly
|
||||||
|
/// ([`WINDOWS_TARGET`]), only to learn the version number — see
|
||||||
|
/// [`check_outcome`] for why nothing is stored or announced there.
|
||||||
async fn check(app: &AppHandle) -> UpdateCheckResult {
|
async fn check(app: &AppHandle) -> UpdateCheckResult {
|
||||||
let result = match app.updater_builder().timeout(CHECK_TIMEOUT).build() {
|
let is_windows = cfg!(windows);
|
||||||
|
let mut builder = app.updater_builder().timeout(CHECK_TIMEOUT);
|
||||||
|
if !is_windows {
|
||||||
|
builder = builder.target(WINDOWS_TARGET);
|
||||||
|
}
|
||||||
|
let result = match builder.build() {
|
||||||
Ok(updater) => updater.check().await,
|
Ok(updater) => updater.check().await,
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
};
|
};
|
||||||
match result {
|
match result {
|
||||||
Ok(Some(update)) => {
|
Ok(found) => {
|
||||||
log::info!("update available: {}", update.version);
|
let version = found.as_ref().map(|update| update.version.clone());
|
||||||
let version = update.version.clone();
|
match &version {
|
||||||
*lock(&app.state::<PendingUpdate>().update) = Some(update);
|
Some(v) => log::info!("update available: {v}"),
|
||||||
let _ = app.emit("update-available", info(app, version.clone()));
|
None => log::info!("no update available"),
|
||||||
UpdateCheckResult::Available { version }
|
}
|
||||||
}
|
let (outcome, offer_install) = check_outcome(is_windows, version.clone());
|
||||||
Ok(None) => {
|
if let (Some(update), true) = (found, offer_install) {
|
||||||
log::info!("no update available");
|
*lock(&app.state::<PendingUpdate>().update) = Some(update);
|
||||||
UpdateCheckResult::None
|
let _ = app.emit(
|
||||||
|
"update-available",
|
||||||
|
info(app, version.expect("offer_install implies a version")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
outcome
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("update check failed: {e}");
|
log::info!("update check failed: {e}");
|
||||||
UpdateCheckResult::Error {
|
UpdateCheckResult::Error {
|
||||||
message: format!("Update-Server nicht erreichbar: {e}"),
|
message: format!("Update-Prüfung fehlgeschlagen: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What a feed answer (`version`, if any) means on this platform: the
|
||||||
|
/// result to return either way, and whether to remember the update for
|
||||||
|
/// `install_update` and announce it to the main window's banner. Only
|
||||||
|
/// Windows self-updates, so only there is a found update ever stored or
|
||||||
|
/// announced; elsewhere a manual check still reports the version (the
|
||||||
|
/// settings show it with a "not on this platform" hint instead of an
|
||||||
|
/// install button), but nothing is kept to install.
|
||||||
|
fn check_outcome(is_windows: bool, version: Option<String>) -> (UpdateCheckResult, bool) {
|
||||||
|
match version {
|
||||||
|
Some(version) => (UpdateCheckResult::Available { version }, is_windows),
|
||||||
|
None => (UpdateCheckResult::None, false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether this is the first start of `version` (e.g. right after an
|
/// Whether this is the first start of `version` (e.g. right after an
|
||||||
/// update), going by the version remembered in `path`; remembers `version`
|
/// update), going by the version remembered in `path`; remembers `version`
|
||||||
/// for the next start.
|
/// for the next start.
|
||||||
@@ -258,6 +331,11 @@ pub fn get_update(app: AppHandle) -> Option<UpdateInfo> {
|
|||||||
/// app. Returns only on failure.
|
/// app. Returns only on failure.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn install_update(app: AppHandle) -> Result<(), String> {
|
pub async fn install_update(app: AppHandle) -> Result<(), String> {
|
||||||
|
// Defense in depth: `check` only ever stores a pending update on
|
||||||
|
// Windows, but this guard holds even if that ever changes.
|
||||||
|
if !cfg!(windows) {
|
||||||
|
return Err(LINUX_CANNOT_INSTALL.to_string());
|
||||||
|
}
|
||||||
let pending = app.state::<PendingUpdate>();
|
let pending = app.state::<PendingUpdate>();
|
||||||
if pending.installing.swap(true, Ordering::SeqCst) {
|
if pending.installing.swap(true, Ordering::SeqCst) {
|
||||||
return Err("Das Update wird bereits installiert".to_string());
|
return Err("Das Update wird bereits installiert".to_string());
|
||||||
@@ -450,13 +528,40 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_value(UpdateCheckResult::Error {
|
serde_json::to_value(UpdateCheckResult::Error {
|
||||||
message: "Update-Server nicht erreichbar: x".into()
|
message: "Update-Prüfung fehlgeschlagen: x".into()
|
||||||
})
|
})
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
serde_json::json!({"status": "error", "message": "Update-Server nicht erreichbar: x"})
|
serde_json::json!({"status": "error", "message": "Update-Prüfung fehlgeschlagen: x"})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Only Windows self-updates: elsewhere a found update is still
|
||||||
|
/// reported (so the settings can show the version), but never stored
|
||||||
|
/// for `install_update` or announced to the banner.
|
||||||
|
#[test]
|
||||||
|
fn only_windows_offers_to_install_a_found_update() {
|
||||||
|
assert_eq!(
|
||||||
|
check_outcome(true, Some("0.3.0".into())),
|
||||||
|
(
|
||||||
|
UpdateCheckResult::Available {
|
||||||
|
version: "0.3.0".into()
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
check_outcome(false, Some("0.3.0".into())),
|
||||||
|
(
|
||||||
|
UpdateCheckResult::Available {
|
||||||
|
version: "0.3.0".into()
|
||||||
|
},
|
||||||
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(check_outcome(true, None), (UpdateCheckResult::None, false));
|
||||||
|
assert_eq!(check_outcome(false, None), (UpdateCheckResult::None, false));
|
||||||
|
}
|
||||||
|
|
||||||
/// A manual check feeds the very scheduler the background loop reads
|
/// A manual check feeds the very scheduler the background loop reads
|
||||||
/// (`record` is the one function either kind of attempt calls): a
|
/// (`record` is the one function either kind of attempt calls): a
|
||||||
/// failure advances the backoff by exactly the one step a single
|
/// failure advances the backoff by exactly the one step a single
|
||||||
@@ -485,4 +590,39 @@ mod tests {
|
|||||||
assert!(!schedule.is_due(t0() + MIN + 6 * HOUR - MIN));
|
assert!(!schedule.is_due(t0() + MIN + 6 * HOUR - MIN));
|
||||||
assert!(schedule.is_due(t0() + MIN + 6 * HOUR));
|
assert!(schedule.is_due(t0() + MIN + 6 * HOUR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A background tick that found a check due, but only got `running`
|
||||||
|
/// after a manual check finished, must not check again: `is_due` is
|
||||||
|
/// re-checked once the lock is held. Sequential here (the tick's own
|
||||||
|
/// early `is_due` happened before the manual check, so only the
|
||||||
|
/// re-check inside `attempt` can stop it).
|
||||||
|
#[test]
|
||||||
|
fn a_background_attempt_rechecks_due_once_it_holds_the_lock() {
|
||||||
|
let schedule = UpdateSchedule::default();
|
||||||
|
assert!(
|
||||||
|
schedule.is_due(SystemTime::now()),
|
||||||
|
"the tick saw a due check"
|
||||||
|
);
|
||||||
|
|
||||||
|
let manual = tauri::async_runtime::block_on(
|
||||||
|
schedule.attempt(false, || async { UpdateCheckResult::None }),
|
||||||
|
);
|
||||||
|
assert_eq!(manual, Some(UpdateCheckResult::None));
|
||||||
|
|
||||||
|
let mut checked = false;
|
||||||
|
let background = tauri::async_runtime::block_on(schedule.attempt(true, || {
|
||||||
|
checked = true;
|
||||||
|
async { UpdateCheckResult::None }
|
||||||
|
}));
|
||||||
|
assert_eq!(background, None);
|
||||||
|
assert!(!checked, "no second check right after the manual one");
|
||||||
|
|
||||||
|
// A manual check always runs, due or not.
|
||||||
|
let again = tauri::async_runtime::block_on(schedule.attempt(false, || async {
|
||||||
|
UpdateCheckResult::Error {
|
||||||
|
message: "x".into(),
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
assert!(matches!(again, Some(UpdateCheckResult::Error { .. })));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Gesprächsrekorder",
|
"productName": "Gesprächsrekorder",
|
||||||
"version": "0.2.1",
|
"version": "0.3.0",
|
||||||
"identifier": "eu.euvino.callrecorder",
|
"identifier": "eu.euvino.callrecorder",
|
||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../ui/dist",
|
"frontendDist": "../ui/dist",
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ui",
|
"name": "ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.2.1",
|
"version": "0.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -28,12 +28,15 @@
|
|||||||
aria-current={call.id === selectedId}
|
aria-current={call.id === selectedId}
|
||||||
onclick={() => onselect(call.id)}
|
onclick={() => onselect(call.id)}
|
||||||
>
|
>
|
||||||
|
{#if call.needs_action}
|
||||||
|
<span class="dot" title="Offen" aria-label="Offen"></span>
|
||||||
|
{/if}
|
||||||
<span class="title">{call.title ?? appLine(call)}</span>
|
<span class="title">{call.title ?? appLine(call)}</span>
|
||||||
<span class="meta">
|
<span class="meta">
|
||||||
<span class="muted">
|
<span class="muted">
|
||||||
{call.title ? `${appLine(call)} · ` : ''}{formatListTime(call.started_at)}
|
{call.title ? `${appLine(call)} · ` : ''}{formatListTime(call.started_at)}
|
||||||
</span>
|
</span>
|
||||||
<StatusPill status={call.status} interrupted={call.interrupted} />
|
<StatusPill state={call.list_state} interrupted={call.interrupted} />
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@@ -53,11 +56,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 3px;
|
gap: 3px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 9px 10px;
|
padding: 9px 10px 9px 18px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: none;
|
background: none;
|
||||||
@@ -67,6 +71,20 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
position: absolute;
|
||||||
|
left: 7px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--primary);
|
||||||
|
/* A thin ring so the dot stays visible against the selected row's
|
||||||
|
primary-soft background (and the hover background). */
|
||||||
|
box-shadow: 0 0 0 2px var(--surface);
|
||||||
|
}
|
||||||
|
|
||||||
.row:hover {
|
.row:hover {
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,248 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onDestroy } from 'svelte'
|
||||||
|
import { errorText, playbackUrl, preparePlayback, releasePlayback, type CallId } from './api'
|
||||||
|
import { formatOffset } from './format'
|
||||||
|
|
||||||
|
let {
|
||||||
|
callId,
|
||||||
|
estimate,
|
||||||
|
ontime,
|
||||||
|
onplaying,
|
||||||
|
}: {
|
||||||
|
callId: CallId
|
||||||
|
/** The call's length from its times, shown until the mix is ready. */
|
||||||
|
estimate: number
|
||||||
|
/** The playback position, once the mix is loaded (also while paused). */
|
||||||
|
ontime?: (secs: number) => void
|
||||||
|
onplaying?: (playing: boolean) => void
|
||||||
|
} = $props()
|
||||||
|
|
||||||
|
let audio: HTMLAudioElement
|
||||||
|
/** Resolves once the mix is loaded; `false` if preparing it failed. */
|
||||||
|
let loading: Promise<boolean> | null = null
|
||||||
|
let preparing = $state(false)
|
||||||
|
let playing = $state(false)
|
||||||
|
// svelte-ignore state_referenced_locally
|
||||||
|
let duration = $state(estimate)
|
||||||
|
let position = $state(0)
|
||||||
|
/** While the slider is dragged it shows the drag, not the audio. */
|
||||||
|
let dragging = $state(false)
|
||||||
|
let error = $state('')
|
||||||
|
/** The mix held in memory where the webview cannot stream it (Linux). */
|
||||||
|
let blobUrl: string | null = null
|
||||||
|
/** This player's hold on the mix on disk (see `releasePlayback`). */
|
||||||
|
let lease: number | null = null
|
||||||
|
/** Set once the player is gone: a load still under way stops at the next
|
||||||
|
* step and keeps nothing (no blob, no mix on disk). */
|
||||||
|
let destroyed = false
|
||||||
|
const abort = new AbortController()
|
||||||
|
|
||||||
|
const LOAD_FAILED = 'Audio konnte nicht geladen werden.'
|
||||||
|
|
||||||
|
/** Lets go of the mix on disk (once). */
|
||||||
|
function release() {
|
||||||
|
if (lease === null) return
|
||||||
|
releasePlayback(callId, lease).catch(() => {})
|
||||||
|
lease = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mixes the call (first use only) and loads the mix into the player. */
|
||||||
|
function load(): Promise<boolean> {
|
||||||
|
loading ??= (async () => {
|
||||||
|
preparing = true
|
||||||
|
error = ''
|
||||||
|
try {
|
||||||
|
const prepared = await preparePlayback(callId)
|
||||||
|
lease = prepared.lease
|
||||||
|
if (destroyed) return false
|
||||||
|
duration = prepared.duration_secs
|
||||||
|
const url = playbackUrl(callId)
|
||||||
|
try {
|
||||||
|
await loadSource(url)
|
||||||
|
} catch (err) {
|
||||||
|
if (destroyed) return false
|
||||||
|
if (!(err instanceof MediaError) || err.code !== MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
// WebKitGTK (Linux) plays no media from a custom scheme such as
|
||||||
|
// playback:// (WebView2 gets http://playback.localhost instead),
|
||||||
|
// but fetches it fine: there the mix is played from memory, and
|
||||||
|
// the file is not needed any more.
|
||||||
|
const response = await fetch(url, { signal: abort.signal })
|
||||||
|
if (!response.ok) throw new Error(LOAD_FAILED)
|
||||||
|
const blob = await response.blob()
|
||||||
|
if (destroyed) return false
|
||||||
|
blobUrl = URL.createObjectURL(blob)
|
||||||
|
release()
|
||||||
|
await loadSource(blobUrl)
|
||||||
|
}
|
||||||
|
return !destroyed
|
||||||
|
} catch (err) {
|
||||||
|
if (destroyed) return false
|
||||||
|
error = err instanceof MediaError ? LOAD_FAILED : errorText(err)
|
||||||
|
loading = null // a later click tries again
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
if (destroyed) release()
|
||||||
|
preparing = false
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
return loading
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Loads `src` into the player; rejects with its `MediaError`. */
|
||||||
|
function loadSource(src: string): Promise<void> {
|
||||||
|
const ready = new Promise<void>((resolve, reject) => {
|
||||||
|
const ok = () => {
|
||||||
|
audio.removeEventListener('error', fail)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
const fail = () => {
|
||||||
|
audio.removeEventListener('loadedmetadata', ok)
|
||||||
|
reject(audio.error)
|
||||||
|
}
|
||||||
|
audio.addEventListener('loadedmetadata', ok, { once: true })
|
||||||
|
audio.addEventListener('error', fail, { once: true })
|
||||||
|
})
|
||||||
|
audio.src = src
|
||||||
|
return ready
|
||||||
|
}
|
||||||
|
|
||||||
|
async function start() {
|
||||||
|
try {
|
||||||
|
await audio.play()
|
||||||
|
} catch (err) {
|
||||||
|
error = `Wiedergabe nicht möglich: ${errorText(err)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggle() {
|
||||||
|
if (playing) {
|
||||||
|
audio.pause()
|
||||||
|
} else if (await load()) {
|
||||||
|
await start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Jumps to `secs` and plays from there (a click on a transcript line). */
|
||||||
|
export async function playFrom(secs: number) {
|
||||||
|
if (!(await load())) return
|
||||||
|
audio.currentTime = Math.min(secs, duration)
|
||||||
|
position = audio.currentTime
|
||||||
|
if (audio.paused) await start()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function seekTo(secs: number) {
|
||||||
|
dragging = false
|
||||||
|
position = secs
|
||||||
|
if (!(await load())) return
|
||||||
|
audio.currentTime = secs
|
||||||
|
}
|
||||||
|
|
||||||
|
function ontimeupdate() {
|
||||||
|
if (!dragging) position = audio.currentTime
|
||||||
|
ontime?.(audio.currentTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPlaying(value: boolean) {
|
||||||
|
playing = value
|
||||||
|
onplaying?.(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
destroyed = true
|
||||||
|
abort.abort()
|
||||||
|
// Lets go of the file and the memory, so the call can be deleted right
|
||||||
|
// away and no customer audio stays behind.
|
||||||
|
audio?.pause()
|
||||||
|
audio?.removeAttribute('src')
|
||||||
|
audio?.load()
|
||||||
|
if (blobUrl) URL.revokeObjectURL(blobUrl)
|
||||||
|
blobUrl = null
|
||||||
|
release()
|
||||||
|
onplaying?.(false)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="player">
|
||||||
|
<audio
|
||||||
|
bind:this={audio}
|
||||||
|
preload="metadata"
|
||||||
|
{ontimeupdate}
|
||||||
|
onplay={() => setPlaying(true)}
|
||||||
|
onpause={() => setPlaying(false)}
|
||||||
|
onended={() => setPlaying(false)}
|
||||||
|
></audio>
|
||||||
|
<button
|
||||||
|
class="play"
|
||||||
|
disabled={preparing}
|
||||||
|
title={playing ? 'Pause' : 'Abspielen'}
|
||||||
|
aria-label={playing ? 'Pause' : 'Abspielen'}
|
||||||
|
onclick={toggle}
|
||||||
|
>
|
||||||
|
{#if preparing}…{:else if playing}❚❚{:else}▶{/if}
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
class="timeline"
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max={duration || 1}
|
||||||
|
step="0.1"
|
||||||
|
value={position}
|
||||||
|
disabled={preparing}
|
||||||
|
aria-label="Position"
|
||||||
|
oninput={(e) => {
|
||||||
|
dragging = true
|
||||||
|
position = Number(e.currentTarget.value)
|
||||||
|
}}
|
||||||
|
onchange={(e) => seekTo(Number(e.currentTarget.value))}
|
||||||
|
/>
|
||||||
|
<span class="time">{formatOffset(position)} / {formatOffset(duration)}</span>
|
||||||
|
{#if preparing}
|
||||||
|
<span class="muted">Audio wird vorbereitet…</span>
|
||||||
|
{:else if error}
|
||||||
|
<span class="error">{error}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.player {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px 10px;
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: none;
|
||||||
|
background: var(--primary);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.play:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline {
|
||||||
|
flex: 1 1 160px;
|
||||||
|
min-width: 120px;
|
||||||
|
accent-color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,21 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { CallStatus } from './api'
|
import type { ListState } from './api'
|
||||||
|
|
||||||
let { status, interrupted = false }: { status: CallStatus; interrupted?: boolean } = $props()
|
let { state, interrupted = false }: { state: ListState; interrupted?: boolean } = $props()
|
||||||
|
|
||||||
const pills: Record<CallStatus, { text: string; kind: string }> = {
|
const pills: Record<ListState, { text: string; kind: string }> = {
|
||||||
done: { text: 'fertig', kind: 'done' },
|
done: { text: 'fertig', kind: 'done' },
|
||||||
|
ready_to_upload: { text: 'bereit zum Hochladen', kind: 'ready' },
|
||||||
processing: { text: 'wird verarbeitet…', kind: 'processing' },
|
processing: { text: 'wird verarbeitet…', kind: 'processing' },
|
||||||
awaiting_decision: { text: 'nicht transkribiert', kind: 'awaiting' },
|
awaiting_decision: { text: 'nicht transkribiert', kind: 'awaiting' },
|
||||||
failed: { text: 'fehlgeschlagen', kind: 'failed' },
|
failed: { text: 'fehlgeschlagen', kind: 'failed' },
|
||||||
recording: { text: 'Aufnahme läuft', kind: 'recording' },
|
recording: { text: 'Aufnahme läuft', kind: 'recording' },
|
||||||
}
|
}
|
||||||
|
|
||||||
let pill = $derived(pills[status])
|
let pill = $derived(pills[state])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<span class="pill status {pill.kind}">
|
<span class="pill status {pill.kind}">
|
||||||
{pill.text}{#if interrupted && status === 'awaiting_decision'}, unterbrochen{/if}
|
{pill.text}{#if interrupted && state === 'awaiting_decision'}, unterbrochen{/if}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -28,6 +29,11 @@
|
|||||||
color: var(--ok);
|
color: var(--ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ready {
|
||||||
|
background: var(--primary-soft);
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
.processing {
|
.processing {
|
||||||
background: #fff4d6;
|
background: #fff4d6;
|
||||||
color: #8a6100;
|
color: #8a6100;
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
onrename,
|
onrename,
|
||||||
onmerge,
|
onmerge,
|
||||||
onunmerge,
|
onunmerge,
|
||||||
|
activeIndex = null,
|
||||||
|
follow = false,
|
||||||
|
onseek,
|
||||||
}: {
|
}: {
|
||||||
/** The transcript with merges applied: merged speakers no longer appear. */
|
/** The transcript with merges applied: merged speakers no longer appear. */
|
||||||
segments: SegmentView[]
|
segments: SegmentView[]
|
||||||
@@ -18,8 +21,45 @@
|
|||||||
onmerge: (fromKey: string, intoKey: string) => Promise<void>
|
onmerge: (fromKey: string, intoKey: string) => Promise<void>
|
||||||
/** Undoes the merge of `fromKey`. */
|
/** Undoes the merge of `fromKey`. */
|
||||||
onunmerge: (fromKey: string) => Promise<void>
|
onunmerge: (fromKey: string) => Promise<void>
|
||||||
|
/** The line being heard; it is highlighted. */
|
||||||
|
activeIndex?: number | null
|
||||||
|
/** Scrolls the line being heard into view when it leaves the view. */
|
||||||
|
follow?: boolean
|
||||||
|
/** Plays from `secs`, a line's start (only while the audio is there). */
|
||||||
|
onseek?: (secs: number) => void
|
||||||
} = $props()
|
} = $props()
|
||||||
|
|
||||||
|
let lineElements: HTMLElement[] = $state([])
|
||||||
|
|
||||||
|
/** A click on a line's text plays from it, unless text was selected. */
|
||||||
|
function lineClick(start: number) {
|
||||||
|
if (window.getSelection()?.toString()) return
|
||||||
|
onseek?.(start)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The nearest ancestor that scrolls vertically. */
|
||||||
|
function scrollParent(node: HTMLElement): HTMLElement | null {
|
||||||
|
for (let el = node.parentElement; el; el = el.parentElement) {
|
||||||
|
if (/(auto|scroll)/.test(getComputedStyle(el).overflowY)) return el
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Following the playback scrolls only once the line has left the view
|
||||||
|
// (also when it hides under the sticky player), and then centres it.
|
||||||
|
$effect(() => {
|
||||||
|
if (!follow || activeIndex === null) return
|
||||||
|
const line = lineElements[activeIndex]
|
||||||
|
const parent = line && scrollParent(line)
|
||||||
|
if (!line || !parent) return
|
||||||
|
const view = parent.getBoundingClientRect()
|
||||||
|
const box = line.getBoundingClientRect()
|
||||||
|
const covered = parseFloat(getComputedStyle(line).scrollMarginTop) || 0
|
||||||
|
if (box.top < view.top + covered || box.bottom > view.bottom) {
|
||||||
|
line.scrollIntoView({ block: 'center' })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// "Ich" is always the primary blue; remote speakers cycle through the rest.
|
// "Ich" is always the primary blue; remote speakers cycle through the rest.
|
||||||
const ME_COLOR = '#3b5bdb'
|
const ME_COLOR = '#3b5bdb'
|
||||||
const REMOTE_COLORS = ['#2b8a3e', '#c2255c', '#e8590c', '#7048e8', '#0c8599', '#5c940d']
|
const REMOTE_COLORS = ['#2b8a3e', '#c2255c', '#e8590c', '#7048e8', '#0c8599', '#5c940d']
|
||||||
@@ -186,8 +226,27 @@
|
|||||||
|
|
||||||
<div class="lines">
|
<div class="lines">
|
||||||
{#each segments as segment, i (i)}
|
{#each segments as segment, i (i)}
|
||||||
<div class="line">
|
<!-- The time is the keyboard-accessible way to play a line. -->
|
||||||
<span class="time">{formatOffset(segment.start)}</span>
|
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
||||||
|
<div
|
||||||
|
class="line"
|
||||||
|
class:active={i === activeIndex}
|
||||||
|
class:seekable={onseek !== undefined}
|
||||||
|
bind:this={lineElements[i]}
|
||||||
|
onclick={() => lineClick(segment.start)}
|
||||||
|
>
|
||||||
|
{#if onseek}
|
||||||
|
<button
|
||||||
|
class="time"
|
||||||
|
title="Ab hier abspielen"
|
||||||
|
onclick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
onseek(segment.start)
|
||||||
|
}}>{formatOffset(segment.start)}</button
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<span class="time">{formatOffset(segment.start)}</span>
|
||||||
|
{/if}
|
||||||
<span class="speaker" style:color={speakerColor(segment.speaker_key)}>{segment.label}</span>
|
<span class="speaker" style:color={speakerColor(segment.speaker_key)}>{segment.label}</span>
|
||||||
<span class="text">{segment.text}</span>
|
<span class="text">{segment.text}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -324,12 +383,33 @@
|
|||||||
.lines {
|
.lines {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto auto 1fr;
|
grid-template-columns: auto auto 1fr;
|
||||||
gap: 8px 12px;
|
column-gap: 12px;
|
||||||
margin-top: 14px;
|
margin: 10px -8px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* One row of the transcript grid that can be highlighted as a whole. */
|
||||||
.line {
|
.line {
|
||||||
display: contents;
|
display: grid;
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
grid-template-columns: subgrid;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 6px;
|
||||||
|
/* Room for the sticky player when the line is scrolled into view. */
|
||||||
|
scroll-margin-top: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line.seekable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line.seekable:hover {
|
||||||
|
background: var(--bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.line.active,
|
||||||
|
.line.active:hover {
|
||||||
|
background: var(--primary-soft);
|
||||||
|
box-shadow: inset 3px 0 0 var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.time {
|
.time {
|
||||||
@@ -339,6 +419,22 @@
|
|||||||
padding-top: 1px;
|
padding-top: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.time {
|
||||||
|
align-self: start;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
padding: 1px 0 0;
|
||||||
|
font-family: inherit;
|
||||||
|
line-height: inherit;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.time:hover {
|
||||||
|
color: var(--primary);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
.speaker {
|
.speaker {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
max-width: 160px;
|
max-width: 160px;
|
||||||
|
|||||||
+41
-1
@@ -1,6 +1,6 @@
|
|||||||
// Typed wrappers around the Tauri commands and events of the app shell.
|
// Typed wrappers around the Tauri commands and events of the app shell.
|
||||||
|
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import { convertFileSrc, invoke } from '@tauri-apps/api/core'
|
||||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||||
|
|
||||||
export type CallId = number
|
export type CallId = number
|
||||||
@@ -11,6 +11,8 @@ export interface Settings {
|
|||||||
output_device: string | null
|
output_device: string | null
|
||||||
language: string
|
language: string
|
||||||
deepscript_model: string
|
deepscript_model: string
|
||||||
|
/** Custom words/names submitted with every transcription. */
|
||||||
|
vocabulary: string[]
|
||||||
retention_days: number
|
retention_days: number
|
||||||
autostart: boolean
|
autostart: boolean
|
||||||
start_after_secs: number
|
start_after_secs: number
|
||||||
@@ -79,6 +81,18 @@ export interface PendingPrompt extends CallBrief {
|
|||||||
|
|
||||||
export type CallStatus = 'recording' | 'awaiting_decision' | 'processing' | 'done' | 'failed'
|
export type CallStatus = 'recording' | 'awaiting_decision' | 'processing' | 'done' | 'failed'
|
||||||
|
|
||||||
|
/** What the status pill shows and whether the row needs the user's
|
||||||
|
* attention. Mirrors `CallStatus`, except `done` splits into `done`
|
||||||
|
* (uploaded to this build's backend — "fertig") and `ready_to_upload`
|
||||||
|
* (not uploaded here yet — "bereit zum Hochladen"). */
|
||||||
|
export type ListState =
|
||||||
|
| 'recording'
|
||||||
|
| 'awaiting_decision'
|
||||||
|
| 'processing'
|
||||||
|
| 'failed'
|
||||||
|
| 'done'
|
||||||
|
| 'ready_to_upload'
|
||||||
|
|
||||||
/** A row of the main window's call list. Times are RFC 3339. */
|
/** A row of the main window's call list. Times are RFC 3339. */
|
||||||
export interface CallListItem {
|
export interface CallListItem {
|
||||||
id: CallId
|
id: CallId
|
||||||
@@ -87,6 +101,10 @@ export interface CallListItem {
|
|||||||
/** 0 while recording. */
|
/** 0 while recording. */
|
||||||
duration_secs: number
|
duration_secs: number
|
||||||
status: CallStatus
|
status: CallStatus
|
||||||
|
list_state: ListState
|
||||||
|
/** Whether this row needs the user to act on it (the dot in the list,
|
||||||
|
* counted in the sidebar header's "N offen"). */
|
||||||
|
needs_action: boolean
|
||||||
interrupted: boolean
|
interrupted: boolean
|
||||||
/** The name the user gave the call, if any. */
|
/** The name the user gave the call, if any. */
|
||||||
title: string | null
|
title: string | null
|
||||||
@@ -122,6 +140,18 @@ export interface CallDetail {
|
|||||||
merges: SpeakerMerge[]
|
merges: SpeakerMerge[]
|
||||||
/** The transcript is being uploaded right now. */
|
/** The transcript is being uploaded right now. */
|
||||||
uploading: boolean
|
uploading: boolean
|
||||||
|
/** The call's audio is still on this PC and can be played. */
|
||||||
|
audio_available: boolean
|
||||||
|
/** Retention deleted the call's audio (not just: the files are missing). */
|
||||||
|
audio_deleted: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A call's two tracks mixed into one file, ready to play from
|
||||||
|
* `playbackUrl`. */
|
||||||
|
export interface PreparedPlayback {
|
||||||
|
duration_secs: number
|
||||||
|
/** Hand back with `releasePlayback` once the player is done. */
|
||||||
|
lease: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A newer version the release feed offers. */
|
/** A newer version the release feed offers. */
|
||||||
@@ -170,6 +200,16 @@ export const getCallBrief = (id: CallId) => invoke<CallBrief>('get_call_brief',
|
|||||||
export const transcribeCall = (id: CallId) => invoke<void>('transcribe_call', { id })
|
export const transcribeCall = (id: CallId) => invoke<void>('transcribe_call', { id })
|
||||||
export const retryCall = (id: CallId) => invoke<void>('retry_call', { id })
|
export const retryCall = (id: CallId) => invoke<void>('retry_call', { id })
|
||||||
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
|
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
|
||||||
|
/** Mixes the call's tracks (or reuses the cached mix); refused while the
|
||||||
|
* call is recorded or processed and once its audio is gone. */
|
||||||
|
export const preparePlayback = (id: CallId) =>
|
||||||
|
invoke<PreparedPlayback>('prepare_playback', { id })
|
||||||
|
/** The player is done with the mix: it is removed from disk. */
|
||||||
|
export const releasePlayback = (id: CallId, lease: number) =>
|
||||||
|
invoke<void>('release_playback', { id, lease })
|
||||||
|
/** Where the main window plays a prepared mix from (the app's `playback`
|
||||||
|
* scheme; other windows are refused). */
|
||||||
|
export const playbackUrl = (id: CallId) => convertFileSrc(String(id), 'playback')
|
||||||
export const listCalls = () => invoke<CallListItem[]>('list_calls')
|
export const listCalls = () => invoke<CallListItem[]>('list_calls')
|
||||||
export const getCall = (id: CallId) => invoke<CallDetail>('get_call', { id })
|
export const getCall = (id: CallId) => invoke<CallDetail>('get_call', { id })
|
||||||
/** An empty name restores the default label. */
|
/** An empty name restores the default label. */
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Couples playback to the transcript: which line is being heard.
|
||||||
|
|
||||||
|
/** The part of a transcript line the lookup needs. */
|
||||||
|
export interface Timed {
|
||||||
|
start: number
|
||||||
|
end: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Index of the line heard at `secs`: the one whose `[start, end)` holds
|
||||||
|
* it — of overlapping lines (both sides talking at once) the one that
|
||||||
|
* started last. `null` before the first line, in a pause between lines and
|
||||||
|
* after the last one. */
|
||||||
|
export function segmentAt(segments: readonly Timed[], secs: number): number | null {
|
||||||
|
let found: number | null = null
|
||||||
|
segments.forEach((segment, i) => {
|
||||||
|
if (segment.start <= secs && secs < segment.end) {
|
||||||
|
if (found === null || segment.start >= segments[found].start) found = i
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return found
|
||||||
|
}
|
||||||
+303
-16
@@ -5,6 +5,7 @@
|
|||||||
errorText,
|
errorText,
|
||||||
getCall,
|
getCall,
|
||||||
getRecordingState,
|
getRecordingState,
|
||||||
|
getSettings,
|
||||||
listCalls,
|
listCalls,
|
||||||
mergeSpeakers,
|
mergeSpeakers,
|
||||||
onBackendLoginError,
|
onBackendLoginError,
|
||||||
@@ -27,6 +28,8 @@
|
|||||||
} from '../lib/api'
|
} from '../lib/api'
|
||||||
import CallList from '../lib/CallList.svelte'
|
import CallList from '../lib/CallList.svelte'
|
||||||
import { formatDateTime, formatDetailTime, formatMinutes } from '../lib/format'
|
import { formatDateTime, formatDetailTime, formatMinutes } from '../lib/format'
|
||||||
|
import Player from '../lib/Player.svelte'
|
||||||
|
import { segmentAt } from '../lib/playback'
|
||||||
import StatusPill from '../lib/StatusPill.svelte'
|
import StatusPill from '../lib/StatusPill.svelte'
|
||||||
import TranscriptView from '../lib/TranscriptView.svelte'
|
import TranscriptView from '../lib/TranscriptView.svelte'
|
||||||
import UpdateBanner from '../lib/UpdateBanner.svelte'
|
import UpdateBanner from '../lib/UpdateBanner.svelte'
|
||||||
@@ -45,11 +48,27 @@
|
|||||||
let actionError = $state('')
|
let actionError = $state('')
|
||||||
let busy = $state(false)
|
let busy = $state(false)
|
||||||
|
|
||||||
|
// "Löschen" (transcribed calls): confirmed with a dialog instead of
|
||||||
|
// running straight away like the other actions.
|
||||||
|
let deleteDialogOpen = $state(false)
|
||||||
|
let deleteBusy = $state(false)
|
||||||
|
let deleteError = $state('')
|
||||||
|
|
||||||
// Uploads run per call and may outlive the selection (the login can
|
// Uploads run per call and may outlive the selection (the login can
|
||||||
// take a while); their errors are kept per call too.
|
// take a while); their errors are kept per call too.
|
||||||
let uploading = $state<CallId[]>([])
|
let uploading = $state<CallId[]>([])
|
||||||
let uploadErrors = $state<Record<CallId, string>>({})
|
let uploadErrors = $state<Record<CallId, string>>({})
|
||||||
|
|
||||||
|
// Playback of the shown call (the player itself lives in `Player`).
|
||||||
|
let player = $state<ReturnType<typeof Player>>()
|
||||||
|
/** The playback position once the mix is loaded, else `null`. */
|
||||||
|
let playerTime = $state<number | null>(null)
|
||||||
|
let playing = $state(false)
|
||||||
|
/** Whether the transcript scrolls along; scrolling by hand ends it. */
|
||||||
|
let follow = $state(true)
|
||||||
|
/** For "… werden N Tage nach der Transkription gelöscht". */
|
||||||
|
let retentionDays = $state<number | null>(null)
|
||||||
|
|
||||||
let editingTitle = $state(false)
|
let editingTitle = $state(false)
|
||||||
let titleDraft = $state('')
|
let titleDraft = $state('')
|
||||||
let savingTitle = $state(false)
|
let savingTitle = $state(false)
|
||||||
@@ -97,24 +116,36 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetPlayback() {
|
||||||
|
playerTime = null
|
||||||
|
playing = false
|
||||||
|
follow = true
|
||||||
|
}
|
||||||
|
|
||||||
function select(id: CallId) {
|
function select(id: CallId) {
|
||||||
if (id === selectedId) return
|
if (id === selectedId) return
|
||||||
selectedId = id
|
selectedId = id
|
||||||
|
resetPlayback()
|
||||||
detail = null
|
detail = null
|
||||||
detailError = ''
|
detailError = ''
|
||||||
actionError = ''
|
actionError = ''
|
||||||
editingTitle = false
|
editingTitle = false
|
||||||
titleError = ''
|
titleError = ''
|
||||||
|
deleteDialogOpen = false
|
||||||
|
deleteError = ''
|
||||||
refreshDetail()
|
refreshDetail()
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearSelection() {
|
function clearSelection() {
|
||||||
selectedId = null
|
selectedId = null
|
||||||
|
resetPlayback()
|
||||||
detail = null
|
detail = null
|
||||||
detailError = ''
|
detailError = ''
|
||||||
actionError = ''
|
actionError = ''
|
||||||
editingTitle = false
|
editingTitle = false
|
||||||
titleError = ''
|
titleError = ''
|
||||||
|
deleteDialogOpen = false
|
||||||
|
deleteError = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -135,6 +166,12 @@
|
|||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
refreshList()
|
refreshList()
|
||||||
|
// Read on every visit: the settings page is a route of this window, so
|
||||||
|
// a changed retention period is shown on the way back. Without it the
|
||||||
|
// "no audio" line just leaves the period out.
|
||||||
|
getSettings()
|
||||||
|
.then((settings) => (retentionDays = settings.retention_days))
|
||||||
|
.catch((err) => console.warn('settings not read:', errorText(err)))
|
||||||
getRecordingState()
|
getRecordingState()
|
||||||
.then((state) => (recordingState = state))
|
.then((state) => (recordingState = state))
|
||||||
.catch((err) => (recordError = errorText(err)))
|
.catch((err) => (recordError = errorText(err)))
|
||||||
@@ -189,6 +226,49 @@
|
|||||||
refreshList()
|
refreshList()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** "Löschen" on a transcribed call: asks for confirmation first. */
|
||||||
|
function askDelete() {
|
||||||
|
deleteError = ''
|
||||||
|
deleteDialogOpen = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelDelete() {
|
||||||
|
deleteDialogOpen = false
|
||||||
|
deleteError = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Confirmed delete: same backend path as "Verwerfen" (`discard_call`).
|
||||||
|
* On success the selection moves to the next call in the list, or clears
|
||||||
|
* if none is left. */
|
||||||
|
async function confirmDelete() {
|
||||||
|
if (!detail) return
|
||||||
|
const id = detail.call.id
|
||||||
|
deleteBusy = true
|
||||||
|
try {
|
||||||
|
await discardCall(id)
|
||||||
|
deleteDialogOpen = false
|
||||||
|
selectAfterDelete(id)
|
||||||
|
refreshList()
|
||||||
|
} catch (err) {
|
||||||
|
deleteError = errorText(err)
|
||||||
|
} finally {
|
||||||
|
deleteBusy = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selects the call that took `deletedId`'s place in the list (or the one
|
||||||
|
* before it, if `deletedId` was last), else clears the selection. */
|
||||||
|
function selectAfterDelete(deletedId: CallId) {
|
||||||
|
const index = calls.findIndex((c) => c.id === deletedId)
|
||||||
|
const remaining = calls.filter((c) => c.id !== deletedId)
|
||||||
|
if (remaining.length === 0) {
|
||||||
|
clearSelection()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const next = remaining[Math.min(Math.max(index, 0), remaining.length - 1)]
|
||||||
|
select(next.id)
|
||||||
|
}
|
||||||
|
|
||||||
/** Uploads the shown call's transcript (logging in first if needed). A
|
/** Uploads the shown call's transcript (logging in first if needed). A
|
||||||
* call already uploaded has no button any more: the CRM never gets a
|
* call already uploaded has no button any more: the CRM never gets a
|
||||||
* duplicate. */
|
* duplicate. */
|
||||||
@@ -257,6 +337,28 @@
|
|||||||
node.select()
|
node.select()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A click on a transcript line: plays from there and follows again. */
|
||||||
|
function playFrom(secs: number) {
|
||||||
|
follow = true
|
||||||
|
player?.playFrom(secs)
|
||||||
|
}
|
||||||
|
|
||||||
|
const SCROLL_KEYS = ['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', ' ']
|
||||||
|
|
||||||
|
/** Scrolling the detail by hand while playing stops following the
|
||||||
|
* playback (until "folgen" or a click on a line). Only user input counts:
|
||||||
|
* the transcript's own scrolling raises none of these events. */
|
||||||
|
function manualScroll(event: Event) {
|
||||||
|
if (!playing) return
|
||||||
|
if (event instanceof KeyboardEvent) {
|
||||||
|
const target = event.target as HTMLElement
|
||||||
|
if (!SCROLL_KEYS.includes(event.key) || target.closest('input, textarea, button')) return
|
||||||
|
}
|
||||||
|
// A press on the scroll bar (not on the content).
|
||||||
|
if (event instanceof PointerEvent && event.target !== event.currentTarget) return
|
||||||
|
follow = false
|
||||||
|
}
|
||||||
|
|
||||||
/** "Microsoft Teams · heute 10:14 · 32 min" (no duration while recording). */
|
/** "Microsoft Teams · heute 10:14 · 32 min" (no duration while recording). */
|
||||||
function defaultTitle(call: CallListItem): string {
|
function defaultTitle(call: CallListItem): string {
|
||||||
const parts = [call.app, formatDetailTime(call.started_at)]
|
const parts = [call.app, formatDetailTime(call.started_at)]
|
||||||
@@ -273,13 +375,22 @@
|
|||||||
// A failed start (e.g. missing key) also marks the call failed; its
|
// A failed start (e.g. missing key) also marks the call failed; its
|
||||||
// error is then shown once, in the failure box.
|
// error is then shown once, in the failure box.
|
||||||
let shownActionError = $derived(actionError !== detail?.call.error ? actionError : '')
|
let shownActionError = $derived(actionError !== detail?.call.error ? actionError : '')
|
||||||
|
|
||||||
|
// Calls that still need the user's attention (not transcribed, or
|
||||||
|
// transcribed but not uploaded here) — shown as "Gespräche · N offen".
|
||||||
|
let openCount = $derived(calls.filter((c) => c.needs_action).length)
|
||||||
|
|
||||||
|
/** The transcript line being heard, highlighted while the mix is loaded. */
|
||||||
|
let activeIndex = $derived(
|
||||||
|
detail && playerTime !== null ? segmentAt(detail.segments, playerTime) : null,
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main class="main">
|
<main class="main">
|
||||||
<UpdateBanner />
|
<UpdateBanner />
|
||||||
<aside class="sidebar">
|
<aside class="sidebar">
|
||||||
<header class="sidebar-header">
|
<header class="sidebar-header">
|
||||||
<h1>Gespräche</h1>
|
<h1>Gespräche{#if openCount > 0}<span class="open-count" title="{openCount} offen" aria-label="{openCount} offen">{openCount}</span>{/if}</h1>
|
||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
<button
|
<button
|
||||||
class="btn small record-btn"
|
class="btn small record-btn"
|
||||||
@@ -307,7 +418,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<section class="detail">
|
<!-- The handlers only watch for scrolling by hand (see manualScroll). -->
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<section
|
||||||
|
class="detail"
|
||||||
|
onwheel={manualScroll}
|
||||||
|
ontouchmove={manualScroll}
|
||||||
|
onkeydown={manualScroll}
|
||||||
|
onpointerdown={manualScroll}
|
||||||
|
>
|
||||||
{#if detail}
|
{#if detail}
|
||||||
{@const call = detail.call}
|
{@const call = detail.call}
|
||||||
<header class="detail-header">
|
<header class="detail-header">
|
||||||
@@ -328,7 +447,7 @@
|
|||||||
<button class="edit-title" title="Titel ändern" onclick={startTitleEdit}>✎</button>
|
<button class="edit-title" title="Titel ändern" onclick={startTitleEdit}>✎</button>
|
||||||
</h1>
|
</h1>
|
||||||
{/if}
|
{/if}
|
||||||
<StatusPill status={call.status} interrupted={call.interrupted} />
|
<StatusPill state={call.list_state} interrupted={call.interrupted} />
|
||||||
</div>
|
</div>
|
||||||
{#if editingTitle}
|
{#if editingTitle}
|
||||||
<p class="muted subline">Enter speichert, Esc bricht ab. Leer = Standardtitel.</p>
|
<p class="muted subline">Enter speichert, Esc bricht ab. Leer = Standardtitel.</p>
|
||||||
@@ -351,14 +470,19 @@
|
|||||||
{:else if call.status === 'failed'}
|
{:else if call.status === 'failed'}
|
||||||
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
||||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||||
{:else if call.status === 'done' && !call.uploaded_at}
|
{:else if call.status === 'done'}
|
||||||
<button
|
{#if !call.uploaded_at}
|
||||||
class="btn primary"
|
<button
|
||||||
disabled={!call.transcribed_at || isUploading}
|
class="btn primary"
|
||||||
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
|
disabled={!call.transcribed_at || isUploading}
|
||||||
onclick={upload}
|
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
|
||||||
>
|
onclick={upload}
|
||||||
{isUploading ? 'wird hochgeladen…' : 'Transkript hochladen'}
|
>
|
||||||
|
{isUploading ? 'wird hochgeladen…' : 'Transkript hochladen'}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
<button class="btn danger" disabled={deleteBusy || isUploading} onclick={askDelete}>
|
||||||
|
Löschen
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
@@ -371,6 +495,40 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
{#if call.status !== 'recording' && call.status !== 'processing'}
|
||||||
|
{#if detail.audio_available}
|
||||||
|
<div class="playback-bar">
|
||||||
|
{#key call.id}
|
||||||
|
<Player
|
||||||
|
bind:this={player}
|
||||||
|
callId={call.id}
|
||||||
|
estimate={call.duration_secs}
|
||||||
|
ontime={(secs) => (playerTime = secs)}
|
||||||
|
onplaying={(value) => (playing = value)}
|
||||||
|
/>
|
||||||
|
{/key}
|
||||||
|
{#if call.status === 'done' && detail.segments.length > 0}
|
||||||
|
<button
|
||||||
|
class="btn small follow"
|
||||||
|
class:on={follow}
|
||||||
|
aria-pressed={follow}
|
||||||
|
title="Das Transkript scrollt mit der Wiedergabe mit"
|
||||||
|
onclick={() => (follow = !follow)}>folgen</button
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{:else if detail.audio_deleted && retentionDays !== null}
|
||||||
|
<p class="muted no-audio">
|
||||||
|
Audio nicht mehr vorhanden – Aufnahmen werden {retentionDays} Tage nach der
|
||||||
|
Transkription gelöscht (<a href="#/settings">Einstellungen</a>).
|
||||||
|
</p>
|
||||||
|
{:else if detail.audio_deleted}
|
||||||
|
<p class="muted no-audio">Audio nicht mehr vorhanden.</p>
|
||||||
|
{:else}
|
||||||
|
<p class="muted no-audio">Audio nicht vorhanden.</p>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="body">
|
<div class="body">
|
||||||
{#if call.status === 'recording'}
|
{#if call.status === 'recording'}
|
||||||
<p class="state rec">● Aufnahme läuft</p>
|
<p class="state rec">● Aufnahme läuft</p>
|
||||||
@@ -394,9 +552,46 @@
|
|||||||
onrename={rename}
|
onrename={rename}
|
||||||
onmerge={merge}
|
onmerge={merge}
|
||||||
onunmerge={unmerge}
|
onunmerge={unmerge}
|
||||||
|
{activeIndex}
|
||||||
|
follow={follow && playing}
|
||||||
|
onseek={detail.audio_available ? playFrom : undefined}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if deleteDialogOpen}
|
||||||
|
<div
|
||||||
|
class="dialog-backdrop"
|
||||||
|
onclick={cancelDelete}
|
||||||
|
onkeydown={(e) => e.key === 'Escape' && cancelDelete()}
|
||||||
|
role="presentation"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="dialog"
|
||||||
|
role="alertdialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-labelledby="delete-dialog-title"
|
||||||
|
tabindex="-1"
|
||||||
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
onkeydown={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<p class="dialog-title" id="delete-dialog-title">Gespräch löschen?</p>
|
||||||
|
<p>Audio und Transkript werden unwiderruflich von diesem PC gelöscht.</p>
|
||||||
|
{#if call.uploaded_at}
|
||||||
|
<p>Die Kopie im CRM bleibt erhalten.</p>
|
||||||
|
{/if}
|
||||||
|
{#if deleteError}
|
||||||
|
<p class="error">{deleteError}</p>
|
||||||
|
{/if}
|
||||||
|
<div class="dialog-actions">
|
||||||
|
<button class="btn danger" disabled={deleteBusy} onclick={confirmDelete}>
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
<button class="btn" disabled={deleteBusy} onclick={cancelDelete}>Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{:else if detailError}
|
{:else if detailError}
|
||||||
<p class="error pad">{detailError}</p>
|
<p class="error pad">{detailError}</p>
|
||||||
{:else if loaded && selectedId === null && calls.length > 0}
|
{:else if loaded && selectedId === null && calls.length > 0}
|
||||||
@@ -435,21 +630,47 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 14px 12px 10px 16px;
|
gap: 4px;
|
||||||
|
padding: 12px 6px 8px 10px;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-header h1 {
|
.sidebar-header h1 {
|
||||||
font-size: 16px;
|
flex: 0 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.open-count {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-left: 4px;
|
||||||
|
min-width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
padding: 0 3px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--primary-soft);
|
||||||
|
color: var(--primary);
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1;
|
||||||
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-actions {
|
.header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 6px;
|
gap: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.record-btn {
|
.record-btn {
|
||||||
|
padding: 2px 6px;
|
||||||
|
font-size: 11px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,9 +687,9 @@
|
|||||||
|
|
||||||
.gear {
|
.gear {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
font-size: 18px;
|
font-size: 15px;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
padding: 4px 6px;
|
padding: 3px 4px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
@@ -559,6 +780,36 @@
|
|||||||
margin: 10px 0 0;
|
margin: 10px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stays at the top while the transcript scrolls under it. */
|
||||||
|
.playback-bar {
|
||||||
|
position: sticky;
|
||||||
|
top: -18px; /* the detail's top padding: flush with its edge */
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin: 0 -24px 14px;
|
||||||
|
padding: 8px 24px;
|
||||||
|
background: var(--bg);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.follow {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--muted);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.follow.on {
|
||||||
|
border-color: var(--primary);
|
||||||
|
background: var(--primary-soft);
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-audio {
|
||||||
|
margin: 0 0 14px;
|
||||||
|
}
|
||||||
|
|
||||||
.state {
|
.state {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
@@ -574,4 +825,40 @@
|
|||||||
background: var(--rec-soft);
|
background: var(--rec-soft);
|
||||||
color: var(--rec);
|
color: var(--rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dialog-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(29, 35, 48, 0.4);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog {
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 12px 32px rgba(29, 35, 48, 0.25);
|
||||||
|
padding: 20px;
|
||||||
|
width: min(420px, calc(100vw - 32px));
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog p {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -43,6 +43,10 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
let settings = $state<Settings | null>(null)
|
let settings = $state<Settings | null>(null)
|
||||||
|
/** The vocabulary textarea's raw text, one term per line; converted
|
||||||
|
* to/from `settings.vocabulary` on load/save (the backend trims, drops
|
||||||
|
* blanks and deduplicates — see `Settings::edited`). */
|
||||||
|
let vocabularyText = $state('')
|
||||||
let devices = $state<Devices>({ inputs: [], outputs: [] })
|
let devices = $state<Devices>({ inputs: [], outputs: [] })
|
||||||
let keySaved = $state<Record<Service, boolean>>({ deepscript: false })
|
let keySaved = $state<Record<Service, boolean>>({ deepscript: false })
|
||||||
let keyInput = $state<Record<Service, string>>({ deepscript: '' })
|
let keyInput = $state<Record<Service, string>>({ deepscript: '' })
|
||||||
@@ -71,6 +75,24 @@
|
|||||||
let installProgress = $state<UpdateProgress | null>(null)
|
let installProgress = $state<UpdateProgress | null>(null)
|
||||||
let installError = $state('')
|
let installError = $state('')
|
||||||
|
|
||||||
|
/** The version to show as "available", if any. On Windows this comes
|
||||||
|
* from `pendingUpdate` (kept in sync with the banner by `get_update`/
|
||||||
|
* `update-available`, so it is current even without a manual check).
|
||||||
|
* Everywhere else the backend never stores `pendingUpdate` for a found
|
||||||
|
* update (see `updater::check_outcome`), so a manual check's own result
|
||||||
|
* is the only source. It is also the fallback whenever `pendingUpdate`
|
||||||
|
* is not known (e.g. the follow-up `getUpdate()` failed, or
|
||||||
|
* `canSelfUpdate()` failed): a found update is never hidden. */
|
||||||
|
let availableVersion = $derived(
|
||||||
|
(selfUpdateCapable === true ? pendingUpdate?.version : undefined) ??
|
||||||
|
(checkResult?.status === 'available' ? checkResult.version : undefined),
|
||||||
|
)
|
||||||
|
/** Whether the install button/progress can be offered for
|
||||||
|
* `availableVersion`: only once this build is confirmed able to
|
||||||
|
* self-update AND `pendingUpdate` (with its `can_install` guard) is
|
||||||
|
* actually known. */
|
||||||
|
let canOfferInstall = $derived(selfUpdateCapable === true && pendingUpdate !== null)
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
load()
|
load()
|
||||||
backendServer()
|
backendServer()
|
||||||
@@ -97,20 +119,22 @@
|
|||||||
|
|
||||||
/** "Nach Updates suchen": runs the same check as the background loop,
|
/** "Nach Updates suchen": runs the same check as the background loop,
|
||||||
* immediately. An available update also arrives via `update-available`
|
* immediately. An available update also arrives via `update-available`
|
||||||
* (so the main window's banner shows it too), but is applied here as
|
* (so the main window's banner shows it too, on Windows), but is applied
|
||||||
* well in case that event is missed. */
|
* here as well in case that event is missed. That follow-up fetch is
|
||||||
|
* best-effort: if it fails, the "available" result just found still
|
||||||
|
* stands — it must never be replaced by that unrelated failure. */
|
||||||
async function checkUpdateNow() {
|
async function checkUpdateNow() {
|
||||||
checking = true
|
checking = true
|
||||||
checkResult = null
|
checkResult = null
|
||||||
try {
|
try {
|
||||||
const result = await checkForUpdateNow()
|
checkResult = await checkForUpdateNow()
|
||||||
checkResult = result
|
|
||||||
if (result.status === 'available') pendingUpdate = await getUpdate()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
checkResult = { status: 'error', message: errorText(err) }
|
checkResult = { status: 'error', message: errorText(err) }
|
||||||
} finally {
|
|
||||||
checking = false
|
checking = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if (checkResult.status === 'available') await refreshPendingUpdate()
|
||||||
|
checking = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshPendingUpdate() {
|
async function refreshPendingUpdate() {
|
||||||
@@ -187,6 +211,7 @@
|
|||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
settings = await getSettings()
|
settings = await getSettings()
|
||||||
|
vocabularyText = settings.vocabulary.join('\n')
|
||||||
for (const { id } of services) keySaved[id] = await hasApiKey(id)
|
for (const { id } of services) keySaved[id] = await hasApiKey(id)
|
||||||
devices = await listDevices()
|
devices = await listDevices()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -248,7 +273,12 @@
|
|||||||
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
||||||
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
||||||
}
|
}
|
||||||
|
settings.vocabulary = vocabularyText.split('\n')
|
||||||
await saveSettings($state.snapshot(settings))
|
await saveSettings($state.snapshot(settings))
|
||||||
|
// Re-read: the backend trims/dedupes the vocabulary, so the textarea
|
||||||
|
// should show the cleaned-up list, not what was just typed.
|
||||||
|
settings = await getSettings()
|
||||||
|
vocabularyText = settings.vocabulary.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runTest() {
|
async function runTest() {
|
||||||
@@ -454,6 +484,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>Transkription</h2>
|
||||||
|
<div class="grid">
|
||||||
|
<label for="deepscript-model">Modell</label>
|
||||||
|
<select id="deepscript-model" bind:value={settings.deepscript_model}>
|
||||||
|
<option value="premium">Premium</option>
|
||||||
|
<option value="premium_jade">Premium Jade</option>
|
||||||
|
</select>
|
||||||
|
<span></span>
|
||||||
|
<span class="muted">Gilt für neue Transkriptionen.</span>
|
||||||
|
</div>
|
||||||
|
<label for="vocabulary" class="vocabulary-label">Vokabular (ein Begriff pro Zeile)</label>
|
||||||
|
<textarea id="vocabulary" rows="6" bind:value={vocabularyText}></textarea>
|
||||||
|
<p class="muted">
|
||||||
|
Namen, Firmen- und Produktbegriffe, die oft falsch erkannt werden.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<h2>Updates</h2>
|
<h2>Updates</h2>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
@@ -470,24 +518,30 @@
|
|||||||
<span class="error">{checkResult.message}</span>
|
<span class="error">{checkResult.message}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if pendingUpdate && selfUpdateCapable !== null}
|
{#if availableVersion !== undefined}
|
||||||
<div class="update-available">
|
<div class="update-available">
|
||||||
<span>Update verfügbar (v{pendingUpdate.version})</span>
|
<span>Update verfügbar (v{availableVersion})</span>
|
||||||
{#if selfUpdateCapable}
|
{#if canOfferInstall}
|
||||||
{#if installing}
|
{#if installing}
|
||||||
<span>{updateProgressText(installProgress)}</span>
|
<span>{updateProgressText(installProgress)}</span>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="btn primary small" disabled={!pendingUpdate.can_install} onclick={installUpdateNow}>
|
<button
|
||||||
|
class="btn primary small"
|
||||||
|
disabled={!pendingUpdate?.can_install}
|
||||||
|
onclick={installUpdateNow}
|
||||||
|
>
|
||||||
Installieren & neu starten
|
Installieren & neu starten
|
||||||
</button>
|
</button>
|
||||||
{#if !pendingUpdate.can_install}
|
{#if !pendingUpdate?.can_install}
|
||||||
<span class="muted">{UPDATE_BUSY_HINT}</span>
|
<span class="muted">{UPDATE_BUSY_HINT}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if installError}
|
{#if installError}
|
||||||
<span class="error">{installError}</span>
|
<span class="error">{installError}</span>
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else if selfUpdateCapable !== true}
|
||||||
|
<!-- Not able to self-update, or unknown (`canSelfUpdate()`
|
||||||
|
failed): never an install button, just the hint. -->
|
||||||
<span class="muted">
|
<span class="muted">
|
||||||
Updates gibt es unter Windows automatisch; unter Linux bitte das .deb neu installieren.
|
Updates gibt es unter Windows automatisch; unter Linux bitte das .deb neu installieren.
|
||||||
</span>
|
</span>
|
||||||
@@ -549,6 +603,21 @@
|
|||||||
justify-self: start;
|
justify-self: start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vocabulary-label {
|
||||||
|
display: block;
|
||||||
|
margin-top: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea#vocabulary {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 420px;
|
||||||
|
margin-top: 6px;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
.hint {
|
.hint {
|
||||||
margin: 12px 0;
|
margin: 12px 0;
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
|
|||||||
Reference in New Issue
Block a user