feat: add volume save/restore on failure/unload
On the first failed unlock attempt, save the current system volume and mute state then set volume to maximum unmuted; restore on g_module_unload. A lock file under XDG_RUNTIME_DIR prevents double-acquisition when multiple gtklock windows are active. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,13 @@ impl WindowHandler {
|
||||
}
|
||||
println!("[ahfail] Error label changed to: '{}'", text_str);
|
||||
|
||||
MODULE_STATE.with(|s| {
|
||||
let mut st = s.borrow_mut();
|
||||
if st.volume_state.is_none() {
|
||||
st.volume_state = ahfail_ui::volume::save_and_set_max();
|
||||
}
|
||||
});
|
||||
|
||||
MODULE_STATE.with(|state| {
|
||||
let state = state.borrow();
|
||||
if let (Some(animation), Some(audio_uri)) = (&state.animation, &state.audio_uri) {
|
||||
|
||||
@@ -136,8 +136,12 @@ pub unsafe extern "C" fn on_idle_show(_gtklock: *mut GtkLock) {}
|
||||
pub unsafe extern "C" fn g_module_unload(_module: *mut c_void) {
|
||||
MODULE_STATE.with(|state| {
|
||||
let mut state = state.borrow_mut();
|
||||
if let Some(vs) = state.volume_state.take() {
|
||||
ahfail_ui::volume::restore(vs);
|
||||
}
|
||||
state.animation = None;
|
||||
state.audio_uri = None;
|
||||
state.config.deadzone = None;
|
||||
state.volume_state = None;
|
||||
});
|
||||
}
|
||||
@@ -7,6 +7,7 @@ pub struct ModuleState {
|
||||
pub animation: Option<gdk_pixbuf::PixbufAnimation>,
|
||||
pub audio_uri: Option<String>,
|
||||
pub config: ModuleConfig,
|
||||
pub volume_state: Option<ahfail_ui::volume::VolumeState>,
|
||||
}
|
||||
|
||||
pub struct WindowData {
|
||||
@@ -22,5 +23,6 @@ thread_local! {
|
||||
animation: None,
|
||||
audio_uri: None,
|
||||
config: ModuleConfig { deadzone: None },
|
||||
volume_state: None,
|
||||
}) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user