2019-06-23 09:44:49 +02:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// RectangleLauncher
|
|
|
|
//
|
|
|
|
// Created by Ryan Hanson on 6/14/19.
|
|
|
|
// Copyright © 2019 Ryan Hanson. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
@NSApplicationMain
|
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
2023-02-20 17:52:07 -05:00
|
|
|
if #available(macOS 13, *) {
|
|
|
|
terminate()
|
|
|
|
return
|
|
|
|
}
|
2019-06-23 09:44:49 +02:00
|
|
|
let mainAppIdentifier = "com.knollsoft.Rectangle"
|
|
|
|
let running = NSWorkspace.shared.runningApplications
|
|
|
|
let isRunning = !running.filter({$0.bundleIdentifier == mainAppIdentifier}).isEmpty
|
|
|
|
|
|
|
|
if isRunning {
|
|
|
|
self.terminate()
|
|
|
|
} else {
|
|
|
|
let killNotification = Notification.Name("killLauncher")
|
|
|
|
DistributedNotificationCenter.default().addObserver(self,
|
|
|
|
selector: #selector(self.terminate),
|
|
|
|
name: killNotification,
|
|
|
|
object: mainAppIdentifier)
|
|
|
|
let path = Bundle.main.bundlePath as NSString
|
|
|
|
var components = path.pathComponents
|
|
|
|
components.removeLast()
|
|
|
|
components.removeLast()
|
|
|
|
components.removeLast()
|
|
|
|
components.append("MacOS")
|
|
|
|
components.append("Rectangle")
|
|
|
|
let newPath = NSString.path(withComponents: components)
|
|
|
|
NSWorkspace.shared.launchApplication(newPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func terminate() {
|
|
|
|
NSApp.terminate(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|