Created
January 6, 2012 21:13
-
-
Save andrewhavens/1572433 to your computer and use it in GitHub Desktop.
MacRuby web browser, needs links to open default browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework "WebKit" | |
class AppDelegate | |
attr_accessor :window | |
def applicationDidFinishLaunching(notification) | |
load_web_view | |
end | |
def load_web_view | |
web_view = WebView.new | |
request = NSURLRequest.requestWithURL(NSURL.URLWithString("http://example.com")) | |
web_view.mainFrame.loadRequest(request) | |
window.contentView = web_view | |
web_view.frameLoadDelegate = self | |
web_view.setPolicyDelegate(self) # so each link click calls the following method | |
end | |
# this is supposed to make it so links open in the default browser | |
def webView(view, decidePolicyForNavigationAction:actionInformation, request:request, frame:frame, decisionListener:listener) | |
puts 'running nav policy' | |
listener.ignore | |
NSWorkspace.sharedWorkspace.openURL(request.URL) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment