mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 00:31:14 +00:00
Mark classes as final. Create private Key structs instead of duplicating string literals. Make supportsSecureCoding let instead of var.
This commit is contained in:
1 parent
74890781c5
commit
91f66835f9
4 files changed
+77
-55
No files matched your search
@@ -8,26 +8,30 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class DetailWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static var supportsSecureCoding = true
|
||||
final class DetailWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static let supportsSecureCoding = true
|
||||
|
||||
let isShowingExtractedArticle: Bool
|
||||
let windowScrollY: CGFloat
|
||||
|
||||
internal init(isShowingExtractedArticle: Bool, windowScrollY: CGFloat) {
|
||||
init(isShowingExtractedArticle: Bool, windowScrollY: CGFloat) {
|
||||
self.isShowingExtractedArticle = isShowingExtractedArticle
|
||||
self.windowScrollY = windowScrollY
|
||||
}
|
||||
|
||||
|
||||
private struct Key {
|
||||
static let isShowingExtractedArticle = "isShowingExtractedArticle"
|
||||
static let windowScrollY = "windowScrollY"
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
isShowingExtractedArticle = coder.decodeBool(forKey: "isShowingExtractedArticle")
|
||||
windowScrollY = CGFloat(coder.decodeDouble(forKey: "windowScrollY"))
|
||||
isShowingExtractedArticle = coder.decodeBool(forKey: Key.isShowingExtractedArticle)
|
||||
windowScrollY = CGFloat(coder.decodeDouble(forKey: Key.windowScrollY))
|
||||
}
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(isShowingExtractedArticle, forKey: "isShowingExtractedArticle")
|
||||
coder.encode(Double(windowScrollY), forKey: "windowScrollY")
|
||||
coder.encode(isShowingExtractedArticle, forKey: Key.isShowingExtractedArticle)
|
||||
coder.encode(Double(windowScrollY), forKey: Key.windowScrollY)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class MainWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static var supportsSecureCoding = true
|
||||
|
||||
final class MainWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static let supportsSecureCoding = true
|
||||
|
||||
let isFullScreen: Bool
|
||||
let splitViewWidths: [Int]
|
||||
let isSidebarHidden: Bool
|
||||
@@ -28,23 +28,30 @@ class MainWindowState: NSObject, NSSecureCoding {
|
||||
self.detailWindowState = detailWindowState
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
isFullScreen = coder.decodeBool(forKey: "isFullScreen")
|
||||
splitViewWidths = coder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: "splitViewWidths") as? [Int] ?? []
|
||||
isSidebarHidden = coder.decodeBool(forKey: "isSidebarHidden")
|
||||
sidebarWindowState = coder.decodeObject(of: SidebarWindowState.self, forKey: "sidebarWindowState")
|
||||
timelineWindowState = coder.decodeObject(of: TimelineWindowState.self, forKey: "timelineWindowState")
|
||||
detailWindowState = coder.decodeObject(of: DetailWindowState.self, forKey: "detailWindowState")
|
||||
private struct Key {
|
||||
static let isFullScreen = "isFullScreen"
|
||||
static let splitViewWidths = "splitViewWidths"
|
||||
static let isSidebarHidden = "isSidebarHidden"
|
||||
static let sidebarWindowState = "sidebarWindowState"
|
||||
static let timelineWindowState = "timelineWindowState"
|
||||
static let detailWindowState = "detailWindowState"
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
isFullScreen = coder.decodeBool(forKey: Key.isFullScreen)
|
||||
splitViewWidths = coder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: Key.splitViewWidths) as? [Int] ?? []
|
||||
isSidebarHidden = coder.decodeBool(forKey: Key.isSidebarHidden)
|
||||
sidebarWindowState = coder.decodeObject(of: SidebarWindowState.self, forKey: Key.sidebarWindowState)
|
||||
timelineWindowState = coder.decodeObject(of: TimelineWindowState.self, forKey: Key.timelineWindowState)
|
||||
detailWindowState = coder.decodeObject(of: DetailWindowState.self, forKey: Key.detailWindowState)
|
||||
}
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(isFullScreen, forKey: "isFullScreen")
|
||||
coder.encode(splitViewWidths, forKey: "splitViewWidths")
|
||||
coder.encode(isSidebarHidden, forKey: "isSidebarHidden")
|
||||
coder.encode(sidebarWindowState, forKey: "sidebarWindowState")
|
||||
coder.encode(timelineWindowState, forKey: "timelineWindowState")
|
||||
coder.encode(detailWindowState, forKey: "detailWindowState")
|
||||
coder.encode(isFullScreen, forKey: Key.isFullScreen)
|
||||
coder.encode(splitViewWidths, forKey: Key.splitViewWidths)
|
||||
coder.encode(isSidebarHidden, forKey: Key.isSidebarHidden)
|
||||
coder.encode(sidebarWindowState, forKey: Key.sidebarWindowState)
|
||||
coder.encode(timelineWindowState, forKey: Key.timelineWindowState)
|
||||
coder.encode(detailWindowState, forKey: Key.detailWindowState)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class SidebarWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static var supportsSecureCoding = true
|
||||
|
||||
final class SidebarWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static let supportsSecureCoding = true
|
||||
|
||||
let isReadFiltered: Bool
|
||||
let expandedContainers: [[String: String]]
|
||||
let selectedFeeds: [[String: String]]
|
||||
@@ -21,17 +21,22 @@ class SidebarWindowState: NSObject, NSSecureCoding {
|
||||
self.expandedContainers = expandedContainers
|
||||
self.selectedFeeds = selectedFeeds
|
||||
}
|
||||
|
||||
|
||||
private struct Key {
|
||||
static let isReadFiltered = "isReadFiltered"
|
||||
static let expandedContainers = "expandedContainers"
|
||||
static let selectedFeeds = "selectedFeeds"
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
isReadFiltered = coder.decodeBool(forKey: "isReadFiltered")
|
||||
expandedContainers = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: "expandedContainers") as? [[String: String]] ?? []
|
||||
selectedFeeds = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: "selectedFeeds") as? [[String: String]] ?? []
|
||||
isReadFiltered = coder.decodeBool(forKey: Key.isReadFiltered)
|
||||
expandedContainers = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: Key.expandedContainers) as? [[String: String]] ?? []
|
||||
selectedFeeds = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: Key.selectedFeeds) as? [[String: String]] ?? []
|
||||
}
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(isReadFiltered, forKey: "isReadFiltered")
|
||||
coder.encode(expandedContainers, forKey: "expandedContainers")
|
||||
coder.encode(selectedFeeds, forKey: "selectedFeeds")
|
||||
coder.encode(isReadFiltered, forKey: Key.isReadFiltered)
|
||||
coder.encode(expandedContainers, forKey: Key.expandedContainers)
|
||||
coder.encode(selectedFeeds, forKey: Key.selectedFeeds)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,34 +8,40 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class TimelineWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static var supportsSecureCoding = true
|
||||
|
||||
final class TimelineWindowState: NSObject, NSSecureCoding {
|
||||
|
||||
static let supportsSecureCoding = true
|
||||
|
||||
let readArticlesFilterStateKeys: [[String: String]]
|
||||
let readArticlesFilterStateValues: [Bool]
|
||||
let selectedAccountID: String?
|
||||
let selectedArticleID: String?
|
||||
|
||||
|
||||
init(readArticlesFilterStateKeys: [[String : String]], readArticlesFilterStateValues: [Bool], selectedAccountID: String? = nil, selectedArticleID: String? = nil) {
|
||||
self.readArticlesFilterStateKeys = readArticlesFilterStateKeys
|
||||
self.readArticlesFilterStateValues = readArticlesFilterStateValues
|
||||
self.selectedAccountID = selectedAccountID
|
||||
self.selectedArticleID = selectedArticleID
|
||||
}
|
||||
|
||||
|
||||
private struct Key {
|
||||
static let readArticlesFilterStateKeys = "readArticlesFilterStateKeys"
|
||||
static let readArticlesFilterStateValues = "readArticlesFilterStateValues"
|
||||
static let selectedAccountID = "selectedAccountID"
|
||||
static let selectedArticleID = "selectedArticleID"
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
readArticlesFilterStateKeys = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: "readArticlesFilterStateKeys") as? [[String: String]] ?? []
|
||||
readArticlesFilterStateValues = coder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: "readArticlesFilterStateValues") as? [Bool] ?? []
|
||||
selectedAccountID = coder.decodeObject(of: NSString.self, forKey: "selectedAccountID") as? String
|
||||
selectedArticleID = coder.decodeObject(of: NSString.self, forKey: "selectedArticleID") as? String
|
||||
readArticlesFilterStateKeys = coder.decodeObject(of: [NSArray.self, NSDictionary.self, NSString.self], forKey: Key.readArticlesFilterStateKeys) as? [[String: String]] ?? []
|
||||
readArticlesFilterStateValues = coder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: Key.readArticlesFilterStateValues) as? [Bool] ?? []
|
||||
selectedAccountID = coder.decodeObject(of: NSString.self, forKey: Key.selectedAccountID) as? String
|
||||
selectedArticleID = coder.decodeObject(of: NSString.self, forKey: Key.selectedArticleID) as? String
|
||||
}
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(readArticlesFilterStateKeys, forKey: "readArticlesFilterStateKeys")
|
||||
coder.encode(readArticlesFilterStateValues, forKey: "readArticlesFilterStateValues")
|
||||
coder.encode(selectedAccountID, forKey: "selectedAccountID")
|
||||
coder.encode(selectedArticleID, forKey: "selectedArticleID")
|
||||
coder.encode(readArticlesFilterStateKeys, forKey: Key.readArticlesFilterStateKeys)
|
||||
coder.encode(readArticlesFilterStateValues, forKey: Key.readArticlesFilterStateValues)
|
||||
coder.encode(selectedAccountID, forKey: Key.selectedAccountID)
|
||||
coder.encode(selectedArticleID, forKey: Key.selectedArticleID)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user