mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 17:49:58 +00:00
Improve optional checking in native selector
This commit is contained in:
@@ -2,47 +2,30 @@ import Cocoa
|
||||
|
||||
|
||||
class AppDelegate : NSObject, NSApplicationDelegate {
|
||||
var initData: InitData!
|
||||
|
||||
var mainWindow: NSWindow?
|
||||
var mainWindowController: NSWindowController?
|
||||
var mainWindowViewController: ViewController?
|
||||
|
||||
|
||||
func applicationDidFinishLaunching (_ aNotification: Notification) {
|
||||
if CommandLine.argc < 2 {
|
||||
fputs("Error: Not enough args\n", stderr)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
guard let data = CommandLine.arguments[1].data(using: .utf8) else {
|
||||
fputs("Error: Failed to convert input to data\n", stderr)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
do {
|
||||
// Decode and store initialization JSON data
|
||||
self.initData = try JSONDecoder().decode(InitData.self, from: data)
|
||||
} catch {
|
||||
fputs("Error: Failed to parse input data\n (\(error))", stderr)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
||||
let window = NSWindow(
|
||||
contentRect: NSZeroRect
|
||||
, styleMask: [ .titled, .closable ]
|
||||
, backing: .buffered
|
||||
, defer: false)
|
||||
|
||||
let screenHeight = NSScreen.main!.frame.height
|
||||
|
||||
window.titleVisibility = .hidden
|
||||
window.isMovableByWindowBackground = true
|
||||
window.orderFrontRegardless()
|
||||
window.setFrameTopLeftPoint(NSPoint(
|
||||
x: self.initData.windowPositionX
|
||||
, y: Int(screenHeight - CGFloat(self.initData.windowPositionY))))
|
||||
|
||||
if let screen = NSScreen.main {
|
||||
let windowX = InitDataProvider.shared.data.windowPositionX
|
||||
let windowY = Int(screen.frame.height - CGFloat(
|
||||
InitDataProvider.shared.data.windowPositionY))
|
||||
|
||||
window.setFrameTopLeftPoint(NSPoint(x: windowX, y: windowY))
|
||||
}
|
||||
|
||||
|
||||
let windowController = NSWindowController(window: window)
|
||||
windowController.showWindow(window)
|
||||
@@ -59,7 +42,7 @@ class AppDelegate : NSObject, NSApplicationDelegate {
|
||||
}
|
||||
|
||||
func applicationDidResignActive (_ aNotification: Notification) {
|
||||
if self.initData.closeIfFocusLost {
|
||||
if InitDataProvider.shared.data.closeIfFocusLost {
|
||||
self.mainWindow?.performClose(aNotification)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user