Skip to content

Commit 43bc936

Browse files
authored
Fix desktop onboarding reset scoping (#5604)
1 parent 54580bf commit 43bc936

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

desktop/Desktop/Sources/AppState.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,12 @@ class AppState: ObservableObject {
24662466
nonisolated func resetOnboardingAndRestart() {
24672467
log("Resetting onboarding state for current app...")
24682468

2469+
// Update live @AppStorage state in the current app instance before touching
2470+
// raw UserDefaults so SwiftUI doesn't write stale onboarding values back.
2471+
DispatchQueue.main.async {
2472+
NotificationCenter.default.post(name: .resetOnboardingRequested, object: nil)
2473+
}
2474+
24692475
// Clear onboarding-related UserDefaults keys (thread-safe, do first)
24702476
let onboardingKeys = [
24712477
"hasCompletedOnboarding",
@@ -2503,6 +2509,7 @@ class AppState: ObservableObject {
25032509

25042510
// Restart off the main thread to avoid blocking the menu action path.
25052511
DispatchQueue.global(qos: .utility).async { [self] in
2512+
Thread.sleep(forTimeInterval: 0.15)
25062513
// Keep onboarding reset scoped to the current app instance.
25072514
// It must not mutate production defaults, shared local data, or TCC permissions.
25082515
self.restartApp()
@@ -2773,6 +2780,8 @@ class AppState: ObservableObject {
27732780
// MARK: - System Event Notification Names
27742781

27752782
extension Notification.Name {
2783+
/// Posted when the current app instance should fully clear its own onboarding state.
2784+
static let resetOnboardingRequested = Notification.Name("resetOnboardingRequested")
27762785
/// Posted when the system wakes from sleep
27772786
static let systemDidWake = Notification.Name("systemDidWake")
27782787
/// Posted when the screen is locked

desktop/Desktop/Sources/MainWindow/DesktopHomeView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct DesktopHomeView: View {
2222
}()
2323
@State private var isSidebarCollapsed: Bool = false
2424
@AppStorage("currentTierLevel") private var currentTierLevel = 0
25+
@AppStorage("onboardingStep") private var onboardingStep = 0
26+
@AppStorage("onboardingJustCompleted") private var onboardingJustCompleted = false
2527

2628
// Settings sidebar state
2729
@State private var selectedSettingsSection: SettingsContentView.SettingsSection = .general
@@ -201,6 +203,13 @@ struct DesktopHomeView: View {
201203
appState.hasCompletedOnboarding = false
202204
appState.stopTranscription()
203205
}
206+
.onReceive(NotificationCenter.default.publisher(for: .resetOnboardingRequested)) { _ in
207+
log("DesktopHomeView: resetOnboardingRequested — clearing live onboarding state for current app")
208+
appState.hasCompletedOnboarding = false
209+
onboardingStep = 0
210+
onboardingJustCompleted = false
211+
appState.stopTranscription()
212+
}
204213
// Handle transcription toggle from menu bar
205214
.onReceive(NotificationCenter.default.publisher(for: .toggleTranscriptionRequested)) { notification in
206215
if let enabled = notification.userInfo?["enabled"] as? Bool {

desktop/Desktop/Sources/MainWindow/Pages/SettingsPage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,7 +3801,7 @@ struct SettingsContentView: View {
38013801
.scaledFont(size: 16, weight: .semibold)
38023802
.foregroundColor(OmiColors.textPrimary)
38033803

3804-
Text("Restart setup wizard and reset permissions")
3804+
Text("Restart setup wizard for this app build only")
38053805
.scaledFont(size: 13)
38063806
.foregroundColor(OmiColors.textTertiary)
38073807
}
@@ -3828,7 +3828,7 @@ struct SettingsContentView: View {
38283828
appState.resetOnboardingAndRestart()
38293829
}
38303830
} message: {
3831-
Text("This will reset all permissions, clear chat history, and restart the app. You'll need to grant permissions again during setup.")
3831+
Text("This will reset onboarding for this app build only, clear onboarding chat history, and restart the app without affecting the other installed build.")
38323832
}
38333833
}
38343834
}

desktop/Desktop/Sources/OnboardingView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ struct OnboardingView: View {
6363
// Pre-warm the ACP bridge before the chat step starts.
6464
await chatProvider.warmupBridge()
6565
}
66+
.onReceive(NotificationCenter.default.publisher(for: .resetOnboardingRequested)) { _ in
67+
log("OnboardingView: resetOnboardingRequested — returning to chat step for current app")
68+
currentStep = 0
69+
}
6670
}
6771

6872
private var onboardingContent: some View {

0 commit comments

Comments
 (0)