Repository navigation
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
50 lines (39 loc) · 1.61 KB
/
Copy pathAppDelegate.swift
File metadata and controls
50 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// AppDelegate.swift
// LauncherApplication
//
// Created by Thanh Nguyen on 1/28/19.
// Copyright © 2019 Dwarves Foundation. All rights reserved.
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@objc func terminate() {
NSApp.terminate(nil)
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
let mainAppIdentifier = "com.dwarvesv.minimalbar"
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == mainAppIdentifier }.isEmpty
if !isRunning {
DistributedNotificationCenter.default().addObserver(self,
selector: #selector(self.terminate),
name: Notification.Name("killLauncher"),
object: mainAppIdentifier)
let path = Bundle.main.bundlePath as NSString
var components = path.pathComponents
components.removeLast(3)
components.append("MacOS")
let appName = "Hidden Bar"
components.append(appName) //main app name
let newPath = NSString.path(withComponents: components)
NSWorkspace.shared.launchApplication(newPath)
}
else {
self.terminate()
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}