12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // KMBookmarkManager.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/2/7.
- //
- import Cocoa
- let bookmarksIdentifier = (Bundle.main.bundleIdentifier ?? "") + ".bookmarks"
- let kBookmarks = "bookmarks"
- let kRecentDocuments = "recentDocuments"
- let kProperties = "properties"
- class KMBookmarkManager {
- static let manager = KMBookmarkManager()
-
- var recentDocuments: [[String: Any]] = []
- var rootBookmark: KMRootBookmark = KMRootBookmark()
-
- private init() {
- self.reloadData()
- }
-
- func reloadData() {
- let bookmarkDictionary: NSDictionary = (UserDefaults.standard.persistentDomain(forName: bookmarksIdentifier) ?? NSDictionary() as! [String : Any]) as NSDictionary
- let documents: NSArray = (bookmarkDictionary.object(forKey: kRecentDocuments) ?? NSArray()) as! NSArray
- for info in documents {
- recentDocuments.append(info as! [String : Any])
- }
-
- let childrenProperties = (bookmarkDictionary[kBookmarks] ?? NSArray()) as! NSArray
- rootBookmark = KMRootBookmark.bookmarkRoot(childrenProperties: childrenProperties)
- }
-
- func saveData() {
- let bookmarksDictionary: [String: Any] = [
- "bookmarks": self.rootBookmark.children.map { $0.properties },
- "recentDocuments": recentDocuments as Any
- ]
- UserDefaults.standard.setPersistentDomain(bookmarksDictionary, forName: bookmarksIdentifier)
- // NSDictionary *bookmarksDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[[bookmarkRoot children] valueForKey:@"properties"], BOOKMARKS_KEY, recentDocuments, RECENTDOCUMENTS_KEY, nil];
- // [[NSUserDefaults standardUserDefaults] setPersistentDomain:bookmarksDictionary forName:SKBookmarksIdentifier];
- }
- }
|