Upgraded Tauri to v2.12.7 and the Rust dependencies (#1219)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-22 20:56:12 +01:00
1 parent f96025529a
commit 2772612c00
11 files changed
+1968 -1973

No files matched your search

+10 -3
View File
@@ -325,6 +325,12 @@ pub fn start_tauri(tauri_context: tauri::Context<tauri::Wry>) {
info!(Source = "Tauri"; "Run event: Tauri app is ready.");
}
// When AI Studio restarts itself, Tauri would start the new instance in the background next:
#[cfg(target_os = "macos")]
RunEvent::Exit => {
crate::own_restart::start_new_instance_in_front();
}
_ => {}
}
});
@@ -1000,7 +1006,7 @@ pub async fn install_update() {
if is_prod() {
if let Some(handle) = app_handle {
handle.restart();
crate::own_restart::restart(&handle);
} else {
warn!(Source = "Tauri"; "Cannot restart after update: main window not available.");
}
@@ -1013,7 +1019,7 @@ pub async fn install_update() {
if servers_stopped {
warn!(Source = "Tauri"; "The .NET server and Qdrant Edge are already stopped; try to restart the app now...");
if let Some(handle) = app_handle {
handle.restart();
crate::own_restart::restart(&handle);
} else {
warn!(Source = "Tauri"; "Cannot restart after the failed update: main window not available.");
}
@@ -1104,7 +1110,7 @@ pub async fn restart_app() -> Json<AppRestartResponse> {
info!(Source = "Tauri"; "Controlled app restart was requested by the UI.");
tauri::async_runtime::spawn(async move {
time::sleep(Duration::from_millis(50)).await;
app_handle.request_restart();
crate::own_restart::request_restart(&app_handle);
});
Json(AppRestartResponse {
@@ -1562,6 +1568,7 @@ mod tests {
let approved = tauri::Url::parse("http://127.0.0.1:12345/").unwrap();
for address in [
"file:///etc/passwd",
"about:blank",
"javascript:alert(1)",
"data:text/html,hello",
"tauri://localhost/index.html",
+1
View File
@@ -29,3 +29,4 @@ pub mod tokenizer;
mod file_actions;
pub mod global_shortcuts;
pub mod interface_zoom;
mod own_restart;
+109
View File
@@ -0,0 +1,109 @@
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::AppHandle;
#[cfg(target_os = "macos")]
use std::path::Path;
#[cfg(target_os = "macos")]
use log::{info, warn};
/// Whether AI Studio restarts itself, see `restart` and `request_restart`.
static RESTART_REQUESTED: AtomicBool = AtomicBool::new(false);
/// Restarts the app at once, see `AppHandle::restart`, and shows its window in the foreground again.
///
/// On macOS, Tauri starts the new instance in the background, so that a restart in the background
/// takes no focus away from the app the user works in. AI Studio restarts itself only on behalf of
/// the user, e.g., to finish an update, who then expects to see the app again. Therefore, AI Studio
/// starts the new instance itself, see `start_new_instance_in_front`.
///
/// Call it outside the main thread only: there, Tauri restarts the app at once, without the event
/// `RunEvent::Exit`, and therefore in the background.
pub fn restart(app_handle: &AppHandle) -> ! {
RESTART_REQUESTED.store(true, Ordering::SeqCst);
app_handle.restart()
}
/// Requests a restart of the app, see `AppHandle::request_restart`, and shows its window in the
/// foreground again, see `restart`.
pub fn request_restart(app_handle: &AppHandle) {
RESTART_REQUESTED.store(true, Ordering::SeqCst);
app_handle.request_restart();
}
/// Starts the new instance in the foreground and ends this one, when AI Studio restarts itself.
///
/// Call it on `RunEvent::Exit`, which reaches the app right before Tauri starts the new instance in
/// the background. The new instance cannot bring its window to the front by itself: macOS lets an app
/// become active only when the active app allows it. The old instance, however, is still the active
/// app, so the new instance it starts comes to the front.
///
/// Outside an app bundle, as in a development build, and when the start fails, Tauri restarts the
/// app as usual.
#[cfg(target_os = "macos")]
pub fn start_new_instance_in_front() {
use std::process::{exit, Command, Stdio};
if !RESTART_REQUESTED.load(Ordering::SeqCst) {
return;
}
let Ok(binary) = std::env::current_exe() else {
return;
};
let Some(bundle) = app_bundle(&binary) else {
return;
};
info!(Source = "Tauri"; "Starting the new instance of AI Studio in the foreground.");
let result = Command::new("/usr/bin/open")
.arg("-n")
.arg(bundle)
.arg("--args")
.args(std::env::args_os().skip(1))
.stdin(Stdio::null())
.output();
match result {
Ok(output) if output.status.success() => {
log::logger().flush();
exit(0);
},
Ok(output) => warn!(Source = "Tauri"; "Failed to start the new instance in the foreground ({}), so Tauri starts it in the background: {}", output.status, String::from_utf8_lossy(&output.stderr).trim()),
Err(error) => warn!(Source = "Tauri"; "Failed to start the new instance in the foreground, so Tauri starts it in the background: {error}"),
}
}
/// Returns the app bundle which contains the binary, such as `/Applications/X.app` for
/// `/Applications/X.app/Contents/MacOS/x`.
#[cfg(target_os = "macos")]
fn app_bundle(binary: &Path) -> Option<&Path> {
let macos_directory = binary.parent()?;
let contents_directory = macos_directory.parent()?;
if macos_directory.file_name()? != "MacOS" || contents_directory.file_name()? != "Contents" {
return None;
}
contents_directory.parent()
}
#[cfg(all(test, target_os = "macos"))]
mod tests {
use std::path::Path;
use super::app_bundle;
#[test]
fn finds_the_bundle_of_a_binary_inside_one() {
let binary = Path::new("/Applications/MindWork AI Studio.app/Contents/MacOS/mindwork-ai-studio");
assert_eq!(app_bundle(binary), Some(Path::new("/Applications/MindWork AI Studio.app")));
}
#[test]
fn finds_no_bundle_for_a_binary_outside_one() {
assert_eq!(app_bundle(Path::new("/Users/placeholder/runtime/target/debug/mindwork-ai-studio")), None);
assert_eq!(app_bundle(Path::new("/Applications/MindWork AI Studio.app/Contents/Resources/mindwork-ai-studio")), None);
assert_eq!(app_bundle(Path::new("/mindwork-ai-studio")), None);
}
}
+37
View File
@@ -93,3 +93,40 @@ fn load_pdfium() -> Result<Pdfium, String> {
}
}
}
#[cfg(test)]
mod tests {
/// pdfium-render refuses a PDFium library which lacks a function of the version its feature names.
/// Its default features name the newest PDFium it knows, which changes with updates of the crate,
/// while we ship the PDFium of line 10 of metadata.txt. A mismatch makes every PDF fail to open,
/// and no other test notices, since none of them loads the library.
#[test]
fn binds_the_api_of_the_shipped_pdfium() {
let pdfium_version = include_str!("../../metadata.txt").lines().nth(9).expect("metadata.txt must name the PDFium version in line 10");
let chromium_revision = pdfium_version.trim().split('.').nth(2).expect("the PDFium version must have the form 148.0.7763.0");
let expected_feature = format!("pdfium_{chromium_revision}");
let manifest: toml::Table = toml::from_str(include_str!("../Cargo.toml")).expect("Cargo.toml must be valid TOML");
let dependency = &manifest["dependencies"]["pdfium-render"];
assert_eq!(
dependency.get("default-features").and_then(toml::Value::as_bool),
Some(false),
"pdfium-render must not use its default features: they bind the newest PDFium the crate knows, not the one we ship.",
);
let api_features: Vec<&str> = dependency.get("features")
.and_then(toml::Value::as_array)
.into_iter()
.flatten()
.filter_map(toml::Value::as_str)
.filter(|feature| feature.strip_prefix("pdfium_").is_some_and(|version| version == "latest" || version.chars().all(|c| c.is_ascii_digit())))
.collect();
assert_eq!(
api_features,
[expected_feature.as_str()],
"The feature of pdfium-render must name the PDFium version in metadata.txt. Change both together.",
);
}
}