Skip to content

Commit

Permalink
Fix currently open filenames not syncing, #3159 (#3435)
Browse files Browse the repository at this point in the history
* Fix currently open filenames not syncing, #3159

Change MainWindowController.windowWillOpen to set the window's title to
"Window", the title a NSWindow has by default. If the title is not reset
when a window is reused then the wrong title will be displayed in the
"Window" menu.

* Fix currently open filenames not syncing, #3159

This problem is due to a defect in AppKit that has been fixed in macOS
Monterey. The commit changes the window controller to apply a
workaround of reseting the window's title in earlier versions of macOS.
If the title is not reset when a window is reused then the wrong title
will be displayed in the "Window" menu.

The commit will:
- Change MainWindowController.windowWillOpen to set the window's title
  to "Window", the title a NSWindow has by default
  • Loading branch information
low-batt committed Apr 23, 2022
1 parent 394ee2b commit d349899
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions iina/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,27 @@ class MainWindowController: PlayerWindowController {
// MARK: - Window delegate: Open / Close

func windowWillOpen() {
if #available(macOS 12, *) {
// Apparently Apple fixed AppKit for Monterey so the workaround below is only needed for
// previous versions of macOS. Support for #unavailable is coming in Swift 5.6. The version of
// Xcode being used at the time of this writing supports Swift 5.5.
} else {
// Must workaround an AppKit defect in earlier versions of macOS. This defect is known to
// exist in Catalina and Big Sur. The problem was not reproducible in Monterey. The status of
// other versions of macOS is unknown, however the workaround should be safe to apply in any
// version of macOS. The problem was reported in issues #3159, #3097 and #3253. The titles of
// open windows shown in the "Window" menu are automatically managed by the AppKit framework.
// To improve performance PlayerCore caches and reuses player instances along with their
// windows. This technique is valid and recommended by Apple. But in older versions of macOS,
// if a window is reused the framework will display the title first used for the window in the
// "Window" menu even after IINA has updated the title of the window. This problem can also be
// seen when right-clicking or control-clicking the IINA icon in the dock. As a workaround
// reset the window's title to "Window" before it is reused. This is the default title AppKit
// assigns to a window when it is first created. Surprising and rather disturbing this works
// as a workaround, but it does.
window!.title = "Window"
}

var screen = window!.screen!

if let rectString = UserDefaults.standard.value(forKey: "MainWindowLastPosition") as? String {
Expand Down

0 comments on commit d349899

Please sign in to comment.