From 016a09cf2580e7bbd9feab94da797171e7e011e7 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Mon, 30 Sep 2024 18:59:25 +0900 Subject: [PATCH] Fix window minimized window initializaiton --- CHANGELOG.md | 1 + .../DocumentWindowController.swift | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 466667b5f2..7f10b2e3fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Fixes +- Fix an issue that document windows were not properly initialized when the windows minimized on launch. - Fix an issue in the file browser that duplicate folders were displayed after renaming a folder. - Fix an issue in the file browser that some actions for the root folder were incorrectly disabled. - Fix an issue that changes of insertion formats in the Snippets settings pane were not saved. diff --git a/CotEditor/Sources/Document Window/DocumentWindowController.swift b/CotEditor/Sources/Document Window/DocumentWindowController.swift index 72ade90b59..910d534d7b 100644 --- a/CotEditor/Sources/Document Window/DocumentWindowController.swift +++ b/CotEditor/Sources/Document Window/DocumentWindowController.swift @@ -58,6 +58,8 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate { private var directoryDocument: DirectoryDocument? private var hasDirectoryBrowser: Bool { self.directoryDocument != nil } + private var needsManualOnAppear = false + private lazy var editedIndicator: NSView = NSHostingView(rootView: Circle() .fill(.tertiary) .frame(width: 4, height: 4) @@ -201,6 +203,23 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate { } + func windowWillMiniaturize(_ notification: Notification) { + + if self.window?.isVisible == false { + self.needsManualOnAppear = true + } + } + + + func windowDidDeminiaturize(_ notification: Notification) { + + if self.needsManualOnAppear { + self.contentViewController?.performOnAppearProcedure() + self.needsManualOnAppear = false + } + } + + func windowWillEnterFullScreen(_ notification: Notification) { self.window?.isOpaque = true @@ -345,6 +364,25 @@ final class DocumentWindowController: NSWindowController, NSWindowDelegate { } +private extension NSViewController { + + /// Recursively invokes `viewWillAppear()` and `viewDidAppear()`. + /// + /// Workaround the issue `viewWillAppear()` and `viewDidAppear()` are not invoked + /// on de-miniaturization when the window was initially miniaturized (2024-10, macOS 15, FB15331763). + func performOnAppearProcedure() { + + guard self.isViewShown else { return } + + self.viewWillAppear() + self.viewDidAppear() + + for child in self.children { + child.performOnAppearProcedure() + } + } +} + // MARK: - Toolbar