Skip to content

Commit 5915f3b

Browse files
committed
fix: do not spam temp notification
Signed-off-by: Martichou <[email protected]>
1 parent f6ae4b9 commit 5915f3b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/legacy/src-tauri/src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ fn spawn_receiver_tasks(app_handle: &AppHandle) {
210210
tauri::async_runtime::spawn(async move {
211211
let state: tauri::State<'_, AppState> = capp_handle.state();
212212
let mut ble_receiver = state.ble_receiver.resubscribe();
213+
let mut last_sent = std::time::Instant::now() - std::time::Duration::from_secs(120);
213214

214215
loop {
215216
let rinfo = ble_receiver.recv().await;
@@ -219,9 +220,12 @@ fn spawn_receiver_tasks(app_handle: &AppHandle) {
219220
let v = get_visibility(&capp_handle);
220221
trace!("Tauri: ble received: {:?}", v);
221222

222-
if v == Visibility::Invisible {
223+
if v == Visibility::Invisible
224+
&& last_sent.elapsed() >= std::time::Duration::from_secs(120)
225+
{
223226
#[cfg(not(target_os = "macos"))]
224227
send_temporarily_notification(&capp_handle);
228+
last_sent = std::time::Instant::now();
225229
}
226230
}
227231
Err(e) => {

app/main/src-tauri/src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ fn spawn_receiver_tasks(app_handle: &AppHandle) {
243243
tauri::async_runtime::spawn(async move {
244244
let state: tauri::State<'_, AppState> = capp_handle.state();
245245
let mut ble_receiver = state.ble_receiver.resubscribe();
246+
let mut last_sent = std::time::Instant::now() - std::time::Duration::from_secs(120);
246247

247248
loop {
248249
let rinfo = ble_receiver.recv().await;
@@ -252,8 +253,11 @@ fn spawn_receiver_tasks(app_handle: &AppHandle) {
252253
let v = get_visibility(&capp_handle);
253254
trace!("Tauri: ble received: {:?}", v);
254255

255-
if v == Visibility::Invisible {
256+
if v == Visibility::Invisible
257+
&& last_sent.elapsed() >= std::time::Duration::from_secs(120)
258+
{
256259
send_temporarily_notification(&capp_handle);
260+
last_sent = std::time::Instant::now();
257261
}
258262
}
259263
Err(e) => {

0 commit comments

Comments
 (0)