Skip to content

Commit

Permalink
Fix lots of trailing white space
Browse files Browse the repository at this point in the history
  • Loading branch information
johnste committed Jul 8, 2015
1 parent d3cc8c7 commit 4224acb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
38 changes: 19 additions & 19 deletions Finicky/Finicky/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!
@IBOutlet var statusItemMenu: NSMenu!

var statusItem: NSStatusItem!
var configLoader: FNConfigLoader!
var shortUrlResolver: FNShortUrlResolver!
var urlsToLoad = Array<String>()

static var defaultBrowser: String! = "com.google.Chrome"

func applicationDidFinishLaunching(aNotification: NSNotification) {
var bundleId = "net.kassett.Finicky"
LSSetDefaultHandlerForURLScheme("http", bundleId)
LSSetDefaultHandlerForURLScheme("https", bundleId)

var img: NSImage! = NSImage(named: "statusitem")
img.setTemplate(true)

let bar = NSStatusBar.systemStatusBar()
// Workaround for some bug: -1 instead of NSVariableStatusItemLength
statusItem = bar.statusItemWithLength(CGFloat(-1))
Expand All @@ -39,11 +39,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.image = img
toggleDockIcon(showIcon: false)
}

@IBAction func reloadConfig(sender: NSMenuItem) {
configLoader.reload()
}

@IBAction func showAboutPanel(sender: NSMenuItem) {
NSApp.orderFrontStandardAboutPanel(sender)
}
Expand All @@ -58,21 +58,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
return result
}

func handleGetURLEvent(event: NSAppleEventDescriptor?, withReplyEvent: NSAppleEventDescriptor?) {
var url : NSURL = NSURL(string: event!.paramDescriptorForKeyword(AEKeyword(keyDirectObject))!.stringValue!)!
let pid = event!.attributeDescriptorForKeyword(AEKeyword(keySenderPIDAttr))!.int32Value
let sourceBundleIdentifier = NSRunningApplication(processIdentifier: pid)?.bundleIdentifier

let callback = callUrlHandlers(sourceBundleIdentifier!)

if shortUrlResolver.isShortUrl(url) {
shortUrlResolver.resolveUrl(url, callback: callback)
} else {
callback(url: url)
}
}

func callUrlHandlers(sourceBundleIdentifier: String)(url: NSURL) {
let flags = getFlags()
var bundleIdentifier : String! = AppDelegate.defaultBrowser
Expand All @@ -81,27 +81,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let strategy = FinickyAPI.callUrlHandlers(newUrl, sourceBundleIdentifier: sourceBundleIdentifier, flags: flags)
if strategy["url"] != nil {
newUrl = NSURL(string: strategy["url"]!)!

let bundleId : String! = strategy["bundleIdentifier"] as String!

if bundleId != nil && !bundleId.isEmpty {
bundleIdentifier = strategy["bundleIdentifier"]!
}

if bundleIdentifier != nil && !bundleIdentifier.isEmpty {
openUrlWithBrowser(newUrl, bundleIdentifier:bundleIdentifier)
}
}
}

func openUrlWithBrowser(url: NSURL, bundleIdentifier: String) {
var eventDescriptor: NSAppleEventDescriptor? = NSAppleEventDescriptor()
var errorInfo : NSDictionary? = nil
var appleEventManager:NSAppleEventManager = NSAppleEventManager.sharedAppleEventManager()
var urls = [url]
NSWorkspace.sharedWorkspace().openURLs(urls, withAppBundleIdentifier: bundleIdentifier, options: NSWorkspaceLaunchOptions.Default, additionalEventParamDescriptor: nil, launchIdentifiers: nil)
}

func getFlags() -> Dictionary<String, Bool> {
return [
"cmd": NSEvent.modifierFlags() & .CommandKeyMask != nil,
Expand All @@ -110,16 +110,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
"alt": NSEvent.modifierFlags() & .AlternateKeyMask != nil
]
}

func applicationWillFinishLaunching(aNotification: NSNotification) {
configLoader = FNConfigLoader()
configLoader.reload()
shortUrlResolver = FNShortUrlResolver()

var appleEventManager:NSAppleEventManager = NSAppleEventManager.sharedAppleEventManager()
appleEventManager.setEventHandler(self, andSelector: "handleGetURLEvent:withReplyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

func applicationWillTerminate(aNotification: NSNotification) {
}
}
Expand Down
32 changes: 16 additions & 16 deletions Finicky/Finicky/FNAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ import JavaScriptCore
}

@objc class FinickyAPI : NSObject, FinickyAPIExports {

private static var urlHandlers = Array<JSValue>()

class func setDefaultBrowser(browser: String?) -> Void {
AppDelegate.defaultBrowser = browser
}

static func log(message: String?) -> Void {
if message != nil {
NSLog(message!)
}
}

class func onUrl(handler: JSValue) -> Void {
urlHandlers.append(handler)
}

class func reset() -> Void {
urlHandlers.removeAll(keepCapacity: true)
}

/**
Get strategy from registered handlers
@param originalUrl The original url that triggered finicky to start
@param sourceBundleIdentifier Bundle identifier of the application that triggered the url to open
@return A dictionary keyed with "url" and "bundleIdentifier" with
@return A dictionary keyed with "url" and "bundleIdentifier" with
the new url and bundle identifier to spawn
*/

Expand All @@ -53,12 +53,12 @@ import JavaScriptCore
"url": originalUrl.absoluteString!,
"bundleIdentifier": ""
]

var options : Dictionary<String, AnyObject> = [
"sourceBundleIdentifier": sourceBundleIdentifier,
"flags": flags
]

for handler in urlHandlers {
let url = strategy["url"]!
let val = handler.callWithArguments([url, options])
Expand All @@ -69,18 +69,18 @@ import JavaScriptCore
if handlerStrategy["url"] != nil {
strategy["url"] = (handlerStrategy["url"] as! String)
}

if handlerStrategy["bundleIdentifier"] != nil {
strategy["bundleIdentifier"] = (handlerStrategy["bundleIdentifier"] as! String)
}

if handlerStrategy["last"] != nil {
break
}
}
}
}
}
return strategy
}

}
24 changes: 12 additions & 12 deletions Finicky/Finicky/FNConfigLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import JavaScriptCore
var FNConfigPath: String = "~/.finicky.js"

class FNConfigLoader {

var configPaths: NSMutableSet;
var configWatcher: FNPathWatcher?;
var monitor : FNPathWatcher!;

init() {
self.configPaths = NSMutableSet()
}

func resetConfigPaths() {
FinickyAPI.reset()
configPaths.removeAllObjects()
configPaths.addObject(FNConfigPath)
}

func setupConfigWatcher() {

let url = NSURL(fileURLWithPath: FNConfigPath.stringByExpandingTildeInPath)!
Expand All @@ -35,34 +35,34 @@ class FNConfigLoader {
})
monitor.start()
}

func reload() {
self.resetConfigPaths()
var error:NSError?
let filename: String = FNConfigPath.stringByStandardizingPath
var config: String? = String(contentsOfFile: filename, encoding: NSUTF8StringEncoding, error: &error)

if config == nil {
println("Config file could not be read or found")
println("Config file could not be read or found")
return
}

if let theError = error {
print("\(theError.localizedDescription)")
}

var ctx: JSContext = JSContext()

ctx.exceptionHandler = {
context, exception in
println("JS Error: \(exception)")
}

self.setupAPI(ctx)
ctx.evaluateScript(config!)
setupConfigWatcher()
}

func setupAPI(ctx: JSContext) {
ctx.setObject(FinickyAPI.self, forKeyedSubscript: "api")
ctx.setObject(FinickyAPI.self, forKeyedSubscript: "finicky")
Expand Down
14 changes: 7 additions & 7 deletions Finicky/Finicky/FNPathWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import Foundation

public class FNPathWatcher {

enum State {
case On, Off
}

private let source: dispatch_source_t
private let descriptor: CInt
private var state: State = .Off

/// Creates a folder monitor object with monitoring enabled.
public init(url: NSURL, handler: ()->Void) {

state = .Off
descriptor = open(url.fileSystemRepresentation, O_EVTONLY)
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
Expand All @@ -35,23 +35,23 @@ public class FNPathWatcher {
//dispatch_source_set_cancel_handler({})
start()
}

/// Starts sending notifications if currently stopped
public func start() {
if state == .Off {
state = .On
dispatch_resume(source)
}
}

/// Stops sending notifications if currently enabled
public func stop() {
if state == .On {
state = .Off
dispatch_suspend(source)
}
}

deinit {
close(descriptor)
dispatch_source_cancel(source)
Expand Down

0 comments on commit 4224acb

Please sign in to comment.