Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created January 30, 2010 04:19
Show Gist options
  • Save rjungemann/290406 to your computer and use it in GitHub Desktop.
Save rjungemann/290406 to your computer and use it in GitHub Desktop.
Run a thin server from a RubyCocoa app
# Start a thin server on the side, which can serve UI to the user in a
# WebView. That way you can make RubyCocoa UI with HTML, thanks to Sinatra.
require 'osx/cocoa'
OSX.require_framework 'WebKit'
class ThinDesktopController < OSX::NSObject
include OSX
ib_outlets :webView
ib_action :quitApp
def applicationDidFinishLaunching notification
@thin_path = "#{File.dirname(__FILE__)}/bin/thin"
@cfg_path = "#{File.dirname(__FILE__)}/config.ru"
@port = 4567
@page = "/gists/thefifthcircuit"
IO.popen("#{@thin_path} start -R #{@cfg_path} -p#{@port} -d") do |f|
puts f.gets
sleep 2
url = "http://localhost:#{@port}#{@page}"
request = NSURLRequest.requestWithURL(NSURL.URLWithString(url))
@webView.mainFrame.loadRequest(request)
end
end
def quitApp
IO.popen("#{@thin_path} stop -R #{@cfg_path} -p#{@port} -d") do
puts f.gets
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment