improvements on the ui
This commit is contained in:
@@ -15,7 +15,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
NSApp.mainMenu = MainMenu.make()
|
||||
let store: PageStore
|
||||
do {
|
||||
store = try PageStore()
|
||||
store = try PageStore(pruneAt: Date())
|
||||
} catch {
|
||||
// No store means nothing can flush over the unreadable page file on quit.
|
||||
showUnreadable(error)
|
||||
@@ -23,6 +23,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
return
|
||||
}
|
||||
self.store = store
|
||||
removeUnusedImages(of: store)
|
||||
let controller = PageWindowController(store: store)
|
||||
windowController = controller
|
||||
controller.onHide = { [weak self] in self?.hidePlak() }
|
||||
@@ -108,6 +109,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs only when the page file holds the page: with no page file, or a failed write, it would delete used images.
|
||||
private func removeUnusedImages(of store: PageStore) {
|
||||
guard store.saveError == nil, FileManager.default.fileExists(atPath: store.url.path) else { return }
|
||||
ImageStore(base: store.url.deletingLastPathComponent()).removeUnused(keeping: store.loaded.imagePaths)
|
||||
}
|
||||
|
||||
private func showUnreadable(_ error: Error) {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .critical
|
||||
|
||||
Reference in New Issue
Block a user