mirror of
https://github.com/yattee/yattee.git
synced 2025-01-06 01:20:31 +05:30
41 lines
901 B
Swift
41 lines
901 B
Swift
|
import AppKit
|
||
|
import Foundation
|
||
|
|
||
|
enum OpenWindow: String, CaseIterable {
|
||
|
case player, main
|
||
|
|
||
|
var window: NSWindow? {
|
||
|
// this is not solid but works as long as there is only two windows in the app
|
||
|
// needs to be changed in case we ever have more windows to handle
|
||
|
|
||
|
switch self {
|
||
|
case .player:
|
||
|
return NSApplication.shared.windows.last
|
||
|
case .main:
|
||
|
return NSApplication.shared.windows.first
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func focus() {
|
||
|
window?.makeKeyAndOrderFront(self)
|
||
|
}
|
||
|
|
||
|
var location: String {
|
||
|
switch self {
|
||
|
case .player:
|
||
|
return rawValue
|
||
|
case .main:
|
||
|
return ""
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func open() {
|
||
|
switch self {
|
||
|
case .player:
|
||
|
NSWorkspace.shared.open(URL(string: "yattee://player")!)
|
||
|
case .main:
|
||
|
Self.main.focus()
|
||
|
}
|
||
|
}
|
||
|
}
|