Fixed the clipboard and the .NET server which did not stop when you quit AI Studio on macOS

This commit is contained in:
Thorsten Sommer committed 2026-11-25 12:50:16 +01:00
1 parent 4077e5c50f
commit 377dc070f4
1 file changed
+24 -10
+24 -10
View File
@@ -1,6 +1,7 @@
use std::convert::Infallible; use std::convert::Infallible;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use async_stream::stream; use async_stream::stream;
use axum::body::Body; use axum::body::Body;
@@ -313,12 +314,7 @@ pub fn start_tauri(tauri_context: tauri::Context<tauri::Wry>) {
RunEvent::ExitRequested { .. } => { RunEvent::ExitRequested { .. } => {
warn!(Source = "Tauri"; "Run event: exit was requested."); warn!(Source = "Tauri"; "Run event: exit was requested.");
shutdown_clipboard(); stop_services();
stop_qdrant_edge_database();
if is_prod() {
warn!("Try to stop the .NET server as well...");
stop_dotnet_server();
}
} }
RunEvent::Ready => { RunEvent::Ready => {
@@ -326,10 +322,7 @@ pub fn start_tauri(tauri_context: tauri::Context<tauri::Wry>) {
} }
RunEvent::Exit => { RunEvent::Exit => {
// Quitting through the menu of macOS, e.g., with Cmd+Q, skips RunEvent::ExitRequested. stop_services();
// Qdrant Edge has to stop anyway, so that it unloads its stores. When it already
// stopped, this does nothing.
stop_qdrant_edge_database();
// When AI Studio restarts itself, Tauri would start the new instance in the background next: // When AI Studio restarts itself, Tauri would start the new instance in the background next:
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
@@ -343,6 +336,27 @@ pub fn start_tauri(tauri_context: tauri::Context<tauri::Wry>) {
warn!(Source = "Tauri"; "Tauri app was stopped."); warn!(Source = "Tauri"; "Tauri app was stopped.");
} }
/// Whether `stop_services` already ran.
static SERVICES_STOPPED: AtomicBool = AtomicBool::new(false);
/// Stops what AI Studio runs next to its window: the clipboard, Qdrant Edge, and, in a release, the
/// .NET server.
///
/// Runs on `RunEvent::ExitRequested` and on `RunEvent::Exit`, whichever comes first: quitting
/// through the menu of macOS, e.g., with Cmd+Q, skips `RunEvent::ExitRequested`.
fn stop_services() {
if SERVICES_STOPPED.swap(true, Ordering::SeqCst) {
return;
}
shutdown_clipboard();
stop_qdrant_edge_database();
if is_prod() {
warn!("Try to stop the .NET server as well...");
stop_dotnet_server();
}
}
fn is_local_host(host: Option<&str>) -> bool { fn is_local_host(host: Option<&str>) -> bool {
matches!(host, Some("localhost") | Some("127.0.0.1") | Some("::1") | Some("[::1]")) matches!(host, Some("localhost") | Some("127.0.0.1") | Some("::1") | Some("[::1]"))
} }