mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 10:22:35 +00:00
Merge branch 'bug/mac-state-restoration-4898'
This commit is contained in:
commit
0968b44c2f
5 files changed
+48
-11
No files matched your search
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -979,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 = []
|
||||
}
|
||||
|
||||
@@ -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)]"
|
||||
}
|
||||
}
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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")"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user