Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CatalystPrefsWindow/AppKitIntegration/AppKitController.swift
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (37 sloc)
1.44 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 2021 Steven Troughton-Smith (@stroughtonsmith) | |
| Provided as sample code to do with as you wish. | |
| No license or attribution required. | |
| */ | |
| import AppKit | |
| extension NSObject { | |
| @objc func hostWindowForSceneIdentifier(_ identifier:String) -> NSWindow? { | |
| return nil | |
| } | |
| } | |
| class AppKitController : NSObject { | |
| var preferencesSceneIdentifier:String? | |
| // MARK: - | |
| @objc public func _marzipan_setupWindow(_ note:Notification) { | |
| guard let preferencesSceneIdentifier = preferencesSceneIdentifier else { return } | |
| NSLog("_marzipan_setupWindow: \(String(describing: note.userInfo))") | |
| /* | |
| Here, AppKit has generated the host window for your UIKit window. | |
| Now it is safe to go do any AppKit-y things you'd like to do to it | |
| */ | |
| if let userInfo = note.userInfo, let sceneIdentifier = userInfo["SceneIdentifier"] as? String { | |
| if sceneIdentifier.hasSuffix(preferencesSceneIdentifier) { | |
| guard let appDelegate = NSApp.delegate as? NSObject else { return } | |
| if appDelegate.responds(to: #selector(hostWindowForSceneIdentifier(_:))) { | |
| guard let hostWindow = appDelegate.hostWindowForSceneIdentifier(sceneIdentifier) else { return } | |
| hostWindow.collectionBehavior = [.fullScreenAuxiliary] | |
| hostWindow.styleMask = [.closable, .titled] | |
| hostWindow.isRestorable = false | |
| } | |
| } | |
| } | |
| } | |
| @objc public func configurePreferencesWindowForSceneIdentifier(_ sceneIdentifier:String) { | |
| preferencesSceneIdentifier = sceneIdentifier | |
| } | |
| } |