Skip to content

Instantly share code, notes, and snippets.

@simongregory
Created April 4, 2011 14:02
Show Gist options
  • Save simongregory/901675 to your computer and use it in GitHub Desktop.
Save simongregory/901675 to your computer and use it in GitHub Desktop.
Utility class to help run melomel on Windows XP and OSX
module Project
class << self
def on_windows?
RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin/i
end
def adl
tool = "#{ENV['FLEX_HOME']}/bin/adl"
tool = "#{tool}.exe" if on_windows?
tool
end
def app_descriptor
'bin-debug/Desktop-app.xml'
end
end
end
module Runner
@@runner = nil
def self.start
@@runner = make if @@runner.nil?
@@runner.start
end
def self.stop
@@runner = make if @@runner.nil?
@@runner.stop
end
private
def self.make
return Windoze.new if Project.on_windows?
Unix.new
end
class Windoze
WM_DESTROY = 0x0002
AIR_WINDOW = "ApolloRuntimeContentWindow"
def initialize
require 'Win32API'
@shell = Win32API.new('shell32', 'ShellExecute', 'LPPPPI', 'L')
@find = Win32API.new('user32', 'FindWindow', 'PP', 'L')
@send = Win32API.new('user32', 'SendMessage', 'LILL', 'L')
end
def start
# Double check adl etc exist so we can fail and warn users properly.
raise "Error with path to adl: #{Project.adl}" unless File.exists? Project.adl
raise raise "Error with path to app_descriptor: #{Project.app_descriptor}" unless File.exists? Project.app_descriptor
unless @shell.call(0, 'open', Project.adl, Project.app_descriptor, '', 1) > 0
raise "ShellExecute failed"
end
end
def stop
#Close the main window
window = @find.call(AIR_WINDOW, "BBC iPlayer Desktop")
@send.call(window, WM_DESTROY, 0, 0) if window > 0
#Mop up toaster window (if required)
window = @find.call(AIR_WINDOW, 0)
@send.call(window, WM_DESTROY, 0, 0) if window > 0
end
end
class Unix
def start
@pid = fork do
exec("#{Project.adl} #{Project.app_descriptor}")
end
Process.detach(@pid)
end
def stop
Process.kill('KILL', @pid)
end
end
end
Before do |scenario|
ConfigureIPD.as_normal if !custom_configuration
Runner.start
Melomel.connect
end
@theDon
Copy link

theDon commented May 4, 2011

Hi Simon, can you please provide the Project class.

@theDon
Copy link

theDon commented May 4, 2011

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment