Skip to content

Commit f1495b8

Browse files
committed
wip
1 parent ffac211 commit f1495b8

File tree

12 files changed

+64
-87
lines changed

12 files changed

+64
-87
lines changed

Cargo.lock

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

apps/desktop/src-tauri/src/ext.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use tauri_plugin_store2::{ScopedStore, StorePluginExt};
99
pub trait AppExt<R: tauri::Runtime> {
1010
fn sentry_dsn(&self) -> String;
1111
fn desktop_store(&self) -> Result<ScopedStore<R, crate::StoreKey>, String>;
12-
fn setup_local_ai(&self) -> impl Future<Output = Result<(), String>>;
1312
fn setup_db_for_local(&self) -> impl Future<Output = Result<(), String>>;
1413
fn setup_db_for_cloud(&self) -> impl Future<Output = Result<(), String>>;
1514
}
@@ -34,38 +33,6 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> AppExt<R> for T {
3433
self.scoped_store("desktop").map_err(|e| e.to_string())
3534
}
3635

37-
#[tracing::instrument(skip_all)]
38-
39-
async fn setup_local_ai(&self) -> Result<(), String> {
40-
{
41-
use tauri_plugin_local_stt::LocalSttPluginExt;
42-
43-
let current_model = self
44-
.get_current_model()
45-
.unwrap_or(SupportedSttModel::Whisper(WhisperModel::QuantizedSmall));
46-
47-
if let Ok(true) = self.is_model_downloaded(&current_model).await {
48-
if let Err(e) = self.start_server(Some(current_model)).await {
49-
tracing::error!("start_local_stt_server: {}", e);
50-
}
51-
}
52-
}
53-
54-
{
55-
use tauri_plugin_local_llm::{LocalLlmPluginExt, SupportedModel};
56-
57-
let current_model = self.get_current_model().unwrap_or(SupportedModel::HyprLLM);
58-
59-
if let Ok(true) = self.is_model_downloaded(&current_model).await {
60-
if let Err(e) = self.start_server().await {
61-
tracing::error!("start_local_llm_server: {}", e);
62-
}
63-
}
64-
}
65-
66-
Ok(())
67-
}
68-
6936
#[tracing::instrument(skip_all)]
7037
async fn setup_db_for_local(&self) -> Result<(), String> {
7138
let (db, db_just_created) = {

apps/desktop/src-tauri/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@ pub async fn main() {
236236
}
237237
}
238238
}
239-
240-
tokio::spawn(async move {
241-
app_clone.setup_local_ai().await.unwrap();
242-
});
243239
});
244240

245241
Ok(())

apps/desktop/src/components/settings/components/ai/stt-view-local.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function ProModelsSection({
250250
{proModels.data?.map((model) => (
251251
<ModelEntry
252252
key={model.key}
253-
disabled={true}
253+
disabled={false}
254254
model={model}
255255
selectedSTTModel={selectedSTTModel}
256256
setSelectedSTTModel={setSelectedSTTModel}

crates/detect/src/mic/macos.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ impl crate::Observer for Detector {
208208
system_listener,
209209
system_listener_ptr,
210210
) {
211-
println!("Failed to add system listener: {:?}", e);
211+
tracing::error!("adding_system_listener_failed: {:?}", e);
212212
} else {
213-
println!("✅ System listener added successfully");
213+
tracing::info!("adding_system_listener_success");
214214
}
215215

216216
if let Ok(device) = ca::System::default_input_device() {
@@ -229,7 +229,7 @@ impl crate::Observer for Detector {
229229
)
230230
.is_ok()
231231
{
232-
println!("✅ Device listener added successfully");
232+
tracing::info!("adding_device_listener_success");
233233

234234
if let Ok(mut device_guard) = current_device.lock() {
235235
*device_guard = Some(device);
@@ -244,10 +244,10 @@ impl crate::Observer for Detector {
244244
}
245245
}
246246
} else {
247-
println!("❌ Failed to add device listener");
247+
tracing::error!("adding_device_listener_failed");
248248
}
249249
} else {
250-
println!("⚠️ No default input device found");
250+
tracing::warn!("no_default_input_device_found");
251251
}
252252

253253
let _ = tx.blocking_send(());

plugins/local-llm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ hypr-llama = { workspace = true }
3131

3232
tauri = { workspace = true, features = ["test"] }
3333
tauri-plugin-store2 = { workspace = true }
34+
tauri-plugin-windows = { workspace = true }
3435
tauri-specta = { workspace = true, features = ["derive", "typescript"] }
3536

3637
thiserror = { workspace = true }

plugins/local-llm/src/events.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::LocalLlmPluginExt;
2+
use tauri_plugin_windows::HyprWindow;
3+
4+
pub fn on_event<R: tauri::Runtime>(app: &tauri::AppHandle<R>, event: &tauri::RunEvent) {
5+
match event {
6+
tauri::RunEvent::WindowEvent { label, event, .. } => {
7+
let hypr_window = match label.parse::<HyprWindow>() {
8+
Ok(window) => window,
9+
Err(e) => {
10+
tracing::warn!("parse_error: {:?}", e);
11+
return;
12+
}
13+
};
14+
15+
if hypr_window != HyprWindow::Main {
16+
return;
17+
}
18+
19+
match event {
20+
tauri::WindowEvent::Focused(true) => {
21+
tokio::task::block_in_place(|| {
22+
tokio::runtime::Handle::current().block_on(async {
23+
let _ = app.start_server().await;
24+
});
25+
});
26+
}
27+
_ => {}
28+
}
29+
}
30+
_ => {}
31+
}
32+
}

plugins/local-llm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use tokio::sync::Mutex;
66

77
mod commands;
88
mod error;
9+
mod events;
910
mod ext;
1011
mod manager;
1112
mod model;
1213
mod server;
1314
mod store;
1415

1516
pub use error::*;
17+
use events::*;
1618
pub use ext::*;
1719
pub use manager::*;
1820
pub use model::*;
@@ -83,6 +85,7 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
8385

8486
Ok(())
8587
})
88+
.on_event(on_event)
8689
.build()
8790
}
8891

plugins/local-stt/src/events.rs

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,32 @@
1-
use tauri::Manager;
2-
3-
use crate::{LocalSttPluginExt, SharedState};
1+
use crate::LocalSttPluginExt;
42
use tauri_plugin_windows::HyprWindow;
53

64
pub fn on_event<R: tauri::Runtime>(app: &tauri::AppHandle<R>, event: &tauri::RunEvent) {
7-
let state = app.state::<SharedState>();
8-
95
match event {
10-
tauri::RunEvent::WindowEvent { label, event, .. } => match event {
11-
tauri::WindowEvent::CloseRequested { .. } | tauri::WindowEvent::Destroyed => {
12-
let hypr_window = match label.parse::<HyprWindow>() {
13-
Ok(window) => window,
14-
Err(e) => {
15-
tracing::warn!("window_parse_error: {:?}", e);
16-
return;
17-
}
18-
};
19-
20-
if hypr_window != HyprWindow::Main {
6+
tauri::RunEvent::WindowEvent { label, event, .. } => {
7+
let hypr_window = match label.parse::<HyprWindow>() {
8+
Ok(window) => window,
9+
Err(e) => {
10+
tracing::warn!("parse_error: {:?}", e);
2111
return;
2212
}
13+
};
2314

24-
tracing::info!("events: stopping servers");
25-
26-
tokio::task::block_in_place(|| {
27-
tokio::runtime::Handle::current().block_on(async {
28-
let mut guard = state.lock().await;
29-
30-
if let Some(_) = guard.internal_server.take() {
31-
guard.internal_server = None;
32-
}
33-
if let Some(_) = guard.external_server.take() {
34-
guard.external_server = None;
35-
}
36-
for (_, (task, token)) in guard.download_task.drain() {
37-
token.cancel();
38-
task.abort();
39-
}
40-
});
41-
});
15+
if hypr_window != HyprWindow::Main {
16+
return;
4217
}
43-
tauri::WindowEvent::Focused(true) => {
44-
tokio::task::block_in_place(|| {
45-
tokio::runtime::Handle::current().block_on(async {
46-
let _ = app.start_server(None).await;
18+
19+
match event {
20+
tauri::WindowEvent::Focused(true) => {
21+
tokio::task::block_in_place(|| {
22+
tokio::runtime::Handle::current().block_on(async {
23+
let _ = app.start_server(None).await;
24+
});
4725
});
48-
});
26+
}
27+
_ => {}
4928
}
50-
_ => {}
51-
},
29+
}
5230
_ => {}
5331
}
5432
}

plugins/local-stt/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ mod model;
1010
mod server;
1111
mod store;
1212
mod types;
13-
mod utils;
1413

1514
pub use error::*;
1615
use events::*;
1716
pub use ext::*;
1817
pub use model::*;
1918
pub use store::*;
2019
pub use types::*;
21-
use utils::*;
2220

2321
pub type SharedState = std::sync::Arc<tokio::sync::Mutex<State>>;
2422

0 commit comments

Comments
 (0)