From 5d8e49057d9ba9bbfd187cc22c38ac7cbef50a38 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 5 Jan 2026 19:18:50 -0800 Subject: [PATCH 1/3] Add description methods for Mac state restoration models. --- Mac/MainWindow/Detail/DetailWindowState.swift | 4 ++++ Mac/MainWindow/MainWindowState.swift | 7 +++++++ Mac/MainWindow/Sidebar/SidebarWindowState.swift | 4 ++++ Mac/MainWindow/Timeline/TimelineWindowState.swift | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/Mac/MainWindow/Detail/DetailWindowState.swift b/Mac/MainWindow/Detail/DetailWindowState.swift index 775524d7f..e117483f0 100644 --- a/Mac/MainWindow/Detail/DetailWindowState.swift +++ b/Mac/MainWindow/Detail/DetailWindowState.swift @@ -34,4 +34,8 @@ final class DetailWindowState: NSObject, NSSecureCoding { coder.encode(isShowingExtractedArticle, forKey: Key.isShowingExtractedArticle) coder.encode(Double(windowScrollY), forKey: Key.windowScrollY) } + + override var description: String { + "DetailWindowState: extracted=\(isShowingExtractedArticle), scrollY=\(windowScrollY)" + } } diff --git a/Mac/MainWindow/MainWindowState.swift b/Mac/MainWindow/MainWindowState.swift index a92168938..cc79843a0 100644 --- a/Mac/MainWindow/MainWindowState.swift +++ b/Mac/MainWindow/MainWindowState.swift @@ -54,4 +54,11 @@ final class MainWindowState: NSObject, NSSecureCoding { coder.encode(timelineWindowState, forKey: Key.timelineWindowState) coder.encode(detailWindowState, forKey: Key.detailWindowState) } + + override var description: String { + let sidebar = sidebarWindowState?.description ?? "nil" + let timeline = timelineWindowState?.description ?? "nil" + let detail = detailWindowState?.description ?? "nil" + return "MainWindowState: fullScreen=\(isFullScreen), widths=\(splitViewWidths), sidebarHidden=\(isSidebarHidden), sidebar=[\(sidebar)], timeline=[\(timeline)], detail=[\(detail)]" + } } diff --git a/Mac/MainWindow/Sidebar/SidebarWindowState.swift b/Mac/MainWindow/Sidebar/SidebarWindowState.swift index 12b434715..75a1332eb 100644 --- a/Mac/MainWindow/Sidebar/SidebarWindowState.swift +++ b/Mac/MainWindow/Sidebar/SidebarWindowState.swift @@ -38,4 +38,8 @@ final class SidebarWindowState: NSObject, NSSecureCoding { coder.encode(expandedContainers, forKey: Key.expandedContainers) coder.encode(selectedFeeds, forKey: Key.selectedFeeds) } + + override var description: String { + "SidebarWindowState: readFiltered=\(isReadFiltered), expandedContainers=\(expandedContainers), selectedFeeds=\(selectedFeeds)" + } } diff --git a/Mac/MainWindow/Timeline/TimelineWindowState.swift b/Mac/MainWindow/Timeline/TimelineWindowState.swift index 720744f66..ef7951ea3 100644 --- a/Mac/MainWindow/Timeline/TimelineWindowState.swift +++ b/Mac/MainWindow/Timeline/TimelineWindowState.swift @@ -44,4 +44,8 @@ final class TimelineWindowState: NSObject, NSSecureCoding { coder.encode(selectedAccountID, forKey: Key.selectedAccountID) coder.encode(selectedArticleID, forKey: Key.selectedArticleID) } + + override var description: String { + "TimelineWindowState: filterKeys=\(readArticlesFilterStateKeys.count), filterValues=\(readArticlesFilterStateValues.count), accountID=\(selectedAccountID ?? "nil"), articleID=\(selectedArticleID ?? "nil")" + } } From 36347924c0419ab64cd25283a7a0d4e954bcf060 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 5 Jan 2026 19:19:55 -0800 Subject: [PATCH 2/3] Add logging for state restoration. Also: do UI restoration after window restoration, instead of before. --- Mac/MainWindow/MainWindowController.swift | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index ed9ff16f1..ce91786c8 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -7,6 +7,7 @@ // import AppKit +import os import UserNotifications import Articles import Account @@ -17,7 +18,9 @@ enum TimelineSourceMode { } final class MainWindowController: NSWindowController, NSUserInterfaceValidations { - @IBOutlet var articleThemePopUpButton: NSPopUpButton? + static private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MainWindowController") + + @IBOutlet var articleThemePopUpButton: NSPopUpButton? private var activityManager = ActivityManager() @@ -130,7 +133,9 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations } func saveStateToUserDefaults() { - let data = try? NSKeyedArchiver.archivedData(withRootObject: savableState(), requiringSecureCoding: true) + let state = savableState() + Self.logger.debug("MainWindowController: Saving state to UserDefaults: \(state)") + let data = try? NSKeyedArchiver.archivedData(withRootObject: state, requiringSecureCoding: true) AppDefaults.shared.secureWindowState = data window?.saveFrame(usingName: windowAutosaveName) } @@ -138,12 +143,13 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations func restoreStateFromUserDefaults() { if let data = AppDefaults.shared.secureWindowState, let state = try? NSKeyedUnarchiver.unarchivedObject(ofClass: MainWindowState.self, from: data) { - restoreState(from: state) + Self.logger.debug("MainWindowController: restoring state from UserDefaults: \(state)") window?.setFrameUsingName(windowAutosaveName, force: true) + restoreState(from: state) } else if let state = AppDefaults.shared.legacyWindowState { // Migrate from previous window state data. Delete data when finished. - restoreLegacyState(from: state) window?.setFrameUsingName(windowAutosaveName, force: true) + restoreLegacyState(from: state) AppDefaults.shared.deleteLegacyWindowState() } } @@ -545,7 +551,6 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations @objc func selectArticleTheme(_ menuItem: NSMenuItem) { ArticleThemesManager.shared.currentThemeName = menuItem.title } - } // MARK: NSWindowDelegate @@ -553,19 +558,25 @@ final class MainWindowController: NSWindowController, NSUserInterfaceValidations extension MainWindowController: NSWindowDelegate { func window(_ window: NSWindow, willEncodeRestorableState coder: NSCoder) { - coder.encode(savableState(), forKey: UserInfoKey.windowState) + let state = savableState() + Self.logger.debug("MainWindowController: willEncodeRestorableState: \(state)") + coder.encode(state, forKey: UserInfoKey.windowState) } func window(_ window: NSWindow, didDecodeRestorableState coder: NSCoder) { - guard let state = coder.decodeObject(of: MainWindowState.self, forKey: UserInfoKey.windowState) else { return } + guard let state = coder.decodeObject(of: MainWindowState.self, forKey: UserInfoKey.windowState) else { + Self.logger.debug("MainWindowController: failed to decode restorable state") + return + } + Self.logger.debug("MainWindowController: didDecodeRestorableState: \(state)") restoreState(from: state) } func windowWillClose(_ notification: Notification) { + Self.logger.debug("MainWindowController: windowWillClose") detailViewController?.stopMediaPlayback() appDelegate.removeMainWindow(self) } - } // MARK: - SidebarDelegate @@ -594,9 +605,9 @@ extension MainWindowController: SidebarDelegate { } func sidebarInvalidatedRestorationState(_: SidebarViewController) { + Self.logger.debug("MainWindowController: sidebarInvalidatedRestorationState") invalidateRestorableState() } - } // MARK: - TimelineContainerViewControllerDelegate From 02bc49611efd6fb27aef394e8845c2d08f44d4d8 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 5 Jan 2026 19:29:12 -0800 Subject: [PATCH 3/3] Calculate timeline pane width, since its reported width is not what we want. --- Mac/MainWindow/MainWindowController.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index ce91786c8..1ffc1bf97 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -990,8 +990,15 @@ private extension MainWindowController { let isFullScreen = window?.styleMask.contains(.fullScreen) ?? false let splitViewWidths: [Int] - if let splitView = splitViewController?.splitView { - splitViewWidths = splitView.arrangedSubviews.map { Int(floor($0.frame.width)) } + if let splitView = splitViewController?.splitView, let window { + let sidebarWidth = splitView.arrangedSubviews[0].frame.width + let detailWidth = splitView.arrangedSubviews[2].frame.width + // Starting with macOS 26, timelineWidth has to be calculated — + // because its width is greater than its apparent width, + // so that things can slide under the sidebar. + let dividerThickness = splitView.dividerThickness + let timelineWidth = window.frame.width - (sidebarWidth + detailWidth + (dividerThickness * 2)) + splitViewWidths = [Int(floor(sidebarWidth)), Int(floor(timelineWidth)), Int(floor(detailWidth))] } else { splitViewWidths = [] }