forked from cjpais/Handy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.rs
More file actions
76 lines (64 loc) · 2.65 KB
/
utils.rs
File metadata and controls
76 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::managers::audio::AudioRecordingManager;
use crate::managers::transcription::TranscriptionManager;
use crate::shortcut;
use crate::TranscriptionCoordinator;
use log::{info, warn};
use std::sync::Arc;
use tauri::{AppHandle, Manager};
// Re-export all utility modules for easy access
// pub use crate::audio_feedback::*;
pub use crate::clipboard::*;
pub use crate::overlay::*;
pub use crate::tray::*;
/// Send a transcription input to the coordinator.
/// Used by signal handlers, CLI flags, tray menu, and any other external trigger.
pub fn send_transcription_input(app: &AppHandle, binding_id: &str, source: &str) {
if let Some(c) = app.try_state::<TranscriptionCoordinator>() {
c.send_input(binding_id, source, true, false);
} else {
warn!("TranscriptionCoordinator not initialized");
}
}
/// Centralized cancellation function that can be called from anywhere in the app.
/// Handles cancelling both recording and transcription operations and updates UI state.
pub fn cancel_current_operation(app: &AppHandle) {
info!("Initiating operation cancellation...");
// Unregister the cancel shortcut asynchronously
shortcut::unregister_cancel_shortcut(app);
// Cancel any ongoing recording
let audio_manager = app.state::<Arc<AudioRecordingManager>>();
let recording_was_active = audio_manager.is_recording();
audio_manager.cancel_recording();
// Update tray icon and hide overlay
change_tray_icon(app, crate::tray::TrayIconState::Idle);
hide_recording_overlay(app);
// Unload model if immediate unload is enabled
let tm = app.state::<Arc<TranscriptionManager>>();
tm.maybe_unload_immediately("cancellation");
// Notify coordinator so it can keep lifecycle state coherent.
if let Some(coordinator) = app.try_state::<TranscriptionCoordinator>() {
coordinator.notify_cancel(recording_was_active);
}
info!("Operation cancellation completed - returned to idle state");
}
/// Check if using the Wayland display server protocol
#[cfg(target_os = "linux")]
pub fn is_wayland() -> bool {
std::env::var("WAYLAND_DISPLAY").is_ok()
|| std::env::var("XDG_SESSION_TYPE")
.map(|v| v.to_lowercase() == "wayland")
.unwrap_or(false)
}
/// Check if running on KDE Plasma desktop environment
#[cfg(target_os = "linux")]
pub fn is_kde_plasma() -> bool {
std::env::var("XDG_CURRENT_DESKTOP")
.map(|v| v.to_uppercase().contains("KDE"))
.unwrap_or(false)
|| std::env::var("KDE_SESSION_VERSION").is_ok()
}
/// Check if running on KDE Plasma with Wayland
#[cfg(target_os = "linux")]
pub fn is_kde_wayland() -> bool {
is_wayland() && is_kde_plasma()
}