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
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 'daemons'

View File

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