Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
687d4bccfe | ||
|
|
fa55dcb7bc | ||
|
|
dad98b4558 | ||
|
|
96eec22971 | ||
|
|
1735f431dd |
Generated
+1
-1
@@ -445,7 +445,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "call-recorder"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
|
||||
+4
-8
@@ -1,14 +1,10 @@
|
||||
{
|
||||
"version": "0.1.1",
|
||||
"pub_date": "2026-11-06T11:12:59Z",
|
||||
"version": "0.2.0",
|
||||
"pub_date": "2026-11-06T14:19:53Z",
|
||||
"platforms": {
|
||||
"windows-x86_64": {
|
||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUU5ME1DVkRlaXdwYXdpT0tvRk0rUFcvZXR4ditldzI5QWkyUVU2d0dqemN4UXhaMVA4bU8yQnJzU2ZJLzN1NnJFc3lWSmtqaDM2ZkFWeHBTdEtWQXdBPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzkzOTYzNDE1CWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMS4xX3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjEuMQpPdVllUzFVSm13UTFKL3BTRVpjeEVOTzh4Z2pnN1J4OW15TWpIM1B3V1YzNlFLam9DaEc4Q21PUTZKSjlRZXRlZUx1U1ROcytGemtTK0hOTXdsNmhCUT09Cg==",
|
||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.1.1/Gespraechsrekorder_0.1.1_x64-setup.exe"
|
||||
},
|
||||
"linux-x86_64": {
|
||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUtVMWk1Yzhjcy9CeTBzeTV3ck1YNXhpQTEzMm9ES1l4YVM2OGI1Z1Vnbm9EMXFmZlNtcjBNMWJOd0l1ei9vVVg4VkZwR2JicllHNkQreE5ZRWYxSndJPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzkzOTYzNTc5CWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMS4xX2FtZDY0LkFwcEltYWdlCXZlcnNpb246MC4xLjEKTUJnbWdKN0JWZytvcXl4UVAyRnlOaUhZempseXpEbE8yTGk0RldoZEZWVzQvWUF5V0pvb0Q2eG1mRjM3cnhnWWtTQjdzTS9pSkR0N0VBN245VnovQ2c9PQo=",
|
||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.1.1/Gespraechsrekorder_0.1.1_amd64.AppImage"
|
||||
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUdGpRa1ZvalU2SUtlUG9ZajRMcmFHb0dxNG1OM1lWZEExbzhsSjYzdUJxY1NrY2xERmRGbGJEV3c0UWRjdmVuaHFtWXlzYVU2alFJY0k4V1hoZ1FWdDVNV0xkclRQV2c0PQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzkzOTc0NzYxCWZpbGU6R2VzcHLDpGNoc3Jla29yZGVyXzAuMi4wX3g2NC1zZXR1cC5leGUJdmVyc2lvbjowLjIuMApna2tpeVdYMkhDU2d4ZjAwVTJaQjBBMG0yL010V2xIc3Awc0QzOXJsK2lmUi9oM1hwWmlvL2dNdFQzVzQrTys1ZnNmZHpXM0JicTRzd1d2MXp5YjhEQT09Cg==",
|
||||
"url": "https://gitea.euvino.eu/public/call-recorder/releases/download/v0.2.0/Gespraechsrekorder_0.2.0_x64-setup.exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "call-recorder"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
description = "Gesprächsrekorder desktop app"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
@@ -440,6 +440,14 @@ fn lock<T>(mutex: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn backend_urls_have_no_trailing_slash_and_use_https() {
|
||||
for url in [RELEASE_BACKEND_URL, DEV_BACKEND_URL] {
|
||||
assert!(!url.ends_with('/'), "{url}");
|
||||
assert!(url.starts_with("https://"), "{url}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn everyone_waiting_gets_the_one_login_result() {
|
||||
let waiters = LoginWaiters::default();
|
||||
|
||||
@@ -23,6 +23,10 @@ use crate::state::{
|
||||
};
|
||||
|
||||
const LEVELS_INTERVAL: Duration = Duration::from_millis(100);
|
||||
/// `set_api_key`/`has_api_key` refuse this service: its key is managed only
|
||||
/// by the backend login (`backend::login`), which holds `backend_key_lock`
|
||||
/// and binds the key to this build's backend.
|
||||
const BACKEND_KEY_MANAGED: &str = "Dieser Schlüssel wird über die Backend-Anmeldung verwaltet";
|
||||
|
||||
type CmdResult<T> = Result<T, String>;
|
||||
|
||||
@@ -32,6 +36,12 @@ struct CallEnded {
|
||||
id: CallId,
|
||||
}
|
||||
|
||||
/// This build's own version, for the settings' "Updates" section.
|
||||
#[tauri::command]
|
||||
pub fn get_app_version(app: AppHandle) -> String {
|
||||
app.package_info().version.to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_settings(state: State<'_, AppState>) -> Settings {
|
||||
state.settings()
|
||||
@@ -49,9 +59,11 @@ pub fn save_settings(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stores `key` in the keyring; an empty key deletes the entry.
|
||||
/// Stores `key` in the keyring; an empty key deletes the entry. Refuses
|
||||
/// `Service::Backend` (see [`BACKEND_KEY_MANAGED`]).
|
||||
#[tauri::command]
|
||||
pub async fn set_api_key(app: AppHandle, service: Service, key: String) -> CmdResult<()> {
|
||||
reject_backend_service(service)?;
|
||||
blocking(app, move |app| {
|
||||
let secrets = &app.state::<AppState>().secrets;
|
||||
let key = key.trim();
|
||||
@@ -65,9 +77,11 @@ pub async fn set_api_key(app: AppHandle, service: Service, key: String) -> CmdRe
|
||||
.await
|
||||
}
|
||||
|
||||
/// Whether a key is stored. Never returns the key itself.
|
||||
/// Whether a key is stored. Never returns the key itself. Refuses
|
||||
/// `Service::Backend` (see [`BACKEND_KEY_MANAGED`]).
|
||||
#[tauri::command]
|
||||
pub async fn has_api_key(app: AppHandle, service: Service) -> CmdResult<bool> {
|
||||
reject_backend_service(service)?;
|
||||
blocking(app, move |app| {
|
||||
let key = app.state::<AppState>().secrets.get(service);
|
||||
Ok(key.is_some_and(|key| !key.is_empty()))
|
||||
@@ -75,6 +89,15 @@ pub async fn has_api_key(app: AppHandle, service: Service) -> CmdResult<bool> {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Refuses direct keyring access to `Service::Backend`: its key is only
|
||||
/// ever set by the backend login flow.
|
||||
fn reject_backend_service(service: Service) -> CmdResult<()> {
|
||||
if service == Service::Backend {
|
||||
return Err(BACKEND_KEY_MANAGED.to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_devices() -> CmdResult<Devices> {
|
||||
tauri::async_runtime::spawn_blocking(recorder_audio::list_devices)
|
||||
@@ -412,3 +435,17 @@ where
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_backend_key_is_managed_only_by_the_login() {
|
||||
assert_eq!(
|
||||
reject_backend_service(Service::Backend),
|
||||
Err(BACKEND_KEY_MANAGED.to_string())
|
||||
);
|
||||
assert_eq!(reject_backend_service(Service::DeepScript), Ok(()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_log::{RotationStrategy, Target, TargetKind, TimezoneStrategy};
|
||||
|
||||
use crate::state::AppState;
|
||||
use crate::updater::PendingUpdate;
|
||||
use crate::updater::{PendingUpdate, UpdateSchedule};
|
||||
|
||||
/// Command-line flag the login item starts the app with; the main window
|
||||
/// then stays hidden in the tray.
|
||||
@@ -98,6 +98,7 @@ pub fn run() {
|
||||
processing::clear_upload_dir(app.handle());
|
||||
app.manage(state);
|
||||
app.manage(PendingUpdate::default());
|
||||
app.manage(UpdateSchedule::default());
|
||||
app.manage(backend::LoginWaiters::default());
|
||||
// Windows are created here (`create: false` in tauri.conf.json)
|
||||
// instead of by Tauri before `setup` runs: their webviews load
|
||||
@@ -130,6 +131,7 @@ pub fn run() {
|
||||
}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::get_app_version,
|
||||
commands::get_settings,
|
||||
commands::save_settings,
|
||||
commands::set_api_key,
|
||||
@@ -160,6 +162,8 @@ pub fn run() {
|
||||
backend::upload_transcript,
|
||||
updater::get_update,
|
||||
updater::install_update,
|
||||
updater::check_for_update_now,
|
||||
updater::can_self_update,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
|
||||
+32
-4
@@ -209,7 +209,12 @@ impl AppState {
|
||||
pending_prompts: Mutex::new(VecDeque::new()),
|
||||
processing: Mutex::new(HashSet::new()),
|
||||
devices_busy: AtomicBool::new(false),
|
||||
backend_url: crate::backend::BACKEND_URL.to_string(),
|
||||
// Defensive: BACKEND_URL itself must never have a trailing
|
||||
// slash (see backend::tests::backend_urls_have_no_trailing…),
|
||||
// but a stored key's base_url is compared against this field.
|
||||
backend_url: crate::backend::BACKEND_URL
|
||||
.trim_end_matches('/')
|
||||
.to_string(),
|
||||
backend_key_lock: Mutex::new(()),
|
||||
uploading: Mutex::new(HashSet::new()),
|
||||
}
|
||||
@@ -337,11 +342,20 @@ impl AppState {
|
||||
}
|
||||
|
||||
/// Reserves call `id` for one upload; released when the claim is
|
||||
/// dropped. A second upload of the same call is refused meanwhile.
|
||||
/// dropped. A second upload of the same call is refused meanwhile, and a
|
||||
/// call that already carries a CRM transcript id is refused outright:
|
||||
/// the CRM must never get a duplicate. Both 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> {
|
||||
if !lock(&self.uploading).insert(id) {
|
||||
let mut uploading = lock(&self.uploading);
|
||||
if uploading.contains(&id) {
|
||||
return Err("Wird bereits hochgeladen".to_string());
|
||||
}
|
||||
if self.find_call(id)?.crm_transcript_id.is_some() {
|
||||
return Err("Bereits hochgeladen".to_string());
|
||||
}
|
||||
uploading.insert(id);
|
||||
Ok(UploadClaim { state: self, id })
|
||||
}
|
||||
|
||||
@@ -1599,6 +1613,7 @@ mod tests {
|
||||
fn a_call_is_uploaded_once_at_a_time() {
|
||||
let f = fixture();
|
||||
let (id, _, _) = finished_call(&f, "a");
|
||||
let (other, _, _) = finished_call(&f, "b");
|
||||
assert!(!f.state.call_detail(id).unwrap().uploading);
|
||||
|
||||
let claim = f.state.claim_upload(id).unwrap();
|
||||
@@ -1608,13 +1623,26 @@ mod tests {
|
||||
f.state.claim_upload(id).err(),
|
||||
Some("Wird bereits hochgeladen".to_string())
|
||||
);
|
||||
assert!(f.state.claim_upload(id + 1).is_ok(), "other calls are free");
|
||||
assert!(f.state.claim_upload(other).is_ok(), "other calls are free");
|
||||
|
||||
drop(claim);
|
||||
assert!(!f.state.is_uploading(id));
|
||||
assert!(f.state.claim_upload(id).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_already_uploaded_is_not_claimed_again() {
|
||||
let f = fixture();
|
||||
let (id, _, _) = finished_call(&f, "a");
|
||||
f.state.mark_uploaded(id, "4711").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.claim_upload(id).err(),
|
||||
Some("Bereits hochgeladen".to_string())
|
||||
);
|
||||
assert!(!f.state.is_uploading(id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_upload_is_recorded_on_the_call() {
|
||||
let f = fixture();
|
||||
|
||||
+158
-23
@@ -2,10 +2,15 @@
|
||||
//! in `tauri.conf.json`) at startup and every 6 h (sooner after a failed
|
||||
//! check), tells the main window about a newer version and installs it when
|
||||
//! the user asks, but never while a recording runs or a call is being
|
||||
//! processed.
|
||||
//! processed. The settings' "Nach Updates suchen" button
|
||||
//! ([`check_for_update_now`]) runs the very same check immediately, counts
|
||||
//! as an attempt for the same scheduler ([`UpdateSchedule`]) and never runs
|
||||
//! at the same time as the background loop.
|
||||
//!
|
||||
//! On Windows the NSIS installer runs in passive mode for the current user
|
||||
//! (no admin rights) and restarts the app; installing ends this process.
|
||||
//! Debian builds never self-update; a manual check still asks the feed
|
||||
//! there (see [`can_self_update`]).
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
@@ -58,6 +63,71 @@ pub struct UpdateInfo {
|
||||
pub can_install: bool,
|
||||
}
|
||||
|
||||
/// Answer of `check_for_update_now`: what a check (background or manual)
|
||||
/// found. `Available` leaves the same state `get_update` reads and fires
|
||||
/// the same `update-available` event as the background loop, so the main
|
||||
/// window's banner shows it too.
|
||||
#[derive(Serialize, Clone, Debug, PartialEq)]
|
||||
#[serde(tag = "status", rename_all = "lowercase")]
|
||||
pub enum UpdateCheckResult {
|
||||
/// No newer version on the feed.
|
||||
None,
|
||||
Available {
|
||||
version: String,
|
||||
},
|
||||
/// The feed could not be asked; safe to show (never a secret).
|
||||
Error {
|
||||
message: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// When the last check attempt (background or manual) started and how many
|
||||
/// failed in a row, shared so a manual check feeds the same scheduler the
|
||||
/// background loop uses: success resets the 6 h interval and the failure
|
||||
/// count, a failure advances the backoff by one step. `running` also
|
||||
/// serializes checks, so a manual and a background check never run at once.
|
||||
#[derive(Default)]
|
||||
pub struct UpdateSchedule {
|
||||
state: Mutex<Schedule>,
|
||||
running: tokio::sync::Mutex<()>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
struct Schedule {
|
||||
last_attempt: Option<SystemTime>,
|
||||
failures: u32,
|
||||
}
|
||||
|
||||
impl UpdateSchedule {
|
||||
/// Whether a check is due at `now`, per the last recorded attempt.
|
||||
fn is_due(&self, now: SystemTime) -> bool {
|
||||
let s = lock(&self.state);
|
||||
check_due(s.last_attempt, s.failures, now)
|
||||
}
|
||||
|
||||
/// Records the outcome of a check attempt that started at `now`.
|
||||
fn record(&self, now: SystemTime, success: bool) {
|
||||
let mut s = lock(&self.state);
|
||||
s.last_attempt = Some(now);
|
||||
s.failures = if success {
|
||||
0
|
||||
} else {
|
||||
s.failures.saturating_add(1)
|
||||
};
|
||||
}
|
||||
|
||||
/// Runs one check attempt right now: 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 {
|
||||
let _serialize = self.running.lock().await;
|
||||
let now = SystemTime::now();
|
||||
let result = check(app).await;
|
||||
self.record(now, !matches!(result, UpdateCheckResult::Error { .. }));
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/// Payload of `update-progress`.
|
||||
#[derive(Serialize, Clone, Debug, PartialEq)]
|
||||
pub struct Progress {
|
||||
@@ -67,27 +137,19 @@ pub struct Progress {
|
||||
}
|
||||
|
||||
/// Starts the periodic update check. Only on Windows: Debian builds do not
|
||||
/// update themselves.
|
||||
/// update themselves (a manual check from the settings still asks the feed
|
||||
/// on Linux, see `check_for_update_now`).
|
||||
pub fn spawn(app: AppHandle) {
|
||||
if !cfg!(windows) {
|
||||
log::info!("update check disabled on this platform");
|
||||
return;
|
||||
}
|
||||
thread::spawn(move || {
|
||||
let mut last_attempt = None;
|
||||
let mut failures = 0;
|
||||
loop {
|
||||
let now = SystemTime::now();
|
||||
if check_due(last_attempt, failures, now) {
|
||||
last_attempt = Some(now);
|
||||
if tauri::async_runtime::block_on(check(&app)) {
|
||||
failures = 0;
|
||||
} else {
|
||||
failures = failures.saturating_add(1);
|
||||
}
|
||||
}
|
||||
thread::sleep(WAKE_INTERVAL);
|
||||
thread::spawn(move || loop {
|
||||
let now = SystemTime::now();
|
||||
if app.state::<UpdateSchedule>().is_due(now) {
|
||||
tauri::async_runtime::block_on(app.state::<UpdateSchedule>().run(&app));
|
||||
}
|
||||
thread::sleep(WAKE_INTERVAL);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,9 +172,11 @@ fn check_due(last_attempt: Option<SystemTime>, failures: u32, now: SystemTime) -
|
||||
.map_or(true, |elapsed| elapsed >= wait)
|
||||
}
|
||||
|
||||
/// Asks the release feed for a newer version; `false` if the check failed.
|
||||
/// Failures (offline, no release yet) are expected and only logged.
|
||||
async fn check(app: &AppHandle) -> bool {
|
||||
/// Asks the release feed for a newer version: the one implementation the
|
||||
/// background loop and a manual check (`check_for_update_now`) both run.
|
||||
/// 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).
|
||||
async fn check(app: &AppHandle) -> UpdateCheckResult {
|
||||
let result = match app.updater_builder().timeout(CHECK_TIMEOUT).build() {
|
||||
Ok(updater) => updater.check().await,
|
||||
Err(e) => Err(e),
|
||||
@@ -122,16 +186,18 @@ async fn check(app: &AppHandle) -> bool {
|
||||
log::info!("update available: {}", update.version);
|
||||
let version = update.version.clone();
|
||||
*lock(&app.state::<PendingUpdate>().update) = Some(update);
|
||||
let _ = app.emit("update-available", info(app, version));
|
||||
true
|
||||
let _ = app.emit("update-available", info(app, version.clone()));
|
||||
UpdateCheckResult::Available { version }
|
||||
}
|
||||
Ok(None) => {
|
||||
log::info!("no update available");
|
||||
true
|
||||
UpdateCheckResult::None
|
||||
}
|
||||
Err(e) => {
|
||||
log::info!("update check failed: {e}");
|
||||
false
|
||||
UpdateCheckResult::Error {
|
||||
message: format!("Update-Server nicht erreichbar: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,6 +227,24 @@ fn info(app: &AppHandle, version: String) -> UpdateInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// "Nach Updates suchen" in the settings: runs the same check as the
|
||||
/// background loop, immediately, reusing its scheduling (a success resets
|
||||
/// the 6 h interval and the failure count, same as a background success)
|
||||
/// and never running at the same time as a background check. Works on
|
||||
/// every platform; see `can_self_update` for whether this build can then
|
||||
/// install what it finds.
|
||||
#[tauri::command]
|
||||
pub async fn check_for_update_now(app: AppHandle) -> UpdateCheckResult {
|
||||
app.state::<UpdateSchedule>().run(&app).await
|
||||
}
|
||||
|
||||
/// Whether this build can install an update itself (Windows only: Debian
|
||||
/// builds ship a `.deb` and never self-update, see `spawn`).
|
||||
#[tauri::command]
|
||||
pub fn can_self_update() -> bool {
|
||||
cfg!(windows)
|
||||
}
|
||||
|
||||
/// The update found by the last check, if any.
|
||||
#[tauri::command]
|
||||
pub fn get_update(app: AppHandle) -> Option<UpdateInfo> {
|
||||
@@ -350,4 +434,55 @@ mod tests {
|
||||
let reports = reported(&mut meter, &[half, half, half, half, half], None);
|
||||
assert_eq!(reports, [MIB / 2, MIB, 2 * MIB]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_check_result_maps_to_a_tagged_status() {
|
||||
assert_eq!(
|
||||
serde_json::to_value(UpdateCheckResult::None).unwrap(),
|
||||
serde_json::json!({"status": "none"})
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(UpdateCheckResult::Available {
|
||||
version: "0.3.0".into()
|
||||
})
|
||||
.unwrap(),
|
||||
serde_json::json!({"status": "available", "version": "0.3.0"})
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(UpdateCheckResult::Error {
|
||||
message: "Update-Server nicht erreichbar: x".into()
|
||||
})
|
||||
.unwrap(),
|
||||
serde_json::json!({"status": "error", "message": "Update-Server nicht erreichbar: x"})
|
||||
);
|
||||
}
|
||||
|
||||
/// A manual check feeds the very scheduler the background loop reads
|
||||
/// (`record` is the one function either kind of attempt calls): a
|
||||
/// failure advances the backoff by exactly the one step a single
|
||||
/// failure always does (never more just for being a manual attempt),
|
||||
/// and a success resets the interval to 6 h and the failure count.
|
||||
#[test]
|
||||
fn a_manual_checks_result_feeds_the_background_scheduler() {
|
||||
let schedule = UpdateSchedule::default();
|
||||
assert!(schedule.is_due(t0()), "nothing attempted yet");
|
||||
|
||||
// One failed manual check: due again after the 1st retry delay,
|
||||
// exactly as check_due(_, 1, _) says, not sooner and not later.
|
||||
schedule.record(t0(), false);
|
||||
assert!(!schedule.is_due(t0() + MIN - Duration::from_secs(1)));
|
||||
assert!(schedule.is_due(t0() + MIN));
|
||||
|
||||
// A second failed attempt (background or manual, the scheduler does
|
||||
// not distinguish) advances to the 2nd retry delay, not further.
|
||||
schedule.record(t0() + MIN, false);
|
||||
assert!(!schedule.is_due(t0() + MIN + 5 * MIN - Duration::from_secs(1)));
|
||||
assert!(schedule.is_due(t0() + MIN + 5 * MIN));
|
||||
|
||||
// A manual check that then succeeds resets the interval to 6 h and
|
||||
// the failure count, exactly like a background success.
|
||||
schedule.record(t0() + MIN, true);
|
||||
assert!(!schedule.is_due(t0() + MIN + 6 * HOUR - MIN));
|
||||
assert!(schedule.is_due(t0() + MIN + 6 * HOUR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Gesprächsrekorder",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"identifier": "eu.euvino.callrecorder",
|
||||
"build": {
|
||||
"frontendDist": "../ui/dist",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ui",
|
||||
"private": true,
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
onRecordingState,
|
||||
onUpdateAvailable,
|
||||
onUpdateProgress,
|
||||
updateProgressText,
|
||||
UPDATE_BUSY_HINT,
|
||||
type UpdateInfo,
|
||||
type UpdateProgress,
|
||||
} from './api'
|
||||
@@ -62,16 +64,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function megabytes(bytes: number): string {
|
||||
return (bytes / 1024 / 1024).toLocaleString('de-DE', { maximumFractionDigits: 1 }) + ' MB'
|
||||
}
|
||||
|
||||
let progressText = $derived.by(() => {
|
||||
if (!progress) return 'Update wird heruntergeladen…'
|
||||
if (progress.total === null) return `Update wird heruntergeladen… ${megabytes(progress.downloaded)}`
|
||||
if (progress.downloaded >= progress.total) return 'Update wird installiert…'
|
||||
return `Update wird heruntergeladen… ${Math.floor((progress.downloaded * 100) / progress.total)} %`
|
||||
})
|
||||
let progressText = $derived(updateProgressText(progress))
|
||||
</script>
|
||||
|
||||
{#if update}
|
||||
@@ -84,7 +77,7 @@
|
||||
Installieren & neu starten
|
||||
</button>
|
||||
{#if !update.can_install}
|
||||
<span class="hint">Nach der laufenden Aufnahme/Verarbeitung möglich</span>
|
||||
<span class="hint">{UPDATE_BUSY_HINT}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if error}
|
||||
|
||||
@@ -137,6 +137,15 @@ export interface UpdateProgress {
|
||||
total: number | null
|
||||
}
|
||||
|
||||
/** Why the install button is disabled, shown next to it as a hint. */
|
||||
export const UPDATE_BUSY_HINT = 'Nach der laufenden Aufnahme/Verarbeitung möglich'
|
||||
|
||||
/** What a check (background or manual) found. */
|
||||
export type UpdateCheckResult =
|
||||
| { status: 'none' }
|
||||
| { status: 'available'; version: string }
|
||||
| { status: 'error'; message: string }
|
||||
|
||||
export interface Levels {
|
||||
mic: number
|
||||
out: number
|
||||
@@ -185,6 +194,14 @@ export const uploadTranscript = (id: CallId) => invoke<void>('upload_transcript'
|
||||
export const getUpdate = () => invoke<UpdateInfo | null>('get_update')
|
||||
/** Resolves only on failure: on success the app restarts. */
|
||||
export const installUpdate = () => invoke<void>('install_update')
|
||||
/** This build's own version, for the settings' "Updates" section. */
|
||||
export const getAppVersion = () => invoke<string>('get_app_version')
|
||||
/** Whether this build can install an update itself (Windows only). */
|
||||
export const canSelfUpdate = () => invoke<boolean>('can_self_update')
|
||||
/** "Nach Updates suchen": runs the same check as the background loop,
|
||||
* immediately. An `available` result leaves the same state `getUpdate`
|
||||
* reads, so the main window's banner shows it too. */
|
||||
export const checkForUpdateNow = () => invoke<UpdateCheckResult>('check_for_update_now')
|
||||
|
||||
export const onRecordingState = (handler: (state: RecordingState) => void): Promise<UnlistenFn> =>
|
||||
listen<RecordingState>('recording-state', (event) => handler(event.payload))
|
||||
@@ -218,6 +235,19 @@ export function meterFill(level: number): number {
|
||||
return Math.min(1, Math.max(0, (db + 60) / 60))
|
||||
}
|
||||
|
||||
function megabytes(bytes: number): string {
|
||||
return (bytes / 1024 / 1024).toLocaleString('de-DE', { maximumFractionDigits: 1 }) + ' MB'
|
||||
}
|
||||
|
||||
/** Text shown while an update installs (the banner and the settings'
|
||||
* Updates section share this). */
|
||||
export function updateProgressText(progress: UpdateProgress | null): string {
|
||||
if (!progress) return 'Update wird heruntergeladen…'
|
||||
if (progress.total === null) return `Update wird heruntergeladen… ${megabytes(progress.downloaded)}`
|
||||
if (progress.downloaded >= progress.total) return 'Update wird installiert…'
|
||||
return `Update wird heruntergeladen… ${Math.floor((progress.downloaded * 100) / progress.total)} %`
|
||||
}
|
||||
|
||||
/** Error text of a rejected command. */
|
||||
export function errorText(err: unknown): string {
|
||||
return typeof err === 'string' ? err : err instanceof Error ? err.message : String(err)
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
// take a while); their errors are kept per call too.
|
||||
let uploading = $state<CallId[]>([])
|
||||
let uploadErrors = $state<Record<CallId, string>>({})
|
||||
let confirmingUpload = $state(false)
|
||||
|
||||
let editingTitle = $state(false)
|
||||
let titleDraft = $state('')
|
||||
@@ -106,7 +105,6 @@
|
||||
actionError = ''
|
||||
editingTitle = false
|
||||
titleError = ''
|
||||
confirmingUpload = false
|
||||
refreshDetail()
|
||||
}
|
||||
|
||||
@@ -117,7 +115,6 @@
|
||||
actionError = ''
|
||||
editingTitle = false
|
||||
titleError = ''
|
||||
confirmingUpload = false
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
@@ -192,18 +189,12 @@
|
||||
refreshList()
|
||||
})
|
||||
|
||||
/** "Transkript hochladen"; an upload done before asks first. */
|
||||
function uploadClick() {
|
||||
if (!detail) return
|
||||
if (detail.call.uploaded_at) confirmingUpload = true
|
||||
else upload()
|
||||
}
|
||||
|
||||
/** Uploads the shown call's transcript (logging in first if needed). */
|
||||
/** 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
|
||||
* duplicate. */
|
||||
async function upload() {
|
||||
if (!detail) return
|
||||
const id = detail.call.id
|
||||
confirmingUpload = false
|
||||
if (uploading.includes(id)) return
|
||||
uploading = [...uploading, id]
|
||||
delete uploadErrors[id]
|
||||
@@ -360,22 +351,14 @@
|
||||
{:else if call.status === 'failed'}
|
||||
<button class="btn primary" disabled={busy} onclick={retry}>Erneut versuchen</button>
|
||||
<button class="btn danger" disabled={busy} onclick={discard}>Verwerfen</button>
|
||||
{:else if call.status === 'done' && confirmingUpload}
|
||||
<span class="confirm">Dieses Transkript wurde bereits hochgeladen. Nochmal hochladen?</span>
|
||||
<button class="btn primary" onclick={upload}>Hochladen</button>
|
||||
<button class="btn" onclick={() => (confirmingUpload = false)}>Abbrechen</button>
|
||||
{:else if call.status === 'done'}
|
||||
{:else if call.status === 'done' && !call.uploaded_at}
|
||||
<button
|
||||
class="btn primary"
|
||||
disabled={!call.transcribed_at || isUploading}
|
||||
title={call.transcribed_at ? 'Transkript ins CRM hochladen' : 'Noch kein Transkript'}
|
||||
onclick={uploadClick}
|
||||
onclick={upload}
|
||||
>
|
||||
{isUploading
|
||||
? 'wird hochgeladen…'
|
||||
: call.uploaded_at
|
||||
? 'Erneut hochladen'
|
||||
: 'Transkript hochladen'}
|
||||
{isUploading ? 'wird hochgeladen…' : 'Transkript hochladen'}
|
||||
</button>
|
||||
{/if}
|
||||
</span>
|
||||
@@ -568,8 +551,7 @@
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.uploaded,
|
||||
.confirm {
|
||||
.uploaded {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,17 +6,26 @@
|
||||
backendLogout,
|
||||
backendServer,
|
||||
backendStatus,
|
||||
canSelfUpdate,
|
||||
checkForUpdateNow,
|
||||
errorText,
|
||||
getAppVersion,
|
||||
getSettings,
|
||||
getUpdate,
|
||||
hasApiKey,
|
||||
installUpdate,
|
||||
listDevices,
|
||||
meterFill,
|
||||
onBackendChanged,
|
||||
onBackendLoginError,
|
||||
onUpdateAvailable,
|
||||
onUpdateProgress,
|
||||
openBackendKeysPage,
|
||||
saveSettings,
|
||||
setApiKey,
|
||||
testDevices,
|
||||
updateProgressText,
|
||||
UPDATE_BUSY_HINT,
|
||||
type BackendServer,
|
||||
type BackendStatus,
|
||||
type DeviceInfo,
|
||||
@@ -24,6 +33,9 @@
|
||||
type Devices,
|
||||
type Service,
|
||||
type Settings,
|
||||
type UpdateCheckResult,
|
||||
type UpdateInfo,
|
||||
type UpdateProgress,
|
||||
} from '../lib/api'
|
||||
|
||||
const services: { id: Service; name: string }[] = [
|
||||
@@ -48,19 +60,84 @@
|
||||
// Status answers can arrive out of order; only the newest is applied.
|
||||
let statusRequest = 0
|
||||
|
||||
let appVersion = $state('')
|
||||
/** `null` until known: whether this build can install an update itself
|
||||
* (Windows only); avoids guessing wrong for an instant. */
|
||||
let selfUpdateCapable = $state<boolean | null>(null)
|
||||
let checking = $state(false)
|
||||
let checkResult = $state<UpdateCheckResult | null>(null)
|
||||
let pendingUpdate = $state<UpdateInfo | null>(null)
|
||||
let installing = $state(false)
|
||||
let installProgress = $state<UpdateProgress | null>(null)
|
||||
let installError = $state('')
|
||||
|
||||
onMount(() => {
|
||||
load()
|
||||
backendServer()
|
||||
.then((s) => (server = s))
|
||||
.catch((err) => (backendError = errorText(err)))
|
||||
refreshBackend()
|
||||
getAppVersion()
|
||||
.then((v) => (appVersion = v))
|
||||
.catch(() => {})
|
||||
canSelfUpdate()
|
||||
.then((v) => (selfUpdateCapable = v))
|
||||
.catch(() => {})
|
||||
getUpdate()
|
||||
.then((u) => (pendingUpdate = u))
|
||||
.catch(() => {})
|
||||
const unlisten = [
|
||||
onBackendChanged(refreshBackend),
|
||||
onBackendLoginError((msg) => (backendError = msg)),
|
||||
onUpdateAvailable((info) => (pendingUpdate = info)),
|
||||
onUpdateProgress((progress) => (installProgress = progress)),
|
||||
]
|
||||
return () => unlisten.forEach((u) => u.then((off) => off()))
|
||||
})
|
||||
|
||||
/** "Nach Updates suchen": runs the same check as the background loop,
|
||||
* immediately. An available update also arrives via `update-available`
|
||||
* (so the main window's banner shows it too), but is applied here as
|
||||
* well in case that event is missed. */
|
||||
async function checkUpdateNow() {
|
||||
checking = true
|
||||
checkResult = null
|
||||
try {
|
||||
const result = await checkForUpdateNow()
|
||||
checkResult = result
|
||||
if (result.status === 'available') pendingUpdate = await getUpdate()
|
||||
} catch (err) {
|
||||
checkResult = { status: 'error', message: errorText(err) }
|
||||
} finally {
|
||||
checking = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshPendingUpdate() {
|
||||
try {
|
||||
pendingUpdate = await getUpdate()
|
||||
} catch {
|
||||
// Optional refresh; the next event or check tries again.
|
||||
}
|
||||
}
|
||||
|
||||
/** "Installieren & neu starten" for the update found above; reuses the
|
||||
* install command and guard the main window's banner uses. */
|
||||
async function installUpdateNow() {
|
||||
installing = true
|
||||
installProgress = null
|
||||
installError = ''
|
||||
try {
|
||||
// Returns only on failure: on success the app restarts.
|
||||
await installUpdate()
|
||||
} catch (err) {
|
||||
installError = errorText(err)
|
||||
refreshPendingUpdate()
|
||||
} finally {
|
||||
installing = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks the stored key with the backend. */
|
||||
async function refreshBackend() {
|
||||
const request = ++statusRequest
|
||||
@@ -377,6 +454,48 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Updates</h2>
|
||||
<div class="grid">
|
||||
<span>Version</span>
|
||||
<span>{appVersion || '…'}</span>
|
||||
</div>
|
||||
<div class="update-check">
|
||||
<button class="btn" disabled={checking} onclick={checkUpdateNow}>
|
||||
{checking ? 'Suche…' : 'Nach Updates suchen'}
|
||||
</button>
|
||||
{#if checkResult?.status === 'none'}
|
||||
<span class="muted">Keine neue Version verfügbar (aktuell: {appVersion})</span>
|
||||
{:else if checkResult?.status === 'error'}
|
||||
<span class="error">{checkResult.message}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if pendingUpdate && selfUpdateCapable !== null}
|
||||
<div class="update-available">
|
||||
<span>Update verfügbar (v{pendingUpdate.version})</span>
|
||||
{#if selfUpdateCapable}
|
||||
{#if installing}
|
||||
<span>{updateProgressText(installProgress)}</span>
|
||||
{:else}
|
||||
<button class="btn primary small" disabled={!pendingUpdate.can_install} onclick={installUpdateNow}>
|
||||
Installieren & neu starten
|
||||
</button>
|
||||
{#if !pendingUpdate.can_install}
|
||||
<span class="muted">{UPDATE_BUSY_HINT}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if installError}
|
||||
<span class="error">{installError}</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="muted">
|
||||
Updates gibt es unter Windows automatisch; unter Linux bitte das .deb neu installieren.
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<div class="footer">
|
||||
<button class="btn primary" onclick={() => run(persist, 'Einstellungen gespeichert ✓')}>
|
||||
Speichern
|
||||
@@ -503,6 +622,15 @@
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.update-check,
|
||||
.update-available {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user