cross platform

This commit is contained in:
John Bintz 2012-05-02 22:54:11 -04:00
parent 9be434c7c0
commit 0a380c6af0
2 changed files with 29 additions and 8 deletions

10
Gemfile
View File

@ -1,7 +1,15 @@
source :rubygems source :rubygems
gem 'qtbindings' gem 'qtbindings'
gem 'rb-fsevent' require 'rbconfig'
case RbConfig::CONFIG['host_os']
when /darwin/
gem 'rb-fsevent'
when /linux/
gem 'rb-inotify'
end
gem 'atomic' gem 'atomic'
gem 'daemons' gem 'daemons'

View File

@ -3,15 +3,12 @@
require 'bundler/setup' require 'bundler/setup'
require 'Qt4' require 'Qt4'
require 'rb-fsevent'
require 'thread' require 'thread'
require 'atomic' require 'atomic'
require 'daemons' require 'daemons'
ENV['PROFILE'] ||= 'default' ENV['PROFILE'] ||= 'default'
TRANSFER_LOG = '~/unison.log' TRANSFER_LOG = '~/unison.log'
SYNC_CHECK_COUNT = 600 SYNC_CHECK_COUNT = 600
SYNC_CHECK_TIME = 0.1 SYNC_CHECK_TIME = 0.1
@ -46,7 +43,7 @@ def check
@current_icon = 'idle' @current_icon = 'idle'
end end
system %{bash -c 'unison -batch default'} system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
animation[:done] = true animation[:done] = true
@ -94,15 +91,31 @@ class UnisonProfile
end end
profile = UnisonProfile.new profile = UnisonProfile.new
require 'rbconfig'
watcher = Thread.new do watcher = Thread.new do
while !Thread.current[:app]; sleep 0.1; end while !Thread.current[:app]; sleep 0.1; end
begin begin
watch = nil
case RbConfig::CONFIG['host_os']
when /darwin/
require 'rb-fsevent'
watch = FSEvent.new watch = FSEvent.new
watch.watch Thread.current[:paths], :latency => 0.25 do |directories| watch.watch Thread.current[:paths], :latency => 0.25 do |directories|
Thread.current[:app] << directories Thread.current[:app] << directories
end end
when /linux/
require 'rb-inotify'
watch = INotify::Notifier.new
Thread.current[:paths].each do |path|
notifier.watch path, :recursive, :modify, :create, :delete do |event|
Thread.current[:app] << event.absolute_name
end
end
end
watch.run watch.run
rescue => e rescue => e
puts e.message puts e.message