The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(onboarding): closing a re-run of the wizard returns to the app
purple6df8e297939a
diff --git a/src-tauri/src/onboarding_window.rs b/src-tauri/src/onboarding_window.rsindex dfe93766..29359d1d 100644--- a/src-tauri/src/onboarding_window.rs+++ b/src-tauri/src/onboarding_window.rs@@ -34,6 +34,14 @@//! Onboarding-Fenster zu, Marker fehlt → die App beendet sich. Das//! Onboarding ist nicht fertig; ein unsichtbares//! Hauptfenster wäre eine App ohne Fenster.+//! Dasselbe beim erneuten Durchlauf → kein Beenden. Die App WAR schon+//! eingerichtet, der Nutzer bricht nur ab: der Marker+//! wird wieder geschrieben und die Fenster folgen+//! ihm wie nach einem Abschluss (`follow_marker(true)`).+//! Woran Rust das erkennt: `follow_marker(false)`+//! merkt es sich (`RERUN`), denn nur „Onboarding+//! zurücksetzen" löscht den Marker. Die Erstinstallation+//! kommt nie dort vorbei und beendet weiter.//!//! ── Warum das Hauptfenster trotzdem existiert ─────────────────────────────//!@@ -65,7 +73,7 @@//! Die `#[cfg]`-Zeilen in `open()` sind die einzigen plattformabhängigen//! Zeilen dieses Moduls.-use std::sync::atomic::{AtomicUsize, Ordering};+use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};use std::time::Duration;// Ein Handy baut und zeigt kein Fenster (siehe unten), dort bleibt die Haelfte ungenutzt.@@ -303,8 +311,10 @@ pub fn open(app: &AppHandle) -> tauri::Result<WebviewWindow> {let handle = app.clone();window.on_window_event(move |event| {if let tauri::WindowEvent::CloseRequested { .. } = event {- if !is_onboarding_done() {- quit(&handle);+ match on_close(is_onboarding_done(), RERUN.load(Ordering::SeqCst)) {+ OnClose::Nothing => {}+ OnClose::Quit => quit(&handle),+ OnClose::BackToTheApp => back_to_the_app(&handle),}}});@@ -312,6 +322,51 @@ pub fn open(app: &AppHandle) -> tauri::Result<WebviewWindow> {Ok(window)}+/// Läuft gerade ein freiwilliger erneuter Durchlauf? Gesetzt von+/// `follow_marker(false)` (nur „Onboarding zurücksetzen" löscht den Marker),+/// gelöscht, sobald der Marker wieder steht. Nur im Speicher: ein Neustart+/// mitten im Durchlauf findet den Abschluss im Store-Backup, weil die+/// Einstellungen `onboardingDone` dafür nicht mehr umlegen+/// (`SettingsPage.tsx`), und `decide_first_window` schreibt den Marker nach.+#[cfg_attr(mobile, allow(dead_code))]+static RERUN: AtomicBool = AtomicBool::new(false);++/// Was das Schließen des Onboarding-Fensters auslöst.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum OnClose {+ /// Der Marker steht: das Onboarding ist fertig, nichts zu tun.+ Nothing,+ /// Erstinstallation abgebrochen: die App beendet sich.+ Quit,+ /// Erneuter Durchlauf abgebrochen: zurück in die eingerichtete App.+ BackToTheApp,+}++/// Die reine Regel hinter dem CloseRequested-Handler.+pub fn on_close(marker: bool, rerun: bool) -> OnClose {+ match (marker, rerun) {+ (true, _) => OnClose::Nothing,+ (false, false) => OnClose::Quit,+ (false, true) => OnClose::BackToTheApp,+ }+}++/// Der erneute Durchlauf wurde abgebrochen: Marker zurück, und die Fenster+/// folgen ihm wie nach einem Abschluss. Das wartende Hauptfenster bootet auf+/// `DONE_EVENT` und zeigt sich. Scheitert das Schreiben, bleibt nur der+/// alte Weg, sonst stünde ein unsichtbares Hauptfenster ohne Gegenüber da.+#[cfg(desktop)]+fn back_to_the_app(app: &AppHandle) {+ tracing::info!("re-run of the onboarding closed, back to the set-up app");+ match write_onboarding_marker(true) {+ Ok(()) => follow_marker(app, true),+ Err(e) => {+ tracing::error!("onboarding marker could not be restored: {e}");+ quit(app);+ }+ }+}+/// Das Onboarding-Fenster wurde geschlossen, bevor das Onboarding fertig war:/// derselbe Weg wie „Quit" im Tray, damit kein Kindprozess zurückbleibt.#[cfg(desktop)]@@ -371,6 +426,7 @@ pub fn onboarding_window_open(app: AppHandle) -> bool {#[cfg(desktop)]pub fn follow_marker(app: &AppHandle, done: bool) {let onboarding = app.get_webview_window(ONBOARDING);+ RERUN.store(!done, Ordering::SeqCst);if done {if onboarding.is_none() {// Die Migration aus `AppShell.tsx` (Marker nachschreiben) oder ein@@ -540,6 +596,34 @@ mod tests {// ── Die Regel hinter show_window ──────────────────────────────────────+ // ── Schließen des Onboarding-Fensters ─────────────────────────────────++ #[test]+ fn erstinstallation_abgebrochen_beendet_die_app() {+ assert_eq!(on_close(false, false), OnClose::Quit);+ }++ #[test]+ fn erneuter_durchlauf_abgebrochen_fuehrt_zurueck_in_die_app() {+ assert_eq!(on_close(false, true), OnClose::BackToTheApp);+ }++ #[test]+ fn fertiges_onboarding_schliesst_ohne_folgen() {+ assert_eq!(on_close(true, false), OnClose::Nothing);+ assert_eq!(on_close(true, true), OnClose::Nothing);+ }++ #[test]+ fn nur_das_zuruecksetzen_merkt_sich_den_erneuten_durchlauf() {+ let src = include_str!("onboarding_window.rs");+ let follow = &src[src.find("pub fn follow_marker(app: &AppHandle, done: bool)").unwrap()..];+ let body = &follow[..follow.find("\n}\n").unwrap()];+ assert!(body.contains("RERUN.store(!done"), "follow_marker must record the re-run");+ let handler = &src[src.find("window.on_window_event").unwrap()..];+ assert!(handler[..400].contains("on_close(is_onboarding_done(), RERUN.load"));+ }+#[test]fn das_onboarding_fenster_darf_sich_immer_zeigen() {assert_eq!(reveal_decision(ONBOARDING, false, true), Reveal::Show);diff --git a/src/components/onboarding/__tests__/onboarding-fenster.test.ts b/src/components/onboarding/__tests__/onboarding-fenster.test.tsindex d3ba1205..38b9603d 100644--- a/src/components/onboarding/__tests__/onboarding-fenster.test.ts+++ b/src/components/onboarding/__tests__/onboarding-fenster.test.ts@@ -215,7 +215,8 @@ describe('die Größe ist gemessen, nicht geraten', () => {describe('„Re-run onboarding" bringt das kleine Fenster zurück — über den Marker', () => {it('die Einstellungen löschen den Marker, und die Fenster folgen ihm', () => {- const settings = codeOnly(read('src', 'components', 'settings', 'SettingsPage.tsx'))+ expect(codeOnly(read('src', 'components', 'settings', 'SettingsPage.tsx'))).toContain('rerunOnboarding()')+ const settings = codeOnly(read('src', 'lib', 'onboarding-rerun.ts'))expect(settings).toContain("await backendCall('set_onboarding_done', { done: false })")const system = read('src-tauri', 'src', 'commands', 'system.rs')expect(system).toContain('crate::onboarding_window::follow_marker(&app, done);')@@ -241,11 +242,14 @@ describe('das Fenster selbst', () => {expect(open).toContain('WebviewUrl::default()')})- it('zu heißt Ende, solange das Onboarding nicht fertig ist', () => {+ it('zu heißt Ende, solange die erste Einrichtung nicht fertig ist', () => {const open = RUST.slice(RUST.indexOf('pub fn open('), RUST.indexOf('fn quit('))expect(open).toContain('tauri::WindowEvent::CloseRequested')- expect(open).toContain('if !is_onboarding_done()')- expect(open).toContain('quit(&handle)')+ expect(open).toContain('on_close(is_onboarding_done(), RERUN.load(Ordering::SeqCst))')+ expect(open).toContain('OnClose::Quit => quit(&handle)')+ // B6: ein abgebrochener erneuter Durchlauf fuehrt zurueck in die App.+ expect(open).toContain('(false, false) => OnClose::Quit')+ expect(open).toContain('OnClose::BackToTheApp => back_to_the_app(&handle)')const quit = RUST.slice(RUST.indexOf('fn quit('), RUST.indexOf('#[tauri::command]'))expect(quit).toContain('shutdown_subprocesses()')expect(quit).toContain('app.exit(0)')diff --git a/src/lib/__tests__/a-re-run-of-the-onboarding-can-be-left.test.ts b/src/lib/__tests__/a-re-run-of-the-onboarding-can-be-left.test.tsnew file mode 100644index 00000000..f07c9003--- /dev/null+++ b/src/lib/__tests__/a-re-run-of-the-onboarding-can-be-left.test.ts@@ -0,0 +1,78 @@+/**+ * Jaeger B, B6: Settings, General, Onboarding, "Re-run onboarding", then+ * closing the wizard window quit LU ("onboarding window closed before setup+ * finished") and every later start forced the wizard with no way back. The+ * button flipped settings.onboardingDone to false in the persisted store, so+ * the store backup said "not set up" as well and nothing could tell the+ * abandoned re-run from a first install.+ *+ * Expected: with the wizard in its own window the store keeps+ * onboardingDone: true (Rust restores the marker when that window closes,+ * see `on_close` in onboarding_window.rs); only without that window does the+ * store flip, so the main window draws the wizard itself as before.+ *+ * Run: npx vitest run src/lib/__tests__/a-re-run-of-the-onboarding-can-be-left.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'++const backend = vi.hoisted(() => ({ backendCall: vi.fn() }))+vi.mock('../../api/backend', async () => {+ const actual = await vi.importActual<typeof import('../../api/backend')>('../../api/backend')+ return { ...actual, backendCall: backend.backendCall }+})++import { rerunOnboarding } from '../onboarding-rerun'+import { useSettingsStore } from '../../stores/settingsStore'++const calls: string[] = []+function rust(ownWindow: boolean | Error) {+ backend.backendCall.mockImplementation(async (cmd: string) => {+ calls.push(cmd)+ if (cmd === 'onboarding_window_open') {+ if (ownWindow instanceof Error) throw ownWindow+ return ownWindow+ }+ return undefined+ })+}++beforeEach(() => {+ calls.length = 0+ backend.backendCall.mockReset()+ useSettingsStore.getState().updateSettings({ onboardingDone: true })+})++describe('Re-run onboarding', () => {+ it('with its own window the store stays set up, so closing the wizard can lead back', async () => {+ rust(true)+ const reload = vi.fn()+ await rerunOnboarding(reload)+ expect(calls).toEqual(['set_onboarding_done', 'onboarding_window_open'])+ expect(backend.backendCall).toHaveBeenCalledWith('set_onboarding_done', { done: false })+ expect(useSettingsStore.getState().settings.onboardingDone).toBe(true)+ expect(reload).toHaveBeenCalledTimes(1)+ })++ it('without its own window the main window draws the wizard, as before', async () => {+ rust(false)+ const reload = vi.fn()+ await rerunOnboarding(reload)+ expect(useSettingsStore.getState().settings.onboardingDone).toBe(false)+ expect(reload).toHaveBeenCalledTimes(1)+ })++ it('a Rust that does not answer counts as no window', async () => {+ rust(new Error('no tauri'))+ await rerunOnboarding(vi.fn())+ expect(useSettingsStore.getState().settings.onboardingDone).toBe(false)+ })++ it('Rust tells a closed re-run from an abandoned first install', () => {+ const rs = readFileSync(resolve(__dirname, '../../../src-tauri/src/onboarding_window.rs'), 'utf8')+ const rule = rs.slice(rs.indexOf('pub fn on_close('), rs.indexOf('fn back_to_the_app('))+ expect(rule).toContain('(false, false) => OnClose::Quit')+ expect(rule).toContain('(false, true) => OnClose::BackToTheApp')+ })+})diff --git a/src/lib/onboarding-rerun.ts b/src/lib/onboarding-rerun.tsnew file mode 100644index 00000000..352f1225--- /dev/null+++ b/src/lib/onboarding-rerun.ts@@ -0,0 +1,30 @@+/**+ * Settings, General, Onboarding, "Re-run onboarding".+ *+ * The backend call clears the marker FILE, and the windows follow it: Rust+ * opens the wizard in its own small window and the main window waits hidden+ * until the marker is back (onboarding_window.rs). Without that window the+ * store flip below is what re-runs the wizard: AppShell gates it on+ * settings.onboardingDone, and that store is persisted, so it survives the+ * reload.+ *+ * Jaeger B, B6: the store used to flip in every case. Closing the wizard then+ * quit LU, and every later start forced the wizard again, because the store+ * backup said "not set up" too. Now, when the wizard has its own window, the+ * store stays onboardingDone: true. The wizard there does not read it; Rust+ * restores the marker when that window is closed during a re-run (`on_close`)+ * and the main window comes back, and a restart in the middle finds the+ * finished setup in the store backup (`decide_first_window`).+ *+ * Level (a): silent on purpose. The visible action succeeds either way, and+ * the reload wipes any message before it could be read.+ */+import { backendCall } from '../api/backend'+import { useSettingsStore } from '../stores/settingsStore'++export async function rerunOnboarding(reload: () => void = () => window.location.reload()): Promise<void> {+ try { await backendCall('set_onboarding_done', { done: false }) } catch { /* see above */ }+ const ownWindow = await backendCall<boolean>('onboarding_window_open').catch(() => false)+ if (ownWindow !== true) useSettingsStore.getState().updateSettings({ onboardingDone: false })+ reload()+}