mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-14 20:33:41 +00:00
fix: restore only main macOS window and select active downloads
This commit is contained in:
1 parent
6568498850
commit
31fa0e5bc9
11 files changed
+219
-14
No files matched your search
@@ -26,16 +26,18 @@ class AppDelegate: FlutterAppDelegate {
|
||||
}
|
||||
|
||||
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)
|
||||
// Closed child windows can remain in NSApp.windows. Restoring every
|
||||
// window resurrects completed create-task forms with their last frame.
|
||||
// Use the main window even when an unfinished child is still visible.
|
||||
if let window = sender.windows.first(where: { $0 is MainFlutterWindow }) {
|
||||
if window.isMiniaturized {
|
||||
window.deminiaturize(self)
|
||||
}
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
window.makeKeyAndOrderFront(self)
|
||||
sender.activate(ignoringOtherApps: true)
|
||||
}
|
||||
return true
|
||||
// We handled reopening; AppKit must not restore other retained windows.
|
||||
return false
|
||||
}
|
||||
|
||||
override func application(_ sender: NSApplication, openFile filename: String) -> Bool {
|
||||
|
||||
@@ -1,12 +1,55 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
import XCTest
|
||||
@testable import Gopeed
|
||||
|
||||
class RunnerTests: XCTestCase {
|
||||
|
||||
func testExample() {
|
||||
// If you add code to the Runner application, consider adding tests here.
|
||||
// See https://developer.apple.com/documentation/xctest for more information about using XCTest.
|
||||
func testReopenDoesNotRestoreClosedCreateTaskWindows() throws {
|
||||
let mainWindow = try XCTUnwrap(NSApp.windows.first { $0 is MainFlutterWindow })
|
||||
let delegate = try XCTUnwrap(NSApp.delegate as? AppDelegate)
|
||||
let children = [makeChildWindow(), makeChildWindow()]
|
||||
defer {
|
||||
children.forEach { $0.close() }
|
||||
mainWindow.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
mainWindow.orderOut(nil)
|
||||
for child in children {
|
||||
child.makeKeyAndOrderFront(nil)
|
||||
child.close()
|
||||
XCTAssertFalse(child.isVisible)
|
||||
}
|
||||
|
||||
XCTAssertFalse(delegate.applicationShouldHandleReopen(NSApp, hasVisibleWindows: false))
|
||||
XCTAssertTrue(mainWindow.isVisible)
|
||||
XCTAssertTrue(children.allSatisfy { !$0.isVisible })
|
||||
}
|
||||
|
||||
func testReopenRestoresMainWindowWithAnUnfinishedChildVisible() throws {
|
||||
let mainWindow = try XCTUnwrap(NSApp.windows.first { $0 is MainFlutterWindow })
|
||||
let delegate = try XCTUnwrap(NSApp.delegate as? AppDelegate)
|
||||
let child = makeChildWindow()
|
||||
defer {
|
||||
child.close()
|
||||
mainWindow.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
mainWindow.orderOut(nil)
|
||||
child.makeKeyAndOrderFront(nil)
|
||||
|
||||
XCTAssertFalse(delegate.applicationShouldHandleReopen(NSApp, hasVisibleWindows: true))
|
||||
XCTAssertTrue(mainWindow.isVisible)
|
||||
XCTAssertTrue(child.isVisible)
|
||||
}
|
||||
|
||||
private func makeChildWindow() -> NSWindow {
|
||||
let window = NSWindow(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 300, height: 200),
|
||||
styleMask: [.titled, .closable], backing: .buffered, defer: false)
|
||||
// Match desktop_multi_window's retained native child windows.
|
||||
window.isReleasedWhenClosed = false
|
||||
return window
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user