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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions app/src-tauri/src/commands/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
pub async fn list_microphones(
core: tauri::State<'_, Core>,
) -> Result<Vec<MicrophoneInfo>, CommandError> {
off_main_core(core.inner().clone(), audio::list_microphones_with).await
off_main_core(core.inner().clone(), audio::list_microphones).await
}

/// Starts a dictation from the dashboard. Runs on the dictation worker, so it
Expand All @@ -32,7 +32,7 @@ pub async fn start_recording(
request,
allow_auto_stop: true,
};
match dictation_worker::request_with(core.inner().clone(), command).await? {
match dictation_worker::request(core.inner().clone(), command).await? {
Outcome::Started(info) => Ok(info),
_ => Err(CommandError::new(
"recording_unavailable",
Expand All @@ -47,13 +47,13 @@ pub async fn start_recording(
/// while nothing is recording does nothing.
#[tauri::command]
pub async fn stop_dictation(core: tauri::State<'_, Core>) -> Result<(), CommandError> {
dictation_worker::request_with(core.inner().clone(), DictationCommand::Stop).await?;
dictation_worker::request(core.inner().clone(), DictationCommand::Stop).await?;
Ok(())
}

#[tauri::command]
pub async fn cancel_recording(core: tauri::State<'_, Core>) -> Result<(), CommandError> {
dictation_worker::request_with(core.inner().clone(), DictationCommand::Cancel).await?;
dictation_worker::request(core.inner().clone(), DictationCommand::Cancel).await?;
Ok(())
}

Expand All @@ -63,14 +63,14 @@ pub async fn record_test_clip(
duration_ms: Option<u64>,
) -> Result<RecordingResult, CommandError> {
off_main_core(core.inner().clone(), move |core| {
audio::record_test_clip_with(core, duration_ms)
audio::record_test_clip(core, duration_ms)
})
.await
}

#[tauri::command]
pub async fn get_test_clip_audio(core: tauri::State<'_, Core>) -> Result<String, CommandError> {
off_main_core(core.inner().clone(), audio::get_test_clip_audio_with).await
off_main_core(core.inner().clone(), audio::get_test_clip_audio).await
}

/// Transcribes a user-picked audio/video file. Async so the (possibly
Expand All @@ -82,16 +82,14 @@ pub async fn transcribe_file(
path: String,
) -> Result<TranscribeFileResult, CommandError> {
let core = core.inner().clone();
tauri::async_runtime::spawn_blocking(move || {
file_transcribe::transcribe_file_with(&core, &path)
})
.await
.map_err(|error| {
CommandError::new(
"whisper_transcription_failed",
format!("File transcription task failed. {}", error),
)
})?
tauri::async_runtime::spawn_blocking(move || file_transcribe::transcribe_file(&core, &path))
.await
.map_err(|error| {
CommandError::new(
"whisper_transcription_failed",
format!("File transcription task failed. {}", error),
)
})?
}

/// Writes transcribed text to `<source>.txt` next to the source file and
Expand All @@ -114,7 +112,7 @@ pub async fn save_text_file(
pub async fn paste_last_transcript(
core: tauri::State<'_, Core>,
) -> Result<OutputResult, CommandError> {
match dictation_worker::request_with(core.inner().clone(), DictationCommand::PasteLast).await? {
match dictation_worker::request(core.inner().clone(), DictationCommand::PasteLast).await? {
Outcome::Output(result) => Ok(result),
_ => Err(CommandError::new(
"paste_failed",
Expand Down
43 changes: 19 additions & 24 deletions app/src-tauri/src/commands/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ use tauri::State;

use super::{off_main_core, on_dialog_thread};
use crate::{
data_hygiene::{
effective_data_dir_with, failed_recordings_dir_with, logs_dir_with, open_folder_with,
open_transcript_externally_with,
},
data_hygiene::{self, effective_data_dir, failed_recordings_dir, logs_dir, open_folder},
db::transcript_audio_missing,
error::CommandError,
import::{load_transcript_import, ImportReport, TranscriptImportPreview},
replacements_file::{notify_backup_with, open_replacements_file_with, replacements_error},
replacements_file::{self, notify_backup, replacements_error},
settings::AppSettings,
settings_store::patch_settings_now_with,
settings_store::patch_settings_now,
stats::BasicStats,
transcript::{Transcript, TranscriptSearchResult, TranscriptSort},
Core,
Expand All @@ -41,7 +38,7 @@ pub async fn patch_settings(
patch: serde_json::Map<String, serde_json::Value>,
) -> Result<AppSettings, CommandError> {
off_main_core(core.inner().clone(), move |core| {
patch_settings_now_with(core, &patch)
patch_settings_now(core, &patch)
})
.await
}
Expand Down Expand Up @@ -215,7 +212,7 @@ pub async fn open_transcript_externally(
id: String,
) -> Result<(), CommandError> {
off_main_core(core.inner().clone(), move |core| {
open_transcript_externally_with(core, &id)
data_hygiene::open_transcript_externally(core, &id)
})
.await
}
Expand Down Expand Up @@ -268,7 +265,7 @@ pub async fn refresh_basic_stats(core: State<'_, Core>) -> Result<BasicStats, Co
#[tauri::command]
pub async fn open_data_folder(core: State<'_, Core>) -> Result<(), CommandError> {
off_main_core(core.inner().clone(), move |core| {
open_folder_with(core.host().as_ref(), effective_data_dir_with(core))
open_folder(core.host().as_ref(), effective_data_dir(core))
})
.await
}
Expand All @@ -278,7 +275,7 @@ pub async fn open_data_folder(core: State<'_, Core>) -> Result<(), CommandError>
#[tauri::command]
pub async fn get_data_dir(core: State<'_, Core>) -> Result<String, CommandError> {
off_main_core(core.inner().clone(), move |core| {
Ok(effective_data_dir_with(core).to_string_lossy().into_owned())
Ok(effective_data_dir(core).to_string_lossy().into_owned())
})
.await
}
Expand All @@ -292,7 +289,7 @@ pub async fn pick_data_dir(core: State<'_, Core>) -> Result<Option<String>, Comm
on_dialog_thread(core.inner().clone(), move |core| {
#[cfg(windows)]
{
let start = effective_data_dir_with(core);
let start = effective_data_dir(core);
let picked = rfd::FileDialog::new()
.set_title("Choose Scribe data folder")
.set_directory(&start)
Expand All @@ -318,7 +315,7 @@ pub async fn pick_data_dir(core: State<'_, Core>) -> Result<Option<String>, Comm
pub async fn open_logs_folder(core: State<'_, Core>) -> Result<(), CommandError> {
off_main_core(core.inner().clone(), move |core| {
let host = core.host().as_ref();
open_folder_with(host, logs_dir_with(host))
open_folder(host, logs_dir(host))
})
.await
}
Expand All @@ -327,7 +324,7 @@ pub async fn open_logs_folder(core: State<'_, Core>) -> Result<(), CommandError>
/// mirroring get_data_dir.
#[tauri::command]
pub fn get_logs_dir(core: State<'_, Core>) -> Result<String, CommandError> {
Ok(logs_dir_with(core.host().as_ref())
Ok(logs_dir(core.host().as_ref())
.to_string_lossy()
.into_owned())
}
Expand All @@ -337,7 +334,7 @@ pub fn get_logs_dir(core: State<'_, Core>) -> Result<String, CommandError> {
#[tauri::command]
pub async fn open_failed_recordings_folder(core: State<'_, Core>) -> Result<(), CommandError> {
off_main_core(core.inner().clone(), move |core| {
open_folder_with(core.host().as_ref(), failed_recordings_dir_with(core))
open_folder(core.host().as_ref(), failed_recordings_dir(core))
})
.await
}
Expand All @@ -346,9 +343,7 @@ pub async fn open_failed_recordings_folder(core: State<'_, Core>) -> Result<(),
/// Privacy view, mirroring get_logs_dir.
#[tauri::command]
pub fn get_failed_recordings_dir(core: State<'_, Core>) -> Result<String, CommandError> {
Ok(failed_recordings_dir_with(&core)
.to_string_lossy()
.into_owned())
Ok(failed_recordings_dir(&core).to_string_lossy().into_owned())
}

/// Exports transcripts to a local file the user picks via a native save dialog.
Expand Down Expand Up @@ -428,7 +423,7 @@ pub async fn export_transcripts(

#[cfg(windows)]
{
let start = effective_data_dir_with(core);
let start = effective_data_dir(core);
let picked = rfd::FileDialog::new()
.set_title("Export transcripts")
.set_directory(&start)
Expand Down Expand Up @@ -467,7 +462,7 @@ pub async fn preview_transcript_import(
on_dialog_thread(core.inner().clone(), move |core| {
#[cfg(windows)]
{
let start = effective_data_dir_with(core);
let start = effective_data_dir(core);
let picked = rfd::FileDialog::new()
.set_title("Restore Scribe backup")
.set_directory(&start)
Expand Down Expand Up @@ -549,7 +544,7 @@ pub async fn add_replacements(
) -> Result<crate::replacements_file::AddReport, CommandError> {
off_main_core(core.inner().clone(), move |core| {
let report = core.replacements().add(&rows).map_err(replacements_error)?;
notify_backup_with(core);
notify_backup(core);
Ok(report)
})
.await
Expand All @@ -566,7 +561,7 @@ pub async fn remove_replacement(
.replacements()
.remove(&row)
.map_err(replacements_error)?;
notify_backup_with(core);
notify_backup(core);
Ok(info)
})
.await
Expand All @@ -576,7 +571,7 @@ pub async fn remove_replacement(
#[tauri::command]
pub async fn open_replacements_file(core: State<'_, Core>) -> Result<(), CommandError> {
off_main_core(core.inner().clone(), move |core| {
open_replacements_file_with(core)
replacements_file::open_replacements_file(core)
})
.await
}
Expand All @@ -585,7 +580,7 @@ pub async fn open_replacements_file(core: State<'_, Core>) -> Result<(), Command
/// The version is the host's (the app's own, which Dev builds override).
#[tauri::command]
pub fn whats_new_pending(core: State<'_, Core>) -> Result<Option<String>, CommandError> {
crate::release_notes::pending_version_with(&core)
crate::release_notes::pending_version(&core)
}

/// Remembers that the card for `version` was dismissed.
Expand All @@ -602,5 +597,5 @@ pub fn dismiss_whats_new(core: State<'_, Core>, version: String) -> Result<(), C
/// which Dev builds override).
#[tauri::command]
pub fn collect_diagnostics(core: State<'_, Core>) -> Result<String, CommandError> {
crate::diagnostics::collect_with(&core)
crate::diagnostics::collect(&core)
}
46 changes: 23 additions & 23 deletions app/src-tauri/src/commands/hotkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn bind_portal_shortcuts(
crate::platform::shortcuts::bind_again()
.map_err(|message| CommandError::new("portal_shortcuts_failed", message))?;
let settings = core.backend().db()?.get_settings()?;
hotkeys::status_with(core, &settings.hotkeys)
hotkeys::status(core, &settings.hotkeys)
}
#[cfg(not(target_os = "linux"))]
{
Expand Down Expand Up @@ -64,7 +64,7 @@ pub async fn configure_portal_shortcuts(core: tauri::State<'_, Core>) -> Result<
pub async fn get_hotkey_status(core: tauri::State<'_, Core>) -> Result<HotkeyStatus, CommandError> {
off_main_core(core.inner().clone(), |core| {
let settings = core.backend().db()?.get_settings()?;
hotkeys::status_with(core, &settings.hotkeys)
hotkeys::status(core, &settings.hotkeys)
})
.await
}
Expand Down Expand Up @@ -94,26 +94,26 @@ pub async fn rebind_hotkey(
action.set_shortcut(&mut next_hotkeys, shortcut);
hotkeys::validate_hotkeys(&next_hotkeys)?;
let failures =
hotkeys::replace_hotkeys_with(core, &previous_hotkeys, &next_hotkeys)?;
hotkeys::replace_hotkeys(core, &previous_hotkeys, &next_hotkeys)?;

// When the binding being changed is the one that failed, restore the
// previous set (other bindings stay registered either way) and surface
// the error inline to the rebind UI.
if let Some(failure) = failures.iter().find(|failure| failure.action == action) {
let message = failure.message.clone();
let _ = hotkeys::replace_hotkeys_with(core, &next_hotkeys, &previous_hotkeys);
let _ = hotkeys::replace_hotkeys(core, &next_hotkeys, &previous_hotkeys);
return Err(CommandError::new("hotkey_registration_failed", message));
}

settings.hotkeys = next_hotkeys.clone();
if let Err(error) = state.db()?.save_settings(&settings) {
let _ = hotkeys::replace_hotkeys_with(core, &next_hotkeys, &previous_hotkeys);
let _ = hotkeys::replace_hotkeys(core, &next_hotkeys, &previous_hotkeys);
return Err(error);
}

settings_store::emit_changed_with(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures_with(core.host().as_ref(), &failures);
hotkeys::status_with(core, &settings.hotkeys)
settings_store::emit_changed(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures(core.host().as_ref(), &failures);
hotkeys::status(core, &settings.hotkeys)
})
.await
}
Expand Down Expand Up @@ -143,17 +143,17 @@ pub async fn set_hotkey_trigger(
}

hotkeys::validate_hotkeys(&next_hotkeys)?;
let failures = hotkeys::replace_hotkeys_with(core, &previous_hotkeys, &next_hotkeys)?;
let failures = hotkeys::replace_hotkeys(core, &previous_hotkeys, &next_hotkeys)?;

settings.hotkeys = next_hotkeys.clone();
if let Err(error) = state.db()?.save_settings(&settings) {
let _ = hotkeys::replace_hotkeys_with(core, &next_hotkeys, &previous_hotkeys);
let _ = hotkeys::replace_hotkeys(core, &next_hotkeys, &previous_hotkeys);
return Err(error);
}

settings_store::emit_changed_with(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures_with(core.host().as_ref(), &failures);
hotkeys::status_with(core, &settings.hotkeys)
settings_store::emit_changed(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures(core.host().as_ref(), &failures);
hotkeys::status(core, &settings.hotkeys)
})
.await
}
Expand All @@ -176,18 +176,18 @@ pub async fn reset_hotkeys_to_defaults(
};

hotkeys::validate_hotkeys(&next_hotkeys)?;
let failures = hotkeys::replace_hotkeys_with(core, &previous_hotkeys, &next_hotkeys)?;
let failures = hotkeys::replace_hotkeys(core, &previous_hotkeys, &next_hotkeys)?;

settings.hotkeys = next_hotkeys.clone();
settings.dev_hotkeys_seeded = true;
if let Err(error) = state.db()?.save_settings(&settings) {
let _ = hotkeys::replace_hotkeys_with(core, &next_hotkeys, &previous_hotkeys);
let _ = hotkeys::replace_hotkeys(core, &next_hotkeys, &previous_hotkeys);
return Err(error);
}

settings_store::emit_changed_with(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures_with(core.host().as_ref(), &failures);
hotkeys::status_with(core, &settings.hotkeys)
settings_store::emit_changed(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures(core.host().as_ref(), &failures);
hotkeys::status(core, &settings.hotkeys)
})
.await
}
Expand All @@ -208,18 +208,18 @@ pub async fn load_production_hotkey_defaults(
let next_hotkeys = AppSettings::default().hotkeys;

hotkeys::validate_hotkeys(&next_hotkeys)?;
let failures = hotkeys::replace_hotkeys_with(core, &previous_hotkeys, &next_hotkeys)?;
let failures = hotkeys::replace_hotkeys(core, &previous_hotkeys, &next_hotkeys)?;

settings.hotkeys = next_hotkeys.clone();
settings.dev_hotkeys_seeded = true;
if let Err(error) = state.db()?.save_settings(&settings) {
let _ = hotkeys::replace_hotkeys_with(core, &next_hotkeys, &previous_hotkeys);
let _ = hotkeys::replace_hotkeys(core, &next_hotkeys, &previous_hotkeys);
return Err(error);
}

settings_store::emit_changed_with(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures_with(core.host().as_ref(), &failures);
hotkeys::status_with(core, &settings.hotkeys)
settings_store::emit_changed(core.host().as_ref(), &settings);
hotkeys::emit_registration_failures(core.host().as_ref(), &failures);
hotkeys::status(core, &settings.hotkeys)
})
.await
}
Loading
Loading