fix: properly reactive frame sizing

This commit is contained in:
Michael Freno
2026-01-11 19:41:56 -05:00
parent 1b55d82bc2
commit 25b7f20e94
3 changed files with 32 additions and 17 deletions

View File

@@ -49,7 +49,7 @@ struct AppSettings: Codable, Equatable, Hashable {
var hasCompletedOnboarding: Bool var hasCompletedOnboarding: Bool
var launchAtLogin: Bool var launchAtLogin: Bool
var playSounds: Bool var playSounds: Bool
// App Store detection (cached at launch, not persisted) // App Store detection (cached at launch, not persisted)
var isAppStoreVersion: Bool var isAppStoreVersion: Bool
@@ -66,7 +66,7 @@ struct AppSettings: Codable, Equatable, Hashable {
hasCompletedOnboarding: Bool = false, hasCompletedOnboarding: Bool = false,
launchAtLogin: Bool = false, launchAtLogin: Bool = false,
playSounds: Bool = true, playSounds: Bool = true,
isAppStoreVersion: Bool = false isAppStoreVersion: Bool = true
) { ) {
self.lookAwayTimer = lookAwayTimer self.lookAwayTimer = lookAwayTimer
self.lookAwayCountdownSeconds = lookAwayCountdownSeconds self.lookAwayCountdownSeconds = lookAwayCountdownSeconds
@@ -105,9 +105,9 @@ struct AppSettings: Codable, Equatable, Hashable {
&& lhs.launchAtLogin == rhs.launchAtLogin && lhs.playSounds == rhs.playSounds && lhs.launchAtLogin == rhs.launchAtLogin && lhs.playSounds == rhs.playSounds
&& lhs.isAppStoreVersion == rhs.isAppStoreVersion && lhs.isAppStoreVersion == rhs.isAppStoreVersion
} }
// MARK: - Custom Codable Implementation // MARK: - Custom Codable Implementation
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case lookAwayTimer case lookAwayTimer
case lookAwayCountdownSeconds case lookAwayCountdownSeconds
@@ -120,7 +120,7 @@ struct AppSettings: Codable, Equatable, Hashable {
case playSounds case playSounds
// isAppStoreVersion is intentionally excluded from persistence // isAppStoreVersion is intentionally excluded from persistence
} }
init(from decoder: Decoder) throws { init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
lookAwayTimer = try container.decode(TimerConfiguration.self, forKey: .lookAwayTimer) lookAwayTimer = try container.decode(TimerConfiguration.self, forKey: .lookAwayTimer)
@@ -135,7 +135,7 @@ struct AppSettings: Codable, Equatable, Hashable {
// isAppStoreVersion is not persisted, will be set at launch // isAppStoreVersion is not persisted, will be set at launch
isAppStoreVersion = false isAppStoreVersion = false
} }
func encode(to encoder: Encoder) throws { func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(lookAwayTimer, forKey: .lookAwayTimer) try container.encode(lookAwayTimer, forKey: .lookAwayTimer)

View File

@@ -31,8 +31,14 @@ struct OnboardingContainerView: View {
@State private var postureIntervalMinutes = 30 @State private var postureIntervalMinutes = 30
@State private var launchAtLogin = false @State private var launchAtLogin = false
@State private var subtleReminderSize: ReminderSize = .medium @State private var subtleReminderSize: ReminderSize = .medium
@State private var isAppStoreVersion: Bool
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
init(settingsManager: SettingsManager) {
self.settingsManager = settingsManager
_isAppStoreVersion = State(initialValue: settingsManager.settings.isAppStoreVersion)
}
var body: some View { var body: some View {
ZStack { ZStack {
VisualEffectView(material: .hudWindow, blendingMode: .behindWindow) VisualEffectView(material: .hudWindow, blendingMode: .behindWindow)
@@ -78,10 +84,7 @@ struct OnboardingContainerView: View {
GeneralSetupView( GeneralSetupView(
launchAtLogin: $launchAtLogin, launchAtLogin: $launchAtLogin,
subtleReminderSize: $subtleReminderSize, subtleReminderSize: $subtleReminderSize,
isAppStoreVersion: Binding( isAppStoreVersion: .constant(isAppStoreVersion),
get: { settingsManager.settings.isAppStoreVersion },
set: { _ in }
),
isOnboarding: true isOnboarding: true
) )
.tag(4) .tag(4)
@@ -149,7 +152,14 @@ struct OnboardingContainerView: View {
} }
} }
} }
.frame(minWidth: 1000, minHeight: 800)
.frame(
minWidth: 1000,
minHeight: isAppStoreVersion ? 700 : 900
)
.onReceive(settingsManager.$settings) { newSettings in
isAppStoreVersion = newSettings.isAppStoreVersion
}
} }
private func completeOnboarding() { private func completeOnboarding() {

View File

@@ -20,6 +20,7 @@ struct SettingsWindowView: View {
@State private var launchAtLogin: Bool @State private var launchAtLogin: Bool
@State private var subtleReminderSize: ReminderSize @State private var subtleReminderSize: ReminderSize
@State private var userTimers: [UserTimer] @State private var userTimers: [UserTimer]
@State private var isAppStoreVersion: Bool
init(settingsManager: SettingsManager, initialTab: Int = 0) { init(settingsManager: SettingsManager, initialTab: Int = 0) {
self.settingsManager = settingsManager self.settingsManager = settingsManager
@@ -40,6 +41,7 @@ struct SettingsWindowView: View {
_subtleReminderSize = State( _subtleReminderSize = State(
initialValue: settingsManager.settings.subtleReminderSize) initialValue: settingsManager.settings.subtleReminderSize)
_userTimers = State(initialValue: settingsManager.settings.userTimers) _userTimers = State(initialValue: settingsManager.settings.userTimers)
_isAppStoreVersion = State(initialValue: settingsManager.settings.isAppStoreVersion)
} }
var body: some View { var body: some View {
@@ -84,10 +86,7 @@ struct SettingsWindowView: View {
GeneralSetupView( GeneralSetupView(
launchAtLogin: $launchAtLogin, launchAtLogin: $launchAtLogin,
subtleReminderSize: $subtleReminderSize, subtleReminderSize: $subtleReminderSize,
isAppStoreVersion: Binding( isAppStoreVersion: .constant(isAppStoreVersion),
get: { settingsManager.settings.isAppStoreVersion },
set: { _ in }
),
isOnboarding: false isOnboarding: false
) )
.tag(4) .tag(4)
@@ -115,7 +114,13 @@ struct SettingsWindowView: View {
} }
.padding() .padding()
} }
.frame(minWidth: 750, minHeight: 850) .frame(
minWidth: 750,
minHeight: isAppStoreVersion ? 700 : 900
)
.onReceive(settingsManager.$settings) { newSettings in
isAppStoreVersion = newSettings.isAppStoreVersion
}
.onReceive( .onReceive(
NotificationCenter.default.publisher(for: Notification.Name("SwitchToSettingsTab")) NotificationCenter.default.publisher(for: Notification.Name("SwitchToSettingsTab"))
) { notification in ) { notification in
@@ -147,7 +152,7 @@ struct SettingsWindowView: View {
hasCompletedOnboarding: settingsManager.settings.hasCompletedOnboarding, hasCompletedOnboarding: settingsManager.settings.hasCompletedOnboarding,
launchAtLogin: launchAtLogin, launchAtLogin: launchAtLogin,
playSounds: settingsManager.settings.playSounds, playSounds: settingsManager.settings.playSounds,
isAppStoreVersion: settingsManager.settings.isAppStoreVersion isAppStoreVersion: isAppStoreVersion
) )
// Assign the entire settings object to trigger didSet and observers // Assign the entire settings object to trigger didSet and observers