From cd822e1efce2c14dbb9048d7f6bdce6d52c74ee2 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 28 Aug 2025 20:34:31 +0100 Subject: [PATCH] reimplemented onboarding via hostsManager.shownOnboarding --- ShhShell/Host/HostsManager.swift | 7 ++++++ ShhShell/ShhShellApp.swift | 26 ++++++++++++--------- ShhShell/Views/Onboarding/WelcomeView.swift | 13 +++++------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 1399eb5..274029b 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -26,6 +26,7 @@ class HostsManager: ObservableObject, @unchecked Sendable { @Published var history: [History] = [] @Published var settings: AppSettings = AppSettings() + @Published var shownOnboarding: Bool = false var tint: SwiftUI.Color { selectedTheme.ansi[selectedAnsi].suiColor @@ -46,6 +47,12 @@ class HostsManager: ObservableObject, @unchecked Sendable { loadFonts() loadSnippets() loadHistory() +// self.shownOnboarding = UserDefaults.standard.bool(forKey: "shownOnboarding") + } + + func setOnboarding(to newValue: Bool) { + self.shownOnboarding = newValue + UserDefaults.standard.set(newValue, forKey: "shownOnboarding") } func setAppIcon() { diff --git a/ShhShell/ShhShellApp.swift b/ShhShell/ShhShellApp.swift index 89ad0a5..62033d0 100644 --- a/ShhShell/ShhShellApp.swift +++ b/ShhShell/ShhShellApp.swift @@ -22,18 +22,22 @@ struct ShhShellApp: App { var body: some Scene { WindowGroup { - if !NSUbiquitousKeyValueStore.default.bool(forKey: "shownOnboarding") { - WelcomeView() - } else { - ContentView( - handler: sshHandler, - hostsManager: hostsManager, - keyManager: keyManager - ) - .transition(.opacity) - .colorScheme(hostsManager.selectedTheme.background.luminance > 0.5 ? .light : .dark) - .tint(hostsManager.tint) + Group { + if !hostsManager.shownOnboarding { + WelcomeView(hostsManager: hostsManager) + + } else { + ContentView( + handler: sshHandler, + hostsManager: hostsManager, + keyManager: keyManager + ) + .colorScheme(hostsManager.selectedTheme.background.luminance > 0.5 ? .light : .dark) + .tint(hostsManager.tint) + } } + .transition(.opacity) + .animation(.default, value: hostsManager.shownOnboarding) } } } diff --git a/ShhShell/Views/Onboarding/WelcomeView.swift b/ShhShell/Views/Onboarding/WelcomeView.swift index 6c4727e..110c022 100644 --- a/ShhShell/Views/Onboarding/WelcomeView.swift +++ b/ShhShell/Views/Onboarding/WelcomeView.swift @@ -8,8 +8,8 @@ import SwiftUI struct WelcomeView: View { + @ObservedObject var hostsManager: HostsManager @State private var spawnDate: Date = .now - @Environment(\.dismiss) var dismiss var body: some View { TimelineView(.animation) { tl in @@ -74,11 +74,13 @@ struct WelcomeView: View { } if time > 9 { #if swift(>=6.2) - Button("Continue") { dismiss() } + Button("Continue") { + hostsManager.setOnboarding(to: true) + } .buttonStyle(.glassProminent) #else Button { - dismiss() + hostsManager.setOnboarding(to: true) } label: { ZStack { Color.terminalGreen @@ -95,9 +97,6 @@ struct WelcomeView: View { #endif } } - .onDisappear { - NSUbiquitousKeyValueStore.default.set(true, forKey: "shownOnboarding") - } .animation(.spring, value: time) .preferredColorScheme(.dark) } @@ -105,5 +104,5 @@ struct WelcomeView: View { } #Preview { - WelcomeView() + WelcomeView(hostsManager: HostsManager(previews: true)) }