Skip to content

Commit ffc8c59

Browse files
committed
fix: update ListenContext and timer event handling for consistency.
1 parent 422b479 commit ffc8c59

4 files changed

Lines changed: 35 additions & 36 deletions

File tree

src-tauri/src/themes/watcher.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ fn debounce_loop(
7373
app_data_dir: &Path,
7474
app: &AppHandle,
7575
) {
76-
loop {
77-
// Block until at least one event arrives.
78-
let first = match rx.recv() {
79-
Ok(evt) => evt,
80-
Err(_) => break, // channel closed — watcher was dropped
81-
};
82-
76+
while let Ok(first) = rx.recv() {
8377
// Log and ignore watcher errors.
8478
if let Err(e) = first {
8579
eprintln!("[themes/watcher] watch error: {e}");

src-tauri/src/timer/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ impl TimerController {
9696
listen_events(
9797
app,
9898
event_rx,
99-
seq_thread,
100-
settings_thread,
101-
shared_thread,
102-
engine_thread,
103-
tray_thread,
104-
db,
99+
ListenContext {
100+
sequence: seq_thread,
101+
settings: settings_thread,
102+
shared: shared_thread,
103+
engine: engine_thread,
104+
tray: tray_thread,
105+
db,
106+
},
105107
);
106108
})
107109
.expect("failed to spawn timer event listener");
@@ -213,16 +215,21 @@ impl TimerController {
213215
// Background event listener thread
214216
// ---------------------------------------------------------------------------
215217

216-
fn listen_events(
217-
app: AppHandle,
218-
event_rx: std::sync::mpsc::Receiver<TimerEvent>,
218+
struct ListenContext {
219219
sequence: Arc<Mutex<SequenceState>>,
220220
settings: Arc<Mutex<Settings>>,
221221
shared: Arc<Mutex<TimerShared>>,
222222
engine: EngineHandle,
223223
tray: Arc<TrayState>,
224224
db: DbState,
225+
}
226+
227+
fn listen_events(
228+
app: AppHandle,
229+
event_rx: std::sync::mpsc::Receiver<TimerEvent>,
230+
ctx: ListenContext,
225231
) {
232+
let ListenContext { sequence, settings, shared, engine, tray, db } = ctx;
226233
// Track last tray progress to throttle redraws to ≥ 1% delta.
227234
let mut last_tray_progress: f32 = -1.0;
228235
// Active session row ID for recording (None = not started yet).

src-tauri/src/tray/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,13 @@ pub fn render_tray_icon_rgba(
214214
) -> Vec<u8> {
215215
let mut pixmap = Pixmap::new(SIZE, SIZE).expect("pixmap alloc");
216216

217-
let mut paint = Paint::default();
218-
paint.anti_alias = true;
217+
let mut paint = Paint { anti_alias: true, ..Default::default() };
219218

220-
let mut stroke = Stroke::default();
221-
stroke.width = STROKE_WIDTH;
222-
stroke.line_cap = tiny_skia::LineCap::Round;
219+
let stroke = Stroke {
220+
width: STROKE_WIDTH,
221+
line_cap: tiny_skia::LineCap::Round,
222+
..Default::default()
223+
};
223224

224225
// Track ring: full circle at low opacity — defines the circular shape.
225226
{

src-tauri/src/websocket/mod.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async fn handle_socket(socket: WebSocket, state: ServerState) {
141141
Ok(s) => s,
142142
Err(_) => continue,
143143
};
144-
if sender.send(Message::Text(json.into())).await.is_err() {
144+
if sender.send(Message::Text(json)).await.is_err() {
145145
break;
146146
}
147147
}
@@ -178,21 +178,18 @@ async fn handle_client_message(
178178
return;
179179
};
180180

181-
match msg.get("type").and_then(|t| t.as_str()) {
182-
Some("getState") => {
183-
if let Some(timer) = app.try_state::<TimerController>() {
184-
let snapshot = timer.get_snapshot();
185-
let response = serde_json::json!({
186-
"type": "state",
187-
"payload": snapshot,
188-
});
189-
// Note: we can't send directly here without the sender;
190-
// the client will receive state via the next broadcast.
191-
// For an immediate reply, broadcast it.
192-
let _ = app.emit("timer:state-query", response);
193-
}
181+
if let Some("getState") = msg.get("type").and_then(|t| t.as_str()) {
182+
if let Some(timer) = app.try_state::<TimerController>() {
183+
let snapshot = timer.get_snapshot();
184+
let response = serde_json::json!({
185+
"type": "state",
186+
"payload": snapshot,
187+
});
188+
// Note: we can't send directly here without the sender;
189+
// the client will receive state via the next broadcast.
190+
// For an immediate reply, broadcast it.
191+
let _ = app.emit("timer:state-query", response);
194192
}
195-
_ => {}
196193
}
197194
}
198195

0 commit comments

Comments
 (0)