Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: use native Linux browser tabs with GTK overlay sizing (#13717)

Wasim Yousef Said02d9ea35a3cd
diff --git a/studio/src-tauri/src/browser_capture.rs b/studio/src-tauri/src/browser_capture.rs
index ae32a14721a..a88d630d668 100644
--- a/studio/src-tauri/src/browser_capture.rs
+++ b/studio/src-tauri/src/browser_capture.rs
@@ -67,9 +67,10 @@ pub async fn browser_capture<R: Runtime>(
}
});
let views = app.state::<BrowserViews>();
- let shown_for_shot = tab
- .as_deref()
- .is_some_and(|tab| show_for_capture(&views, &target, tab));
+ let shown_for_shot = match tab.as_deref() {
+ Some(tab) => show_for_capture(&views, &target, tab).await,
+ None => false,
+ };
if shown_for_shot {
// A frame for the page to paint where it now sits.
tokio::time::sleep(SHOW_FOR_CAPTURE_PAINT).await;
@@ -82,7 +83,7 @@ pub async fn browser_capture<R: Runtime>(
Err(error) => Ok(Ok(Err(error))),
};
if let (true, Some(tab)) = (shown_for_shot, tab.as_deref()) {
- end_capture(&views, &target, tab);
+ end_capture(&views, &target, tab).await;
}
let png = match png {
Ok(Ok(result)) => result?,
@@ -223,19 +224,16 @@ fn platform_capture(platform: tauri::webview::PlatformWebview, clip: Option<Clip
}
}
-/// WebKitGTK only shows the panel's frames (no native views on Linux): crop the app's snapshot.
+/// Capture the native page, or crop the app's snapshot for non-native panel content.
#[cfg(target_os = "linux")]
fn platform_capture(platform: tauri::webview::PlatformWebview, clip: Option<Clip>, done: Done) {
use webkit2gtk::{SnapshotOptions, SnapshotRegion, WebViewExt};
- let Some(clip) = clip else {
- return done(Err("No native pages on Linux".into()));
- };
let view = platform.inner();
let scale = {
use gtk::prelude::WidgetExt;
let width = f64::from(view.allocated_width());
- if width > 0.0 { width / clip.viewport_width } else { 1.0 }
+ clip.filter(|_| width > 0.0).map_or(1.0, |clip| width / clip.viewport_width)
};
view.snapshot(
SnapshotRegion::Visible,
@@ -245,7 +243,14 @@ fn platform_capture(platform: tauri::webview::PlatformWebview, clip: Option<Clip
done(
result
.map_err(|error| error.to_string())
- .and_then(|surface| crop_png(&surface, clip, scale)),
+ .and_then(|surface| match clip {
+ Some(clip) => crop_png(&surface, clip, scale),
+ None => {
+ let mut png = Vec::new();
+ surface.write_to_png(&mut png).map_err(|error| error.to_string())?;
+ Ok(png)
+ }
+ }),
)
},
);
@@ -334,7 +339,20 @@ fn platform_print(platform: tauri::webview::PlatformWebview) -> Result<(), Strin
}
}
-#[cfg(not(any(target_os = "macos", windows)))]
+#[cfg(target_os = "linux")]
+fn platform_print(platform: tauri::webview::PlatformWebview) -> Result<(), String> {
+ use gtk::prelude::*;
+ use webkit2gtk::{PrintOperation, PrintOperationExt};
+ let view = platform.inner();
+ let parent = view.toplevel().and_then(|widget| widget.downcast::<gtk::Window>().ok());
+ // The GTK dialog blocks until dismissed; acknowledge before entering its nested loop.
+ glib::idle_add_local_once(move || {
+ PrintOperation::new(&view).run_dialog(parent.as_ref());
+ });
+ Ok(())
+}
+
+#[cfg(not(any(target_os = "macos", windows, target_os = "linux")))]
fn platform_print(_platform: tauri::webview::PlatformWebview) -> Result<(), String> {
Err("No native pages here".into())
}
diff --git a/studio/src-tauri/src/browser_linux.rs b/studio/src-tauri/src/browser_linux.rs
new file mode 100644
index 00000000000..eaf7aa25701
--- /dev/null
+++ b/studio/src-tauri/src/browser_linux.rs
@@ -0,0 +1,228 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+//! GtkBox ignores child webview bounds. An overlay owns each page's allocation instead.
+//! Tauri's `unstable` WindowChild path lets the main view be reparented without the
+//! WindowContent resize handler's WebView -> VBox -> Window ancestry assumption.
+
+use glib::signal::connect_raw;
+use gtk::prelude::*;
+use std::cell::{Cell, RefCell};
+use std::collections::HashMap;
+use std::rc::Rc;
+use std::time::Duration;
+use tauri::{LogicalPosition, LogicalSize, Runtime, Webview};
+use webkit2gtk::{WebView, WebViewExt};
+
+#[derive(Clone, Copy)]
+struct Bounds {
+ position: LogicalPosition<f64>,
+ size: LogicalSize<f64>,
+}
+
+struct Page {
+ view: WebView,
+ bounds: Rc<Cell<Bounds>>,
+ handler: glib::SignalHandlerId,
+}
+
+struct Host {
+ overlay: gtk::Overlay,
+ pages: HashMap<String, Page>,
+}
+
+thread_local! {
+ static HOST: RefCell<Option<Host>> = const { RefCell::new(None) };
+}
+
+async fn on_view<R: Runtime>(
+ view: &Webview<R>,
+ apply: impl FnOnce(WebView) -> Result<(), String> + Send + 'static,
+) -> Result<(), String> {
+ let (send, receive) = tokio::sync::oneshot::channel();
+ view.with_webview(move |platform| {
+ let _ = send.send(apply(platform.inner()));
+ })
+ .map_err(|error| error.to_string())?;
+ tokio::time::timeout(Duration::from_secs(5), receive)
+ .await
+ .map_err(|_| "GTK browser update timed out".to_string())?
+ .map_err(|_| "GTK browser view closed".to_string())?
+}
+
+pub async fn install<R: Runtime>(main: &Webview<R>) -> Result<(), String> {
+ on_view(main, |main| {
+ HOST.with(|host| {
+ let mut host = host.borrow_mut();
+ if host.is_some() {
+ return Ok(());
+ }
+ let parent = main
+ .parent()
+ .and_then(|parent| parent.downcast::<gtk::Box>().ok())
+ .ok_or("main webview has no GTK box parent")?;
+ let overlay = gtk::Overlay::new();
+ overlay.set_hexpand(true);
+ overlay.set_vexpand(true);
+ let focused = main.has_focus();
+ parent.remove(&main);
+ overlay.add(&main);
+ parent.pack_start(&overlay, true, true, 0);
+ overlay.show_all();
+ if focused {
+ main.grab_focus();
+ }
+ *host = Some(Host {
+ overlay,
+ pages: HashMap::new(),
+ });
+ Ok(())
+ })
+ })
+ .await
+}
+
+struct AllocationData {
+ view: WebView,
+ bounds: Rc<Cell<Bounds>>,
+ fullscreen: Rc<Cell<bool>>,
+}
+
+// GTK passes a writable allocation; gtk-rs 0.18 does not generate this signal.
+// connect_raw owns AllocationData and drops it when its handler is disconnected.
+unsafe extern "C" fn position_child(
+ overlay: *mut gtk::ffi::GtkOverlay,
+ widget: *mut gtk::ffi::GtkWidget,
+ allocation: *mut gdk::ffi::GdkRectangle,
+ data: glib::ffi::gpointer,
+) -> glib::ffi::gboolean {
+ let data = &*(data as *const AllocationData);
+ if widget != data.view.as_ptr() as *mut gtk::ffi::GtkWidget || allocation.is_null() {
+ return 0;
+ }
+ if data.fullscreen.get() {
+ *allocation = gdk::ffi::GdkRectangle {
+ x: 0,
+ y: 0,
+ width: gtk::ffi::gtk_widget_get_allocated_width(overlay.cast()).max(1),
+ height: gtk::ffi::gtk_widget_get_allocated_height(overlay.cast()).max(1),
+ };
+ return 1;
+ }
+ let Bounds { position, size } = data.bounds.get();
+ *allocation = gdk::ffi::GdkRectangle {
+ x: position.x.round() as i32,
+ y: position.y.round() as i32,
+ width: size.width.round().max(1.0) as i32,
+ height: size.height.round().max(1.0) as i32,
+ };
+ 1
+}
+
+pub async fn attach<R: Runtime>(
+ page: &Webview<R>,
+ position: LogicalPosition<f64>,
+ size: LogicalSize<f64>,
+) -> Result<(), String> {
+ let label = page.label().to_string();
+ on_view(page, move |view| {
+ HOST.with(|host| {
+ let mut host = host.borrow_mut();
+ let host = host.as_mut().ok_or("GTK browser host not initialized")?;
+ if host.pages.contains_key(&label) {
+ return Err("GTK browser already attached".into());
+ }
+ let parent = view
+ .parent()
+ .and_then(|parent| parent.downcast::<gtk::Container>().ok())
+ .ok_or("browser has no GTK parent")?;
+ view.hide();
+ parent.remove(&view);
+ let bounds = Rc::new(Cell::new(Bounds { position, size }));
+ let fullscreen = Rc::new(Cell::new(false));
+ let on_fullscreen = |active| {
+ let fullscreen = fullscreen.clone();
+ let overlay = host.overlay.downgrade();
+ move |_: &WebView| {
+ fullscreen.set(active);
+ if let Some(overlay) = overlay.upgrade() {
+ overlay.queue_resize();
+ }
+ false // Let WebKit handle the top-level window transition.
+ }
+ };
+ view.connect_enter_fullscreen(on_fullscreen(true));
+ view.connect_leave_fullscreen(on_fullscreen(false));
+ let data = Box::new(AllocationData {
+ view: view.clone(),
+ bounds: bounds.clone(),
+ fullscreen,
+ });
+ let handler = unsafe {
+ connect_raw(
+ host.overlay.as_ptr() as *mut _,
+ c"get-child-position".as_ptr(),
+ Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
+ position_child as *const (),
+ )),
+ Box::into_raw(data),
+ )
+ };
+ view.set_hexpand(false);
+ view.set_vexpand(false);
+ host.overlay.add_overlay(&view);
+ host.overlay.set_overlay_pass_through(&view, false);
+ host.pages.insert(
+ label,
+ Page {
+ view,
+ bounds,
+ handler,
+ },
+ );
+ host.overlay.queue_resize();
+ Ok(())
+ })
+ })
+ .await
+}
+
+pub async fn set_bounds<R: Runtime>(
+ page: &Webview<R>,
+ position: LogicalPosition<f64>,
+ size: LogicalSize<f64>,
+) -> Result<(), String> {
+ let label = page.label().to_string();
+ on_view(page, move |view| {
+ HOST.with(|host| {
+ let host = host.borrow();
+ let host = host.as_ref().ok_or("GTK browser host not initialized")?;
+ let page = host
+ .pages
+ .get(&label)
+ .filter(|page| page.view == view)
+ .ok_or("GTK browser not attached")?;
+ page.bounds.set(Bounds { position, size });
+ host.overlay.queue_resize();
+ Ok(())
+ })
+ })
+ .await
+}
+
+pub fn detach<R: Runtime>(page: &Webview<R>) -> tauri::Result<()> {
+ let label = page.label().to_string();
+ page.run_on_main_thread(move || {
+ HOST.with(|host| {
+ if let Some(host) = host.borrow_mut().as_mut() {
+ if let Some(page) = host.pages.remove(&label) {
+ host.overlay.disconnect(page.handler);
+ page.view.hide();
+ if page.view.parent().as_ref() == Some(host.overlay.upcast_ref()) {
+ host.overlay.remove(&page.view);
+ }
+ }
+ }
+ });
+ })
+}
diff --git a/studio/src-tauri/src/browser_webview.rs b/studio/src-tauri/src/browser_webview.rs
index 02dbe9f2629..aacf1dd6f1d 100644
--- a/studio/src-tauri/src/browser_webview.rs
+++ b/studio/src-tauri/src/browser_webview.rs
@@ -1082,10 +1082,21 @@ pub(crate) fn download_finished<R: Runtime>(
fn close_view<R: Runtime>(page: &Webview<R>) -> tauri::Result<()> {
#[cfg(target_os = "macos")]
crate::browser_context_downloads::forget(page);
+ #[cfg(target_os = "linux")]
+ crate::browser_linux::detach(page)?;
page.close()
}
-fn create_view<R: Runtime>(
+#[cfg(target_os = "linux")]
+pub fn close_all<R: Runtime>(app: &AppHandle<R>) {
+ for page in browser_views(app) {
+ if let Err(error) = close_view(&page) {
+ log::warn!("Could not close browser page before exit: {error}");
+ }
+ }
+}
+
+async fn create_view<R: Runtime>(
caller: &Webview<R>,
tab_id: &str,
url: Url,
@@ -1103,9 +1114,9 @@ fn create_view<R: Runtime>(
let window_tab = tab.clone();
let download_tab = tab.clone();
- #[cfg(target_os = "macos")]
+ #[cfg(any(target_os = "macos", target_os = "linux"))]
let (initial, deferred) = (Url::parse("about:blank").unwrap(), Some(url));
- #[cfg(not(target_os = "macos"))]
+ #[cfg(not(any(target_os = "macos", target_os = "linux")))]
let (initial, deferred): (Url, Option<Url>) = (url, None);
let builder = WebviewBuilder::new(&label, WebviewUrl::External(initial))
@@ -1219,6 +1230,11 @@ fn create_view<R: Runtime>(
let webview = window
.add_child(builder, position, size)
.map_err(|error| error.to_string())?;
+ #[cfg(target_os = "linux")]
+ if let Err(error) = crate::browser_linux::attach(&webview, position, size).await {
+ let _ = webview.close();
+ return Err(error);
+ }
#[cfg(target_os = "macos")]
crate::browser_layer::place(&webview);
#[cfg(target_os = "macos")]
@@ -1230,6 +1246,18 @@ fn create_view<R: Runtime>(
if let Some(url) = deferred {
load_when_protected(&webview, url);
}
+ app.state::<BrowserViews>()
+ .inner
+ .lock()
+ .unwrap()
+ .placed
+ .insert(
+ tab,
+ Rect {
+ position: position.into(),
+ size: size.into(),
+ },
+ );
start_url_poll(&app);
Ok(webview)
}
@@ -1357,16 +1385,14 @@ fn browser_views<R: Runtime>(app: &AppHandle<R>) -> Vec<Webview<R>> {
.collect()
}
-/// Whether pages open in native webviews: macOS 14+ (per-webview proxy) and Windows. On Linux
-/// Tauri packs child webviews into the window's GtkBox, which ignores their bounds, so the panel
-/// uses its proxied frame there.
+/// Native pages need per-webview proxy support: macOS 14+, Windows, and Linux.
#[tauri::command]
pub fn browser_view_supported() -> bool {
#[cfg(target_os = "macos")]
return macos_at_least(14);
- #[cfg(target_os = "windows")]
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
return true;
- #[cfg(not(any(target_os = "macos", target_os = "windows")))]
+ #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
false
}
@@ -1435,7 +1461,7 @@ pub async fn browser_view_show<R: Runtime>(
.unwrap()
.placed
.insert(tab_id.clone(), rect);
- view.set_bounds(rect).map_err(|error| error.to_string())?;
+ set_view_bounds(&view, rect).await?;
view
}
None if parked => return Err("no page to park".into()),
@@ -1443,7 +1469,9 @@ pub async fn browser_view_show<R: Runtime>(
let url = parse_page_url(url.as_deref().ok_or("no address to open")?)?;
#[cfg(target_os = "macos")]
crate::browser_layer::install(&webview);
- create_view(&webview, tab_id, url, bounds)?
+ #[cfg(target_os = "linux")]
+ crate::browser_linux::install(&webview).await?;
+ create_view(&webview, tab_id, url, bounds).await?
}
}),
_ => None,
@@ -1475,6 +1503,24 @@ pub async fn browser_view_show<R: Runtime>(
Ok(())
}
+async fn set_view_bounds<R: Runtime>(page: &Webview<R>, rect: Rect) -> Result<(), String> {
+ #[cfg(target_os = "linux")]
+ {
+ let scale = page
+ .window()
+ .scale_factor()
+ .map_err(|error| error.to_string())?;
+ crate::browser_linux::set_bounds(
+ page,
+ rect.position.to_logical(scale),
+ rect.size.to_logical(scale),
+ )
+ .await
+ }
+ #[cfg(not(target_os = "linux"))]
+ page.set_bounds(rect).map_err(|error| error.to_string())
+}
+
/// Opens a tab's page without showing it: the agent at work in a chat that isn't on screen. Made
/// just off the window and hidden, so nothing flashes and the page on screen stays.
#[tauri::command]
@@ -1492,11 +1538,13 @@ pub async fn browser_view_open_background<R: Runtime>(
let url = parse_page_url(&url)?;
#[cfg(target_os = "macos")]
crate::browser_layer::install(&webview);
+ #[cfg(target_os = "linux")]
+ crate::browser_linux::install(&webview).await?;
let off_window = ViewBounds {
x: -bounds.width - PARK_GAP,
..bounds
};
- let page = create_view(&webview, &tab_id, url, &off_window)?;
+ let page = create_view(&webview, &tab_id, url, &off_window).await?;
if let Err(error) = page.hide() {
// The frontend never records a view that failed to open, so it would never close this one.
let _ = close_view(&page);
@@ -1507,28 +1555,33 @@ pub async fn browser_view_open_background<R: Runtime>(
/// A hidden page paints nothing to capture (WebView2 doesn't render it; WebKit's snapshot waits
/// on a paint that never comes), so it shows just off the window for the shot. True if it did.
-pub(crate) fn show_for_capture<R: Runtime>(
+pub(crate) async fn show_for_capture<R: Runtime>(
views: &BrowserViews,
page: &Webview<R>,
tab_id: &str,
) -> bool {
- {
+ let placed = {
let mut inner = views.inner.lock().unwrap();
if inner.shown.as_deref() == Some(tab_id) || !inner.capturing.insert(tab_id.to_string()) {
return false;
}
- }
- let size = page
- .bounds()
- .ok()
+ inner.placed.get(tab_id).copied()
+ };
+ // A GTK view opened hidden has not received its requested allocation yet.
+ let size = placed
+ .or_else(|| page.bounds().ok())
.zip(page.window().scale_factor().ok())
.map(|(rect, factor)| rect.size.to_logical::<f64>(factor))
.unwrap_or(LogicalSize::new(1024.0, 768.0));
let position = LogicalPosition::new(-size.width - PARK_GAP, 0.0);
- let _ = page.set_bounds(Rect {
- position: position.into(),
- size: size.into(),
- });
+ let _ = set_view_bounds(
+ page,
+ Rect {
+ position: position.into(),
+ size: size.into(),
+ },
+ )
+ .await;
if page.show().is_err() {
views.inner.lock().unwrap().capturing.remove(tab_id);
return false;
@@ -1538,13 +1591,18 @@ pub(crate) fn show_for_capture<R: Runtime>(
/// Hides a page `show_for_capture` showed. One that became the shown page meanwhile goes back
/// where the switch put it, not off the window.
-pub(crate) fn end_capture<R: Runtime>(views: &BrowserViews, page: &Webview<R>, tab_id: &str) {
- let mut inner = views.inner.lock().unwrap();
- inner.capturing.remove(tab_id);
- if inner.shown.as_deref() != Some(tab_id) {
- let _ = page.hide();
- } else if let Some(rect) = inner.placed.get(tab_id) {
- let _ = page.set_bounds(*rect);
+pub(crate) async fn end_capture<R: Runtime>(views: &BrowserViews, page: &Webview<R>, tab_id: &str) {
+ let rect = {
+ let mut inner = views.inner.lock().unwrap();
+ inner.capturing.remove(tab_id);
+ if inner.shown.as_deref() != Some(tab_id) {
+ let _ = page.hide();
+ return;
+ }
+ inner.placed.get(tab_id).copied()
+ };
+ if let Some(rect) = rect {
+ let _ = set_view_bounds(page, rect).await;
}
}
@@ -1575,6 +1633,17 @@ pub fn browser_view_action<R: Runtime>(
) -> Result<(), String> {
require_main(&webview)?;
let page = view(webview.app_handle(), &tab_id)?;
+ #[cfg(target_os = "linux")]
+ if matches!(action.as_str(), "back" | "forward" | "stop") {
+ return page.with_webview(move |platform| {
+ use webkit2gtk::WebViewExt;
+ match action.as_str() {
+ "back" => platform.inner().go_back(),
+ "forward" => platform.inner().go_forward(),
+ _ => platform.inner().stop_loading(),
+ }
+ }).map_err(|error| error.to_string());
+ }
let result = match action.as_str() {
"back" => page.eval("history.back()"),
"forward" => page.eval("history.forward()"),
@@ -1927,7 +1996,15 @@ fn apply_mute<R: Runtime>(page: &Webview<R>, muted: bool) -> Result<(), String>
.map_err(|error| error.to_string())
}
-#[cfg(not(any(target_os = "macos", windows)))]
+#[cfg(target_os = "linux")]
+fn apply_mute<R: Runtime>(page: &Webview<R>, muted: bool) -> Result<(), String> {
+ page.with_webview(move |platform| {
+ use webkit2gtk::WebViewExt;
+ platform.inner().set_is_muted(muted);
+ }).map_err(|error| error.to_string())
+}
+
+#[cfg(not(any(target_os = "macos", windows, target_os = "linux")))]
fn apply_mute<R: Runtime>(_page: &Webview<R>, _muted: bool) -> Result<(), String> {
Ok(())
}
@@ -1994,6 +2071,8 @@ pub async fn browser_view_clear_data<R: Runtime>(
.focused(false),
&app,
)?;
+ #[cfg(target_os = "linux")]
+ crate::browser_linux::install(&webview).await?;
let page = webview
.window()
.add_child(
@@ -2018,7 +2097,7 @@ const CLEAR_TIMEOUT: Duration = Duration::from_secs(30);
/// Clear a page's profile, resolving once the engine reports it done: wry's own call starts the
/// clear and returns before it finishes.
async fn clear_profile<R: Runtime>(page: &Webview<R>) -> Result<(), String> {
- #[cfg(any(target_os = "macos", windows))]
+ #[cfg(any(target_os = "macos", windows, target_os = "linux"))]
{
let (done, finished) = tokio::sync::oneshot::channel::<Result<(), String>>();
let done = Mutex::new(Some(done));
@@ -2034,7 +2113,7 @@ async fn clear_profile<R: Runtime>(page: &Webview<R>) -> Result<(), String> {
_ => Err("Clearing browsing data didn't finish".into()),
}
}
- #[cfg(not(any(target_os = "macos", windows)))]
+ #[cfg(not(any(target_os = "macos", windows, target_os = "linux")))]
{
page.clear_all_browsing_data()
.map_err(|error| error.to_string())?;
@@ -2043,7 +2122,7 @@ async fn clear_profile<R: Runtime>(page: &Webview<R>) -> Result<(), String> {
}
}
-#[cfg(any(target_os = "macos", windows))]
+#[cfg(any(target_os = "macos", windows, target_os = "linux"))]
type ClearFinish = std::sync::Arc<dyn Fn(Result<(), String>) + Send + Sync>;
#[cfg(target_os = "macos")]
@@ -2063,6 +2142,20 @@ fn platform_clear(platform: tauri::webview::PlatformWebview, finish: ClearFinish
}
}
+#[cfg(target_os = "linux")]
+fn platform_clear(platform: tauri::webview::PlatformWebview, finish: ClearFinish) {
+ use webkit2gtk::{WebViewExt, WebsiteDataManagerExtManual, WebsiteDataTypes};
+ let Some(manager) = platform.inner().website_data_manager() else {
+ return finish(Err("Browser profile is unavailable".into()));
+ };
+ manager.clear(
+ WebsiteDataTypes::all(),
+ glib::TimeSpan::from_seconds(0),
+ None::<&gtk::gio::Cancellable>,
+ move |result| finish(result.map_err(|error| error.to_string())),
+ );
+}
+
#[cfg(windows)]
fn platform_clear(platform: tauri::webview::PlatformWebview, finish: ClearFinish) {
use webview2_com::ClearBrowsingDataCompletedHandler;
diff --git a/studio/src-tauri/src/main.rs b/studio/src-tauri/src/main.rs
index ab4e1055963..69e978e8ea7 100644
--- a/studio/src-tauri/src/main.rs
+++ b/studio/src-tauri/src/main.rs
@@ -10,6 +10,8 @@ mod browser_downloads;
mod browser_layer;
mod browser_open_with;
mod browser_proxy;
+#[cfg(target_os = "linux")]
+mod browser_linux;
mod browser_webview;
mod commands;
#[cfg(target_os = "linux")]
@@ -2265,7 +2267,12 @@ fn main() {
.manage(native_file_dialogs::NativeSaveRegistry::default())
.manage(browser_webview::new_browser_views())
.manage(browser_downloads::new_browser_downloads())
- .invoke_handler(tauri::generate_handler![
+ .invoke_handler(|invoke| {
+ if invoke.message.webview().label() != "main" || invoke.message.webview().window().label() != "main" {
+ invoke.resolver.reject("Studio commands are only available to the main webview");
+ return true;
+ }
+ let handler: fn(tauri::ipc::Invoke<tauri::Wry>) -> bool = tauri::generate_handler![
app_menu::set_app_menu_actions,
browser_webview::browser_view_supported,
browser_webview::browser_view_show,
@@ -2367,7 +2374,9 @@ fn main() {
get_launch_at_login,
set_launch_at_login,
set_tray_server_status,
- ])
+ ];
+ handler(invoke)
+ })
.setup(|app| {
// Resolve here, before any window path can ask: this consumes the relaunch marker.
let launched_hidden = was_launched_hidden(app.handle().clone());
@@ -2462,6 +2471,11 @@ fn main() {
has_visible_windows: false,
..
} => show_main_window(app),
+ #[cfg(target_os = "linux")]
+ tauri::RunEvent::ExitRequested { .. } => {
+ // window-state only saves windows with one webview; detach browser tabs first.
+ browser_webview::close_all(app);
+ }
tauri::RunEvent::Exit => {
// Safety net for framework-driven exits. When another path already owns
// cleanup, this blocks the main event-loop thread until that path is done.