Skip to content

Commit 4890af6

Browse files
authored
(hotfix) Respect notification detect setting from rust side (#4279)
1 parent 33e38dd commit 4890af6

File tree

9 files changed

+1134
-399
lines changed

9 files changed

+1134
-399
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src/stt/contexts.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { createContext, useContext, useEffect, useRef } from "react";
22
import { useStore } from "zustand";
33
import { useShallow } from "zustand/shallow";
4-
import { useConfigValue } from "~/shared/config";
54
import * as main from "~/store/tinybase/store/main";
65
import {
76
createListenerStore,
@@ -79,30 +78,20 @@ function getNearbyEvents(
7978
const useHandleDetectEvents = (store: ListenerStore) => {
8079
const stop = useStore(store, (state) => state.stop);
8180
const setMuted = useStore(store, (state) => state.setMuted);
82-
const notificationDetectEnabled = useConfigValue("notification_detect");
8381
const tinybaseStore = main.UI.useStore(main.STORE_ID);
8482

8583
const tinybaseStoreRef = useRef(tinybaseStore);
8684
useEffect(() => {
8785
tinybaseStoreRef.current = tinybaseStore;
8886
}, [tinybaseStore]);
8987

90-
const notificationDetectEnabledRef = useRef(notificationDetectEnabled);
91-
useEffect(() => {
92-
notificationDetectEnabledRef.current = notificationDetectEnabled;
93-
}, [notificationDetectEnabled]);
94-
9588
useEffect(() => {
9689
let unlisten: (() => void) | undefined;
9790
let cancelled = false;
9891

9992
detectEvents.detectEvent
10093
.listen(({ payload }) => {
10194
if (payload.type === "micDetected") {
102-
if (!notificationDetectEnabledRef.current) {
103-
return;
104-
}
105-
10695
if (store.getState().live.status === "active") {
10796
return;
10897
}

plugins/detect/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ default = ["zoom", "sleep"]
1212
zoom = ["hypr-detect/zoom"]
1313
language = ["hypr-detect/language"]
1414
sleep = ["hypr-detect/sleep"]
15+
test-support = []
1516

1617
[build-dependencies]
1718
tauri-plugin = { workspace = true, features = ["build"] }
1819

1920
[dev-dependencies]
21+
hypr-detect = { workspace = true, features = ["mic"] }
2022
specta-typescript = { workspace = true }
23+
tauri-plugin-detect = { path = ".", features = ["test-support"] }
2124
tokio = { workspace = true, features = ["test-util"] }
2225

2326
[dependencies]
@@ -26,12 +29,14 @@ hypr-host = { workspace = true }
2629
hypr-notification-interface = { workspace = true }
2730

2831
tauri = { workspace = true, features = ["specta", "test"] }
32+
tauri-plugin-settings = { workspace = true }
2933
tauri-plugin-windows = { workspace = true }
3034

3135
specta = { workspace = true }
3236
tauri-specta = { workspace = true, features = ["derive", "typescript"] }
3337

3438
serde = { workspace = true }
39+
serde_json = { workspace = true }
3540
thiserror = { workspace = true }
3641
uuid = { workspace = true, features = ["v4"] }
3742

plugins/detect/src/env.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use tauri_specta::Event;
44

55
use crate::DetectEvent;
66

7-
pub(crate) trait Env: Clone + Send + Sync + 'static {
7+
pub trait Env: Clone + Send + Sync + 'static {
88
fn emit(&self, event: DetectEvent);
99
fn is_do_not_disturb(&self) -> bool;
10+
fn is_detect_enabled(&self) -> bool;
1011
}
1112

1213
pub(crate) struct TauriEnv<R: Runtime> {
@@ -34,31 +35,54 @@ impl<R: Runtime> Env for TauriEnv<R> {
3435
fn is_do_not_disturb(&self) -> bool {
3536
crate::dnd::is_do_not_disturb()
3637
}
38+
39+
fn is_detect_enabled(&self) -> bool {
40+
read_detect_enabled_settings(&self.app_handle).unwrap_or(true)
41+
}
42+
}
43+
44+
fn read_detect_enabled_settings<R: Runtime>(app_handle: &AppHandle<R>) -> Option<bool> {
45+
use tauri_plugin_settings::SettingsPluginExt;
46+
47+
let path = app_handle.settings().settings_path().ok()?;
48+
let content = std::fs::read_to_string(path.as_str()).ok()?;
49+
let settings: serde_json::Value = serde_json::from_str(&content).ok()?;
50+
51+
settings
52+
.get("notification")
53+
.and_then(|n| n.get("detect"))
54+
.and_then(|d| d.as_bool())
3755
}
3856

39-
#[cfg(test)]
40-
pub(crate) mod test_support {
57+
#[cfg(any(test, feature = "test-support"))]
58+
pub mod test_support {
4159
use super::*;
4260
use std::sync::Arc;
4361
use std::sync::atomic::{AtomicBool, Ordering};
4462

4563
#[derive(Clone)]
46-
pub(crate) struct TestEnv {
47-
pub(crate) events: Arc<std::sync::Mutex<Vec<DetectEvent>>>,
64+
pub struct TestEnv {
65+
pub events: Arc<std::sync::Mutex<Vec<DetectEvent>>>,
4866
dnd: Arc<AtomicBool>,
67+
detect_enabled: Arc<AtomicBool>,
4968
}
5069

5170
impl TestEnv {
52-
pub(crate) fn new() -> Self {
71+
pub fn new() -> Self {
5372
Self {
5473
events: Arc::new(std::sync::Mutex::new(Vec::new())),
5574
dnd: Arc::new(AtomicBool::new(false)),
75+
detect_enabled: Arc::new(AtomicBool::new(true)),
5676
}
5777
}
5878

59-
pub(crate) fn set_dnd(&self, value: bool) {
79+
pub fn set_dnd(&self, value: bool) {
6080
self.dnd.store(value, Ordering::Relaxed);
6181
}
82+
83+
pub fn set_detect_enabled(&self, value: bool) {
84+
self.detect_enabled.store(value, Ordering::Relaxed);
85+
}
6286
}
6387

6488
impl Env for TestEnv {
@@ -69,5 +93,9 @@ pub(crate) mod test_support {
6993
fn is_do_not_disturb(&self) -> bool {
7094
self.dnd.load(Ordering::Relaxed)
7195
}
96+
97+
fn is_detect_enabled(&self) -> bool {
98+
self.detect_enabled.load(Ordering::Relaxed)
99+
}
72100
}
73101
}

0 commit comments

Comments
 (0)