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.

Prevent setup-size flash during desktop startup (#11910)

Wasim Yousef Saidec67ce389e11
diff --git a/studio/frontend/src/app/provider.tsx b/studio/frontend/src/app/provider.tsx
index 94d76803e14..eb9b1d18c2e 100644
--- a/studio/frontend/src/app/provider.tsx
+++ b/studio/frontend/src/app/provider.tsx
@@ -19,6 +19,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
import { WebUpdateBanner } from "@/components/web/update-banner";
import { fetchDeviceType } from "@/config/env";
import { getTauriAuthFailure, tauriAutoAuth } from "@/features/auth";
+import { resyncInferenceStatusAfterServerModelChange } from "@/features/chat";
import { DeepLinkHandler } from "@/features/deep-links";
import {
DownloadManagerPanel,
@@ -42,10 +43,9 @@ import { TauriRepairContext } from "@/hooks/tauri-repair-context";
import { TauriUpdateContext } from "@/hooks/tauri-update-context";
import { type BackendStatus, useTauriBackend } from "@/hooks/use-tauri-backend";
import { useTauriUpdate } from "@/hooks/use-tauri-update";
+import { useUiSpaceScale } from "@/hooks/use-ui-space-scale";
import { isTauri } from "@/lib/api-base";
import { followDesktopUpdateScreen } from "@/lib/desktop-update-activity";
-import { resyncInferenceStatusAfterServerModelChange } from "@/features/chat";
-import { useUiSpaceScale } from "@/hooks/use-ui-space-scale";
import { getToastOffsets } from "@/lib/toast-offset";
import { Z_LAYER } from "@/lib/z-layers";
import { useRouterState } from "@tanstack/react-router";
@@ -75,6 +75,7 @@ import {
finalizeAppWindowLayout,
measureWindowLayout,
observeDevicePixelRatio,
+ prepareSetupWindow,
shouldFinishWindowLayoutWait,
} from "./window-layout-lifecycle";
@@ -156,8 +157,9 @@ async function observeWindowLayout(
return {
waitForSettled: async () => {
- let observedRevision = revision;
- let sawPostShowChange = false;
+ // Include restore events that arrived before this wait started.
+ let observedRevision = 0;
+ let sawNativeChange = revision > 0;
for (
let elapsed = 0;
elapsed < WINDOW_LAYOUT_TIMEOUT_MS && isCurrent();
@@ -166,10 +168,10 @@ async function observeWindowLayout(
await delay(WINDOW_LAYOUT_POLL_MS);
if (revision !== observedRevision) {
observedRevision = revision;
- sawPostShowChange = true;
+ sawNativeChange = true;
continue;
}
- if (shouldFinishWindowLayoutWait(sawPostShowChange)) {
+ if (shouldFinishWindowLayoutWait(sawNativeChange)) {
return;
}
}
@@ -268,20 +270,32 @@ async function showSetupWindow(isCurrent: WindowLayoutGuard): Promise<void> {
if (!isCurrent()) return;
const win = windowModule.getCurrentWindow();
- await invoke("reset_app_window_layout_initialized");
- if (!isCurrent()) return;
- await win.setSizeConstraints(null);
- if (!isCurrent()) return;
- await win.setResizable(false);
- if (!isCurrent()) return;
- const measured = await measureTauriWindowLayout(windowModule, win, isCurrent);
- if (!measured) return;
- const setupSize = fitWindowSize(
- PREFERRED_SETUP_WINDOW_SIZE,
- measured.bounds.maximum,
- );
- await placeWindow(win, windowModule, measured, setupSize, isCurrent);
- if (!isCurrent()) return;
+ if (
+ !(await prepareSetupWindow({
+ resetLayout: () => invoke("reset_app_window_layout_initialized"),
+ unmaximize: () => win.unmaximize(),
+ clearConstraints: () => win.setSizeConstraints(null),
+ enableResize: () => win.setResizable(true),
+ resizeForSetup: async () => {
+ const measured = await measureTauriWindowLayout(
+ windowModule,
+ win,
+ isCurrent,
+ );
+ if (!measured) return false;
+ const setupSize = fitWindowSize(
+ PREFERRED_SETUP_WINDOW_SIZE,
+ measured.bounds.maximum,
+ );
+ await placeWindow(win, windowModule, measured, setupSize, isCurrent);
+ return isCurrent();
+ },
+ disableResize: () => win.setResizable(false),
+ isCurrent,
+ }))
+ ) {
+ return;
+ }
if (await wasLaunchedHidden()) return;
if (!isCurrent()) return;
await win.show();
@@ -339,17 +353,22 @@ async function applyAppWindowLayout(
let requestedSize: LogicalWindowSize | undefined;
let restored = false;
+ let nativeRestored = false;
let layoutObserver: WindowLayoutObserver | null = null;
try {
if (hasInitializedAppLayout && hasSavedState) {
restored = true;
+ nativeRestored = await invoke<boolean>("take_native_layout_restored");
+ if (!isCurrent()) return;
// Subscribe before restoring so native events cannot race listener setup.
layoutObserver = await observeWindowLayout(win, isCurrent);
if (!layoutObserver) return;
- await restoreStateCurrent(
- StateFlags.SIZE | StateFlags.POSITION | StateFlags.MAXIMIZED,
- );
- if (!isCurrent()) return;
+ if (!nativeRestored) {
+ await restoreStateCurrent(
+ StateFlags.SIZE | StateFlags.POSITION | StateFlags.MAXIMIZED,
+ );
+ if (!isCurrent()) return;
+ }
} else {
const cssSafeLogicalWidth = measured.monitor
? Math.round(
@@ -364,16 +383,21 @@ async function applyAppWindowLayout(
await placeWindow(win, windowModule, measured, requestedSize, isCurrent);
}
// Apply work-area constraints after restore to preserve the saved size.
+ const hiddenAtLaunch = await wasLaunchedHidden();
+ if (!isCurrent()) return;
await finalizeAppWindowLayout({
restored,
+ nativeRestored,
measured,
show: async () => {
- if (await wasLaunchedHidden()) return false;
+ if (hiddenAtLaunch) return false;
if (!isCurrent()) return false;
await win.show();
return true;
},
- waitForSettled: layoutObserver?.waitForSettled,
+ waitForSettled: hiddenAtLaunch
+ ? undefined
+ : layoutObserver?.waitForSettled,
measure: () => measureTauriWindowLayout(windowModule, win, isCurrent),
setMinimumConstraints: (minimum) =>
win.setSizeConstraints({
@@ -883,7 +907,10 @@ function TauriWrapper({ children }: { children: ReactNode }) {
</>
}
>
- <LlamaUpdateBanner positioned={false} enabled={!hidesTitlebarSidebar} />
+ <LlamaUpdateBanner
+ positioned={false}
+ enabled={!hidesTitlebarSidebar}
+ />
<DownloadManagerPanel positioned={false} />
<LoadedModelsIndicator positioned={false} />
</TauriUpdateLayer>
diff --git a/studio/frontend/src/app/window-layout-lifecycle.ts b/studio/frontend/src/app/window-layout-lifecycle.ts
index 4f4ef086184..173b51dc4e2 100644
--- a/studio/frontend/src/app/window-layout-lifecycle.ts
+++ b/studio/frontend/src/app/window-layout-lifecycle.ts
@@ -10,6 +10,38 @@ import {
export type WindowLayoutGuard = () => boolean;
+export async function prepareSetupWindow(options: {
+ resetLayout: () => Promise<unknown>;
+ unmaximize: () => Promise<void>;
+ clearConstraints: () => Promise<void>;
+ enableResize: () => Promise<void>;
+ resizeForSetup: () => Promise<boolean>;
+ disableResize: () => Promise<void>;
+ isCurrent: WindowLayoutGuard;
+}): Promise<boolean> {
+ const {
+ resetLayout,
+ unmaximize,
+ clearConstraints,
+ enableResize,
+ resizeForSetup,
+ disableResize,
+ isCurrent,
+ } = options;
+ await resetLayout();
+ if (!isCurrent()) return false;
+ await unmaximize();
+ if (!isCurrent()) return false;
+ await clearConstraints();
+ if (!isCurrent()) return false;
+ // GTK can ignore a size change on a non-resizable restored window.
+ await enableResize();
+ if (!isCurrent()) return false;
+ if (!(await resizeForSetup()) || !isCurrent()) return false;
+ await disableResize();
+ return isCurrent();
+}
+
type WorkAreaMonitor = {
scaleFactor: number;
workArea: {
@@ -91,9 +123,9 @@ export async function measureWindowLayout<Monitor extends WorkAreaMonitor>(
}
export function shouldFinishWindowLayoutWait(
- sawPostShowChange: boolean,
+ sawNativeChange: boolean,
): boolean {
- return sawPostShowChange;
+ return sawNativeChange;
}
type ResolutionQuery = {
@@ -136,6 +168,8 @@ export function observeDevicePixelRatio(
}
type FinalizeAppWindowLayoutOptions<Monitor extends WorkAreaMonitor> = {
restored: boolean;
+ /** Geometry was restored natively while hidden; settle after the reveal instead. */
+ nativeRestored?: boolean;
measured: MeasuredWindowLayout<Monitor>;
show: () => Promise<boolean>;
waitForSettled?: () => Promise<void>;
@@ -145,9 +179,10 @@ type FinalizeAppWindowLayoutOptions<Monitor extends WorkAreaMonitor> = {
isCurrent: WindowLayoutGuard;
};
-/** Shows the app window, then applies bounds from the visible monitor. */
+/** Reveals the settled app window, then applies bounds from the visible monitor. */
export async function finalizeAppWindowLayout<Monitor extends WorkAreaMonitor>({
restored,
+ nativeRestored = false,
measured,
show,
waitForSettled,
@@ -157,16 +192,20 @@ export async function finalizeAppWindowLayout<Monitor extends WorkAreaMonitor>({
isCurrent,
}: FinalizeAppWindowLayoutOptions<Monitor>): Promise<void> {
if (!isCurrent()) return;
+ // restoreState returns before native resize lands; showing now flashes the setup size.
+ if (restored && !nativeRestored) {
+ await waitForSettled?.();
+ if (!isCurrent()) return;
+ }
const shown = await show();
if (!isCurrent()) return;
// A restored hidden autostart cannot reliably resolve its saved monitor yet.
// Keep the plugin-restored geometry untouched until native tray reveal.
if (restored && !shown) return;
-
- // Native restore calls complete before GTK/Cocoa move and resize events have
- // necessarily updated Tauri's cached geometry.
+ // Showing can change the resolved monitor (e.g. a compact secondary).
if (restored) {
- await waitForSettled?.();
+ // A hidden GTK window only refreshes its cached size once mapped.
+ if (nativeRestored) await waitForSettled?.();
if (!isCurrent()) return;
measured = (await measure()) ?? measured;
if (!isCurrent()) return;
diff --git a/studio/frontend/tests/window-layout.test.ts b/studio/frontend/tests/window-layout.test.ts
index b5b504375f8..1f39f98e301 100644
--- a/studio/frontend/tests/window-layout.test.ts
+++ b/studio/frontend/tests/window-layout.test.ts
@@ -4,6 +4,13 @@
import assert from "node:assert/strict";
import test from "node:test";
+import {
+ finalizeAppWindowLayout,
+ measureWindowLayout,
+ observeDevicePixelRatio,
+ prepareSetupWindow,
+ shouldFinishWindowLayoutWait,
+} from "../src/app/window-layout-lifecycle.ts";
import {
DEFAULT_APP_WINDOW_SIZE_BOUNDS,
MINIMUM_APP_WINDOW_SIZE,
@@ -14,12 +21,6 @@ import {
constrainWindowSize,
fitWindowSize,
} from "../src/app/window-layout.ts";
-import {
- finalizeAppWindowLayout,
- shouldFinishWindowLayoutWait,
- measureWindowLayout,
- observeDevicePixelRatio,
-} from "../src/app/window-layout-lifecycle.ts";
// A work area is the panel minus the taskbar, in logical pixels.
function workArea(
@@ -34,6 +35,50 @@ function workArea(
};
}
+test("repair setup unmaximizes before sizing or locking the window", async () => {
+ const events: string[] = [];
+ const done = Promise.resolve();
+ let maximized = true;
+ const completed = await prepareSetupWindow({
+ resetLayout: () => {
+ events.push("reset");
+ return done;
+ },
+ unmaximize: () => {
+ maximized = false;
+ events.push("unmaximize");
+ return done;
+ },
+ clearConstraints: () => {
+ events.push("clear");
+ return done;
+ },
+ enableResize: () => {
+ events.push("unlocked");
+ return done;
+ },
+ resizeForSetup: () => {
+ events.push("sized");
+ return Promise.resolve(true);
+ },
+ disableResize: () => {
+ events.push("fixed");
+ return done;
+ },
+ isCurrent: () => true,
+ });
+ assert.equal(completed, true);
+ assert.equal(maximized, false);
+ assert.deepEqual(events, [
+ "reset",
+ "unmaximize",
+ "clear",
+ "unlocked",
+ "sized",
+ "fixed",
+ ]);
+});
+
test("waits for the first native restore event before settling", () => {
assert.equal(shouldFinishWindowLayoutWait(false), false);
assert.equal(shouldFinishWindowLayoutWait(true), true);
@@ -389,7 +434,7 @@ test("remeasures a restored window after show on its compact secondary", async (
assert.deepEqual(savedSize, { width: 900, height: 556 });
});
-test("waits for restored geometry before enforcing its minimum", async () => {
+test("restored geometry settles before the window becomes visible", async () => {
const events: string[] = [];
let currentSize = { width: 760, height: 560 };
const measured = {
@@ -406,6 +451,7 @@ test("waits for restored geometry before enforcing its minimum", async () => {
measured,
show: async () => {
events.push("show");
+ assert.deepEqual(currentSize, { width: 1200, height: 800 });
return true;
},
waitForSettled: async () => {
@@ -427,8 +473,8 @@ test("waits for restored geometry before enforcing its minimum", async () => {
});
assert.deepEqual(events, [
- "show",
"settled",
+ "show",
"measure",
"constraints",
"enforce",
@@ -436,7 +482,7 @@ test("waits for restored geometry before enforcing its minimum", async () => {
assert.deepEqual(currentSize, { width: 1200, height: 800 });
});
-test("preserves restored geometry while an autostart window stays hidden", async () => {
+test("a natively restored window is shown without waiting, then settles", async () => {
const events: string[] = [];
const measured = {
bounds: {
@@ -449,10 +495,11 @@ test("preserves restored geometry while an autostart window stays hidden", async
await finalizeAppWindowLayout({
restored: true,
+ nativeRestored: true,
measured,
show: async () => {
events.push("show");
- return false;
+ return true;
},
waitForSettled: async () => {
events.push("settled");
@@ -470,6 +517,46 @@ test("preserves restored geometry while an autostart window stays hidden", async
isCurrent: () => true,
});
+ assert.deepEqual(events, [
+ "show",
+ "settled",
+ "measure",
+ "constraints",
+ "enforce",
+ ]);
+});
+
+test("preserves restored geometry while an autostart window stays hidden", async () => {
+ const events: string[] = [];
+ const measured = {
+ bounds: {
+ minimum: { width: 900, height: 600 },
+ maximum: { width: 1920, height: 1040 },
+ },
+ monitor: null,
+ frameSize: { width: 0, height: 0 },
+ };
+
+ await finalizeAppWindowLayout({
+ restored: true,
+ measured,
+ show: async () => {
+ events.push("show");
+ return false;
+ },
+ measure: async () => {
+ events.push("measure");
+ return measured;
+ },
+ setMinimumConstraints: async () => {
+ events.push("constraints");
+ },
+ enforceBounds: async () => {
+ events.push("enforce");
+ },
+ isCurrent: () => true,
+ });
+
assert.deepEqual(events, ["show"]);
});
test("stale layouts do not show the window", async () => {
diff --git a/studio/src-tauri/src/app_layout.rs b/studio/src-tauri/src/app_layout.rs
index 9b9277b48dc..ee97a2d39e5 100644
--- a/studio/src-tauri/src/app_layout.rs
+++ b/studio/src-tauri/src/app_layout.rs
@@ -1,5 +1,6 @@
use std::fs;
use std::path::{Path, PathBuf};
+use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{Manager, WebviewWindow};
use tauri_plugin_window_state::AppHandleExt;
@@ -109,6 +110,23 @@ fn should_restore_saved_layout(config_dir: &Path, state_file_name: &str) -> bool
is_initialized(config_dir) || !is_setup_window_size(width, height)
}
+/// Checked before the main window exists, so setup-size resize events cannot overwrite the saved state.
+/// An attached external server may run without a managed launcher; setup will resize on demand.
+pub(crate) fn should_restore_initial_window_state(
+ config_dir: &Path,
+ state_file_name: &str,
+) -> bool {
+ should_restore_saved_layout(config_dir, state_file_name)
+}
+
+pub(crate) struct NativeLayoutRestored(pub(crate) AtomicBool);
+
+/// Read once: a natively restored window has no pending events to wait for before show.
+#[tauri::command]
+pub fn take_native_layout_restored(state: tauri::State<'_, NativeLayoutRestored>) -> bool {
+ state.0.swap(false, Ordering::SeqCst)
+}
+
fn mark_initialized(config_dir: &Path) -> Result<(), String> {
write_marker(config_dir, INITIALIZED_MARKER)
}
@@ -148,9 +166,23 @@ pub fn mark_app_window_layout_initialized(
pub fn reset_app_window_layout_initialized(
window: WebviewWindow,
app: tauri::AppHandle,
+ native_restored: tauri::State<'_, NativeLayoutRestored>,
) -> Result<(), String> {
crate::native_intents::ensure_main_window(&window)?;
- reset_initialized(&app_config_dir(&app)?)
+ reset_initialized(&app_config_dir(&app)?)?;
+ native_restored.0.store(false, Ordering::SeqCst);
+ // Native restore may have maximized it; compact before setup can be revealed.
+ window.unmaximize().map_err(|error| error.to_string())?;
+ window
+ .set_resizable(true)
+ .map_err(|error| error.to_string())?;
+ window
+ .set_size(tauri::LogicalSize::new(
+ SETUP_WINDOW_WIDTH,
+ SETUP_WINDOW_HEIGHT,
+ ))
+ .map_err(|error| error.to_string())?;
+ window.center().map_err(|error| error.to_string())
}
#[cfg(test)]
@@ -256,6 +288,26 @@ mod tests {
let _ = fs::remove_dir_all(dir);
}
+ #[test]
+ fn native_startup_restores_saved_full_app_layouts_without_managed_backend() {
+ let dir = temp_dir("native-startup");
+ fs::create_dir_all(&dir).unwrap();
+ let state_file = ".window-state.json";
+ let state_path = dir.join(state_file);
+ assert!(!should_restore_initial_window_state(&dir, state_file));
+ fs::write(&state_path, window_state(1200, 800, false)).unwrap();
+ assert!(should_restore_initial_window_state(&dir, state_file));
+ reset_initialized(&dir).unwrap();
+ assert!(!should_restore_initial_window_state(&dir, state_file));
+ mark_initialized(&dir).unwrap();
+ assert!(should_restore_initial_window_state(&dir, state_file));
+ fs::write(&state_path, window_state(760, 560, false)).unwrap();
+ assert!(should_restore_initial_window_state(&dir, state_file));
+ reset_initialized(&dir).unwrap();
+ assert!(!should_restore_initial_window_state(&dir, state_file));
+ let _ = fs::remove_dir_all(dir);
+ }
+
#[test]
fn corrupt_plugin_state_does_not_restore_even_with_initialized_marker() {
let dir = temp_dir("plugin-state");
diff --git a/studio/src-tauri/src/main.rs b/studio/src-tauri/src/main.rs
index 7e8f06086ad..1b510357d8d 100644
--- a/studio/src-tauri/src/main.rs
+++ b/studio/src-tauri/src/main.rs
@@ -2095,6 +2095,19 @@ fn main() {
let mut context = tauri::generate_context!();
extend_csp_with_hf_endpoints(&mut context);
+ // Restore while hidden, else the 760x560 setup size overwrites the saved layout.
+ let restore_initial_layout = dirs::config_dir().is_some_and(|dir| {
+ app_layout::should_restore_initial_window_state(
+ &dir.join(&context.config().identifier),
+ tauri_plugin_window_state::DEFAULT_FILENAME,
+ )
+ });
+ info!("Native saved app layout restore enabled: {restore_initial_layout}");
+ let mut window_state = tauri_plugin_window_state::Builder::new()
+ .with_state_flags(StateFlags::SIZE | StateFlags::POSITION | StateFlags::MAXIMIZED);
+ if !restore_initial_layout {
+ window_state = window_state.skip_initial_state("main");
+ }
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
@@ -2112,12 +2125,10 @@ fn main() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_clipboard_manager::init())
- .plugin(
- tauri_plugin_window_state::Builder::new()
- .with_state_flags(StateFlags::SIZE | StateFlags::POSITION | StateFlags::MAXIMIZED)
- .skip_initial_state("main")
- .build(),
- )
+ .plugin(window_state.build())
+ .manage(app_layout::NativeLayoutRestored(
+ std::sync::atomic::AtomicBool::new(restore_initial_layout),
+ ))
.manage(diagnostics::new_diagnostics_state())
.manage(install::new_install_state())
.manage(new_training_activity_state())
@@ -2136,6 +2147,7 @@ fn main() {
app_layout::has_initialized_app_window_layout,
app_layout::mark_app_window_layout_initialized,
app_layout::reset_app_window_layout_initialized,
+ app_layout::take_native_layout_restored,
commands::check_install_status,
commands::desktop_preflight,
commands::start_install,