Reopen the Inspector window at launch if it was open on quit.

This commit is contained in:
Brent Simmons 2018-01-21 13:27:17 -08:00
parent a7a2eabf78
commit 5a75d39b7c
2 changed files with 48 additions and 11 deletions

View File

@ -138,6 +138,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
self.unreadCount = AccountManager.shared.unreadCount
}
if InspectorWindowController.shouldOpenAtStartup {
DispatchQueue.main.async {
self.toggleInspectorWindow(self)
}
}
#if RELEASE
DispatchQueue.main.async {
self.refreshAll(self)
@ -159,6 +165,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
RSMultiLineRenderer.emptyCache()
TimelineCellData.emptyCache()
timelineEmptyCaches()
saveState()
}
func applicationWillTerminate(_ notification: Notification) {
saveState()
}
// MARK: GetURL Apple Event
@ -444,4 +457,11 @@ private extension AppDelegate {
}
return windowController.selectedObjectsInSidebar()
}
func saveState() {
if let inspectorWindowController = inspectorWindowController {
inspectorWindowController.saveState()
}
}
}

View File

@ -23,6 +23,23 @@ typealias InspectorViewController = Inspector & NSViewController
final class InspectorWindowController: NSWindowController {
class var shouldOpenAtStartup: Bool {
return UserDefaults.standard.bool(forKey: DefaultsKey.windowIsOpen)
}
var objects: [Any]? {
didSet {
let _ = window
currentInspector = inspector(for: objects)
}
}
var isOpen: Bool {
get {
return isWindowLoaded && window!.isVisible
}
}
private var inspectors: [InspectorViewController]!
private var currentInspector: InspectorViewController! {
@ -40,17 +57,9 @@ final class InspectorWindowController: NSWindowController {
}
}
var objects: [Any]? {
didSet {
let _ = window
currentInspector = inspector(for: objects)
}
}
var isOpen: Bool {
get {
return isWindowLoaded && window!.isVisible
}
private struct DefaultsKey {
static let windowIsOpen = "FloatingInspectorIsOpen"
static let windowOrigin = "FloatingInspectorOrigin"
}
override func windowDidLoad() {
@ -83,6 +92,14 @@ final class InspectorWindowController: NSWindowController {
return fallbackInspector!
}
func saveState() {
UserDefaults.standard.set(isOpen, forKey: DefaultsKey.windowIsOpen)
if isOpen, let window = window, let flippedOrigin = window.flippedOrigin {
UserDefaults.standard.set(NSStringFromPoint(flippedOrigin), forKey: DefaultsKey.windowOrigin)
}
}
}
private extension InspectorWindowController {