2021-06-12 19:33:24 +03:00
|
|
|
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
struct Window {
|
|
|
|
|
2021-06-13 05:45:54 +03:00
|
|
|
static func showNew() -> NSWindowController {
|
|
|
|
closeAll()
|
|
|
|
let windowController = new
|
|
|
|
activate(windowController)
|
|
|
|
return windowController
|
|
|
|
}
|
|
|
|
|
|
|
|
static func activate(_ windowController: NSWindowController) {
|
|
|
|
windowController.showWindow(nil)
|
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
|
windowController.window?.makeKeyAndOrderFront(nil)
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:33:24 +03:00
|
|
|
static func closeAll() {
|
|
|
|
NSApplication.shared.windows.forEach { $0.close() }
|
|
|
|
}
|
|
|
|
|
|
|
|
static func activateSafari() {
|
|
|
|
if let browser = NSWorkspace().runningApplications.first(where: { $0.bundleIdentifier == "com.apple.Safari" }) {
|
|
|
|
browser.activate(options: .activateIgnoringOtherApps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-13 05:45:54 +03:00
|
|
|
static var current: NSWindowController? {
|
|
|
|
return NSApplication.shared.windows.first?.windowController
|
|
|
|
}
|
|
|
|
|
|
|
|
static var new: NSWindowController {
|
|
|
|
return NSStoryboard.main.instantiateInitialController() as! NSWindowController
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NSStoryboard {
|
|
|
|
static let main = NSStoryboard(name: "Main", bundle: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func instantiate<ViewController: NSViewController>(_ type: ViewController.Type) -> ViewController {
|
|
|
|
return NSStoryboard.main.instantiateController(withIdentifier: String(describing: type)) as! ViewController
|
2021-06-12 19:33:24 +03:00
|
|
|
}
|