Skip to content

Commit

Permalink
fix helper indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tycobbb committed May 10, 2016
1 parent 117e69b commit 9a7c16c
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions HarborHelper/HarborHelper/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@ import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(aNotification: NSNotification) {
let app = NSWorkspace.sharedWorkspace().runningApplications.find { app in
return app.bundleIdentifier == "com.dvm.Harbor"
}

// if the app isn't running, then let's start it
if app == nil || !app!.active {
let path = self.applicationPath()
NSWorkspace.sharedWorkspace().launchApplication(path)
}

// kill the helper app
NSApp.terminate(nil)
func applicationDidFinishLaunching(aNotification: NSNotification) {
let app = NSWorkspace.sharedWorkspace().runningApplications.find { app in
return app.bundleIdentifier == "com.dvm.Harbor"
}

private func applicationPath() -> String {
var components = NSBundle.mainBundle().bundlePath.componentsSeparatedByString("/")

// helper is at "Library/LoginItems/HarborHelper" relative to the app root
components.removeRange(components.count-3..<components.count)
// and the main app is at "MacOS/Harbor"
components.appendContentsOf(["MacOS", "Harbor"])

return components.joinWithSeparator("/")

// if the app isn't running, then let's start it
if app == nil || !app!.active {
let path = self.applicationPath()
NSWorkspace.sharedWorkspace().launchApplication(path)
}


// kill the helper app
NSApp.terminate(nil)
}

private func applicationPath() -> String {
var components = NSBundle.mainBundle().bundlePath.componentsSeparatedByString("/")

// helper is at "Library/LoginItems/HarborHelper" relative to the app root
components.removeRange(components.count-3..<components.count)
// and the main app is at "MacOS/Harbor"
components.appendContentsOf(["MacOS", "Harbor"])

return components.joinWithSeparator("/")
}
}

extension SequenceType {

func find(predicate: (Generator.Element) -> Bool) -> Generator.Element? {
return self.filter(predicate).first
}

}
func find(predicate: (Generator.Element) -> Bool) -> Generator.Element? {
return self.filter(predicate).first
}
}

0 comments on commit 9a7c16c

Please sign in to comment.