diff --git a/Stats/Views/AppSettings.swift b/Stats/Views/AppSettings.swift index 7437db92..e2505df4 100644 --- a/Stats/Views/AppSettings.swift +++ b/Stats/Views/AppSettings.swift @@ -29,6 +29,8 @@ class ApplicationSettings: NSStackView { } private let updateWindow: UpdateWindow = UpdateWindow() + private var updateSelector: NSPopUpButton? + private var startAtLoginBtn: NSButton? init() { super.init(frame: NSRect( @@ -53,6 +55,20 @@ class ApplicationSettings: NSStackView { fatalError("init(coder:) has not been implemented") } + public func viewWillAppear() { + self.startAtLoginBtn?.state = LaunchAtLogin.isEnabled ? .on : .off + + var idx = self.updateSelector?.indexOfSelectedItem ?? 0 + if let items = self.updateSelector?.menu?.items { + for (i, item) in items.enumerated() { + if let obj = item.representedObject as? String, obj == self.updateIntervalValue { + idx = i + } + } + } + self.updateSelector?.selectItem(at: idx) + } + private func informationView() -> NSView { let view = NSStackView() view.heightAnchor.constraint(equalToConstant: 240).isActive = true @@ -118,13 +134,14 @@ class ApplicationSettings: NSStackView { grid.setContentHuggingPriority(.defaultHigh, for: .horizontal) grid.setContentHuggingPriority(.defaultHigh, for: .vertical) + self.updateSelector = selectView( + action: #selector(self.toggleUpdateInterval), + items: AppUpdateIntervals, + selected: self.updateIntervalValue + ) grid.addRow(with: [ self.titleView(localizedString("Check for updates")), - selectView( - action: #selector(self.toggleUpdateInterval), - items: AppUpdateIntervals, - selected: self.updateIntervalValue - ) + self.updateSelector! ]) grid.addRow(with: [ self.titleView(localizedString("Temperature")), @@ -139,11 +156,12 @@ class ApplicationSettings: NSStackView { state: Store.shared.bool(key: "dockIcon", defaultValue: false), text: localizedString("Show icon in dock") )]) - grid.addRow(with: [NSGridCell.emptyContentView, self.toggleView( + self.startAtLoginBtn = self.toggleView( action: #selector(self.toggleLaunchAtLogin), state: LaunchAtLogin.isEnabled, text: localizedString("Start at login") - )]) + ) + grid.addRow(with: [NSGridCell.emptyContentView, self.startAtLoginBtn!]) view.addSubview(grid) @@ -187,7 +205,7 @@ class ApplicationSettings: NSStackView { return field } - private func toggleView(action: Selector, state: Bool, text: String) -> NSView { + private func toggleView(action: Selector, state: Bool, text: String) -> NSButton { let button: NSButton = NSButton(frame: NSRect(x: 0, y: 0, width: 30, height: 20)) button.setButtonType(.switch) button.state = state ? .on : .off diff --git a/Stats/Views/Settings.swift b/Stats/Views/Settings.swift index 81fdd470..aa455974 100644 --- a/Stats/Views/Settings.swift +++ b/Stats/Views/Settings.swift @@ -138,7 +138,7 @@ private class SettingsView: NSView { private var mainView: NSView = NSView() private var dashboard: NSView = Dashboard() - private var settings: NSView = ApplicationSettings() + private var settings: ApplicationSettings = ApplicationSettings() private let supportPopover = NSPopover() @@ -237,6 +237,7 @@ private class SettingsView: NSView { } else if title == "Dashboard" { view = self.dashboard } else if title == "settings" { + self.settings.viewWillAppear() view = self.settings }