MCPcopy Create free account
hub / github.com/Moosync/Moosync / handle_pref_changes

Function handle_pref_changes

src-tauri/src/preference_holder/mod.rs:45–109  ·  view source on GitHub ↗
(app: AppHandle)

Source from the content-addressed store, hash-verified

43
44#[tracing::instrument(level = "debug", skip(app))]
45pub fn handle_pref_changes(app: AppHandle) {
46 async_runtime::spawn(async move {
47 let pref_config: State<PreferenceConfig> = app.state::<PreferenceConfig>();
48 let receiver = pref_config.get_receiver();
49 for (key, value) in receiver {
50 tracing::debug!("Received key: {} value: {}", key, value);
51 if UI_KEYS.contains(&key.as_str()) {
52 tracing::info!("Emitting preference-changed event");
53 if let Err(e) = app.emit("preference-changed", (key.clone(), value.clone())) {
54 tracing::error!("Error emitting preference-changed event{}", e);
55 } else {
56 tracing::info!("Emitted preference-changed event");
57 }
58 }
59
60 if key == "prefs.music_paths" || key == "prefs.exclude_music_paths" {
61 let app = app.clone();
62 thread::spawn(move || {
63 let app = app.clone();
64 if let Err(e) = start_scan(app, None) {
65 tracing::error!("{}", e);
66 }
67 });
68 }
69
70 if key.starts_with("prefs.youtube") {
71 let provider_state: State<ProviderHandler> = app.state();
72 provider_state.initialize_provider("youtube".into()).await;
73 }
74
75 if key.starts_with("prefs.spotify") {
76 let provider_state: State<ProviderHandler> = app.state();
77 provider_state.initialize_provider("spotify".into()).await;
78 }
79
80 if key.starts_with("prefs.system_settings") {
81 #[cfg(not(any(target_os = "android", target_os = "ios")))]
82 {
83 let manager: State<tauri_plugin_autostart::AutoLaunchManager> = app.state();
84
85 let auto_start = pref_config.load_selective_array::<CheckboxPreference>(
86 "system_settings.auto_startup".into(),
87 );
88 tracing::info!("Setting autolaunch {:?}", auto_start);
89 if let Ok(auto_start) = auto_start {
90 let res = if auto_start.enabled {
91 manager.enable()
92 } else {
93 manager.disable()
94 };
95
96 if let Err(e) = res {
97 tracing::error!("Error toggling autostart {:?}", e);
98 }
99 }
100 }
101 }
102

Callers 1

runFunction · 0.85

Calls 6

start_scanFunction · 0.85
get_receiverMethod · 0.80
emitMethod · 0.80
cloneMethod · 0.80
initialize_providerMethod · 0.80
spawn_scan_taskMethod · 0.80

Tested by

no test coverage detected