Skip to content

Instantly share code, notes, and snippets.

@andrewhavens
Created January 6, 2012 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhavens/1572433 to your computer and use it in GitHub Desktop.
Save andrewhavens/1572433 to your computer and use it in GitHub Desktop.
MacRuby web browser, needs links to open default browser
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