diff --git a/launchers/macosx/StartupItemApp/AppDelegate.swift b/launchers/macosx/StartupItemApp/AppDelegate.swift new file mode 100644 index 0000000000..71b6002a4a --- /dev/null +++ b/launchers/macosx/StartupItemApp/AppDelegate.swift @@ -0,0 +1,54 @@ +// +// AppDelegate.swift +// StartupItemApp +// +// Created by Mikal Villa on 21/12/2018. +// Copyright © 2018 The I2P Project. All rights reserved. +// + +import Cocoa + +extension Notification.Name { + static let killLauncher = Notification.Name("killStartupLauncher") +} + +@NSApplicationMain +class AppDelegate: NSObject { + + @objc func terminate() { + NSApp.terminate(nil) + } +} + +extension AppDelegate: NSApplicationDelegate { + + func applicationDidFinishLaunching(_ aNotification: Notification) { + + let mainAppIdentifier = "net.i2p.bootstrap-macosx.I2PLauncher" + let runningApps = NSWorkspace.shared.runningApplications + let isRunning = !runningApps.filter { $0.bundleIdentifier == mainAppIdentifier }.isEmpty + + if !isRunning { + DistributedNotificationCenter.default().addObserver(self, + selector: #selector(self.terminate), + name: .killLauncher, + object: mainAppIdentifier) + + let path = Bundle.main.bundlePath as NSString + var components = path.pathComponents + components.removeLast() + components.removeLast() + components.removeLast() + components.append("MacOS") + components.append("I2PLauncher") //main app name + + let newPath = NSString.path(withComponents: components) + + NSWorkspace.shared.launchApplication(newPath) + } + else { + self.terminate() + } + } +} + diff --git a/launchers/macosx/StartupItemApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/launchers/macosx/StartupItemApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..2db2b1c7c6 --- /dev/null +++ b/launchers/macosx/StartupItemApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/launchers/macosx/StartupItemApp/Assets.xcassets/Contents.json b/launchers/macosx/StartupItemApp/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..da4a164c91 --- /dev/null +++ b/launchers/macosx/StartupItemApp/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/launchers/macosx/StartupItemApp/Info.plist b/launchers/macosx/StartupItemApp/Info.plist new file mode 100644 index 0000000000..d4bd41467b --- /dev/null +++ b/launchers/macosx/StartupItemApp/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2018 The I2P Project. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + LSBackgroundOnly + + + diff --git a/launchers/macosx/StartupItemApp/StartupItemApp.entitlements b/launchers/macosx/StartupItemApp/StartupItemApp.entitlements new file mode 100644 index 0000000000..7ba9c077ae --- /dev/null +++ b/launchers/macosx/StartupItemApp/StartupItemApp.entitlements @@ -0,0 +1,14 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.application-groups + + $(TeamIdentifierPrefix) + + com.apple.security.files.user-selected.read-only + + +