Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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