diff --git a/Stats.xcodeproj/project.pbxproj b/Stats.xcodeproj/project.pbxproj index 0ea8ea34..7b8ed577 100755 --- a/Stats.xcodeproj/project.pbxproj +++ b/Stats.xcodeproj/project.pbxproj @@ -261,7 +261,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1010; - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = "Serhiy Mytrovtsiy"; TargetAttributes = { 9A1410F4229E721100D29793 = { @@ -486,6 +486,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "Stats/Supporting Files/Stats.entitlements"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = RP2S87B72W; @@ -508,6 +509,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "Stats/Supporting Files/Stats.entitlements"; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = RP2S87B72W; @@ -529,6 +531,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = StatsLauncher/StatsLauncher.entitlements; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; @@ -552,6 +555,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = StatsLauncher/StatsLauncher.entitlements; + CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; diff --git a/Stats.xcodeproj/xcshareddata/xcschemes/Stats.xcscheme b/Stats.xcodeproj/xcshareddata/xcschemes/Stats.xcscheme index 12bafd39..b0eb1edf 100644 --- a/Stats.xcodeproj/xcshareddata/xcschemes/Stats.xcscheme +++ b/Stats.xcodeproj/xcshareddata/xcschemes/Stats.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - = Observable([CPU(), Memory(), Disk()]) let colors: Observable = Observable(true) @@ -24,6 +29,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { colors << (defaults.object(forKey: "colors") != nil ? defaults.bool(forKey: "colors") : false) _ = MenuBar(menuBarItem, menuBarButton: menuBarButton) + + let launcherAppId = "eu.exelban.Stats" + let runningApps = NSWorkspace.shared.runningApplications + let isRunning = !runningApps.filter { $0.bundleIdentifier == launcherAppId }.isEmpty + + if isRunning { + DistributedNotificationCenter.default().post(name: .killLauncher, object: Bundle.main.bundleIdentifier!) + } } func applicationWillTerminate(_ aNotification: Notification) { diff --git a/Stats/libs/Module.swift b/Stats/libs/Module.swift index f4389b67..9b646abe 100644 --- a/Stats/libs/Module.swift +++ b/Stats/libs/Module.swift @@ -19,7 +19,7 @@ protocol Module { func stop() } -extension Module where Self: Module { +extension Module { func stop() { self.reader.stop() self.reader.usage.unsubscribe(observer: self as AnyObject) diff --git a/StatsLauncher/AppDelegate.swift b/StatsLauncher/AppDelegate.swift index 136123af..fee14155 100644 --- a/StatsLauncher/AppDelegate.swift +++ b/StatsLauncher/AppDelegate.swift @@ -7,7 +7,6 @@ // import Cocoa -import os.log extension Notification.Name { static let killLauncher = Notification.Name("killLauncher") @@ -26,28 +25,18 @@ class AppDelegate: NSObject, NSApplicationDelegate { selector: #selector(self.terminate), name: .killLauncher, object: mainAppIdentifier) - - let path = Bundle.main.bundlePath as NSString - var components = path.pathComponents - components.removeLast(3) - components.append("MacOS") - components.append("Stats") - - let newPath = NSString.path(withComponents: components) - NSWorkspace.shared.launchApplication(newPath) + var path = Bundle.main.bundlePath as NSString + for _ in 1...4 { + path = path.deletingLastPathComponent as NSString + } + NSWorkspace.shared.launchApplication(path as String) } else { self.terminate() } } - - func applicationWillTerminate(_ aNotification: Notification) { - // Insert code here to tear down your application - } - - + @objc func terminate() { - os_log("WTF") NSApp.terminate(nil) } }