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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! Alert sounds settings — per-event sound configuration.
use crate::SettingsUI;
use crate::section::{SLIDER_WIDTH, collapsing_section};
use par_term_config::AlertEvent;
use std::collections::HashSet;
const SLIDER_HEIGHT: f32 = 18.0;
pub(super) fn show_alert_sounds_section(
ui: &mut egui::Ui,
settings: &mut SettingsUI,
changes_this_frame: &mut bool,
collapsed: &mut HashSet<String>,
) {
collapsing_section(
ui,
"Alert Sounds",
"notifications_alert_sounds",
false,
collapsed,
|ui| {
ui.label("Configure sounds for terminal events. Leave unconfigured to use defaults.");
ui.add_space(4.0);
for event in AlertEvent::all() {
let id_str = format!("alert_{:?}", event);
let has_config = settings
.config
.notifications
.alert_sounds
.contains_key(event);
ui.group(|ui| {
ui.horizontal(|ui| {
let mut enabled = has_config
&& settings
.config
.notifications.alert_sounds
.get(event)
.is_some_and(|c| c.enabled);
if ui.checkbox(&mut enabled, event.display_name()).changed() {
if enabled {
settings
.config
.notifications.alert_sounds
.entry(*event)
.or_default()
.enabled = true;
} else if let Some(cfg) =
settings.config.notifications.alert_sounds.get_mut(event)
{
cfg.enabled = false;
}
settings.has_changes = true;
*changes_this_frame = true;
}
});
if has_config
&& settings
.config
.notifications.alert_sounds
.get(event)
.is_some_and(|c| c.enabled)
{
let cfg = settings.config.notifications.alert_sounds.get_mut(event).expect(
"alert_sounds entry verified present by get().is_some_and() guard above",
);
ui.horizontal(|ui| {
ui.label(" Volume:");
if ui
.add_sized(
[SLIDER_WIDTH, SLIDER_HEIGHT],
egui::Slider::new(&mut cfg.volume, 0..=100),
)
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
});
ui.horizontal(|ui| {
ui.label(" Frequency (Hz):");
if ui
.add_sized(
[SLIDER_WIDTH, SLIDER_HEIGHT],
egui::Slider::new(&mut cfg.frequency, 200.0..=2000.0)
.step_by(50.0),
)
.on_hover_text("Tone frequency for built-in sound")
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
});
ui.horizontal(|ui| {
ui.label(" Duration (ms):");
if ui
.add_sized(
[SLIDER_WIDTH, SLIDER_HEIGHT],
egui::Slider::new(&mut cfg.duration_ms, 10..=1000)
.step_by(10.0),
)
.on_hover_text("Duration of the alert tone")
.changed()
{
settings.has_changes = true;
*changes_this_frame = true;
}
});
// Sound file path (optional)
ui.horizontal(|ui| {
ui.label(" Sound file:");
let mut file_str = cfg.sound_file.clone().unwrap_or_default();
let response = ui.add_sized(
[SLIDER_WIDTH, SLIDER_HEIGHT],
egui::TextEdit::singleline(&mut file_str)
.hint_text("(optional WAV/MP3/OGG/FLAC path)"),
);
if response.changed() {
cfg.sound_file = if file_str.is_empty() {
None
} else {
Some(file_str)
};
settings.has_changes = true;
*changes_this_frame = true;
}
if ui.button("Browse…").clicked() {
let sounds_dir = dirs::config_dir()
.map(|d| d.join("par-term").join("sounds"))
.unwrap_or_default();
if let Some(path) = rfd::FileDialog::new()
.set_title("Select alert sound file")
.set_directory(&sounds_dir)
.add_filter(
"Audio",
&["wav", "mp3", "ogg", "flac", "aac", "m4a"],
)
.pick_file()
{
// If inside sounds dir, store relative; otherwise full path.
cfg.sound_file = Some(
path.strip_prefix(&sounds_dir)
.map(|p| p.display().to_string())
.unwrap_or_else(|_| path.display().to_string()),
);
settings.has_changes = true;
*changes_this_frame = true;
}
}
});
}
});
// suppress unused variable warning
let _ = &id_str;
}
},
);
}