| 25 | |
| 26 | #[tracing::instrument(level = "debug", skip(app))] |
| 27 | pub fn get_theme_handler_state(app: &mut App) -> ThemeHolder { |
| 28 | let path = app.path().app_local_data_dir().unwrap().join("themes"); |
| 29 | if !path.exists() { |
| 30 | fs::create_dir_all(path.clone()).unwrap(); |
| 31 | } |
| 32 | |
| 33 | let tmp_dir = app.path().temp_dir().unwrap(); |
| 34 | |
| 35 | let (tx, rx) = channel(); |
| 36 | |
| 37 | let app_handle = app.app_handle().clone(); |
| 38 | tauri::async_runtime::spawn(async move { |
| 39 | while let Ok(event) = rx.recv() { |
| 40 | if let Err(e) = app_handle.emit("theme-updated", event) { |
| 41 | tracing::error!("Failed to emit theme_updated event: {:?}", e); |
| 42 | } |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | ThemeHolder::new(path, tmp_dir, tx) |
| 47 | } |
| 48 | |
| 49 | #[tracing::instrument(level = "debug", skip(app, theme_handler, window_handler))] |
| 50 | #[tauri::command(async)] |