Skip to content

Commit

Permalink
Open external links in default web browser
Browse files Browse the repository at this point in the history
  • Loading branch information
John W. Long committed Dec 12, 2014
1 parent 17f05f9 commit 6cfbad9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Trello/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
webView.policyDelegate = self
goHome(self)
}

Expand All @@ -26,8 +27,31 @@ class ViewController: NSViewController {
webView.reload(self)
}

func loadUrl(url:NSString) {
func loadUrl(url:String) {
webView.mainFrameURL = url
}

func loadExternalUrl(url:String) {
NSWorkspace.sharedWorkspace().openURL(NSURL(string: url)!)
}

override func webView(sender: WebView!, decidePolicyForNavigationAction actionInformation: [NSObject : AnyObject]!, request: NSURLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!) {
if (sender.isEqual(webView)) {
listener.use()
} else {
let index = actionInformation.indexForKey(WebActionOriginalURLKey)!
let pair = actionInformation[index]
let url = pair.1.debugDescription! // TODO: Figure out how to convert this into a string properly
loadExternalUrl(url)
listener.ignore()
}
}

override func webView(webView: WebView!, decidePolicyForNewWindowAction actionInformation: [NSObject : AnyObject]!, request: NSURLRequest!, newFrameName frameName: String!, decisionListener listener: WebPolicyDecisionListener!) {
let index = actionInformation.indexForKey(WebActionOriginalURLKey)!
let pair = actionInformation[index]
let url = pair.1.debugDescription! // TODO: Figure out how to convert this into a string properly
loadExternalUrl(url)
listener.ignore()
}
}

0 comments on commit 6cfbad9

Please sign in to comment.