From 4345b97d728c4b29a6fbdf7e0e5e904bd23de407 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sat, 16 Dec 2023 18:16:46 +0330 Subject: [PATCH] Fix macOS restore from dock --- macos/Runner/AppDelegate.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index 9e1c7f68..33afb1be 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -7,4 +7,18 @@ class AppDelegate: FlutterAppDelegate { // https://github.com/leanflutter/window_manager/issues/214 return false } + + // window manager restore from dock: https://leanflutter.dev/blog/click-dock-icon-to-restore-after-closing-the-window + override func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + if !flag { + for window in NSApp.windows { + if !window.isVisible { + window.setIsVisible(true) + } + window.makeKeyAndOrderFront(self) + NSApp.activate(ignoringOtherApps: true) + } + } + return true + } }