wow a ton of changes
This commit is contained in:
parent
2663880c85
commit
2232cbdd1e
BIN
assets/large-idle.png
Normal file
BIN
assets/large-idle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/large-paused.png
Normal file
BIN
assets/large-paused.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/large-working-1.png
Normal file
BIN
assets/large-working-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
BIN
assets/large-working-2.png
Normal file
BIN
assets/large-working-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/large.xcf
Normal file
BIN
assets/large.xcf
Normal file
Binary file not shown.
@ -5,11 +5,14 @@ require 'bundler/setup'
|
|||||||
require 'Qt4'
|
require 'Qt4'
|
||||||
require 'thread'
|
require 'thread'
|
||||||
require 'atomic'
|
require 'atomic'
|
||||||
|
require 'thor'
|
||||||
ENV['PROFILE'] ||= 'default'
|
|
||||||
|
|
||||||
class UnisonProfile
|
class UnisonProfile
|
||||||
def initialize(which = ENV['PROFILE'])
|
def self.process(profiles)
|
||||||
|
profiles.collect { |profile| new(profile) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(which)
|
||||||
@which = which
|
@which = which
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,6 +44,10 @@ class UnisonProfile
|
|||||||
@paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) }
|
@paths ||= lines.find_all { |line| line[%r{^path}] }.collect { |line| value_of(line) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def paths_with_local_root
|
||||||
|
paths.collect { |path| File.join(local_root, path) }
|
||||||
|
end
|
||||||
|
|
||||||
def value_of(line)
|
def value_of(line)
|
||||||
line[%r{=(.*)$}, 1].strip
|
line[%r{=(.*)$}, 1].strip
|
||||||
end
|
end
|
||||||
@ -51,10 +58,12 @@ class UnisonWatcher < Qt::Application
|
|||||||
SYNC_CHECK_COUNT = 600
|
SYNC_CHECK_COUNT = 600
|
||||||
SYNC_CHECK_TIME = 0.1
|
SYNC_CHECK_TIME = 0.1
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(profiles, *args)
|
||||||
super(*args)
|
super(*args)
|
||||||
|
|
||||||
|
@profiles = profiles
|
||||||
@queue = Atomic.new([])
|
@queue = Atomic.new([])
|
||||||
|
|
||||||
@sync_now = false
|
@sync_now = false
|
||||||
@exiting = false
|
@exiting = false
|
||||||
@active = true
|
@active = true
|
||||||
@ -64,8 +73,8 @@ class UnisonWatcher < Qt::Application
|
|||||||
@queue.update { |q| q += [ dirs ].flatten ; q }
|
@queue.update { |q| q += [ dirs ].flatten ; q }
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile
|
def processed_profiles
|
||||||
@profile ||= UnisonProfile.new
|
@processed_profiles ||= UnisonProfile.process(@profiles)
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch
|
def watch
|
||||||
@ -104,7 +113,7 @@ class UnisonWatcher < Qt::Application
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
watcher[:paths] = profile.paths.collect { |path| File.join(profile.local_root, path) }
|
watcher[:paths] = processed_profiles.collect(&:paths_with_local_root).flatten
|
||||||
watcher[:app] = self
|
watcher[:app] = self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -150,14 +159,15 @@ class UnisonWatcher < Qt::Application
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_ui
|
def update_ui
|
||||||
|
|
||||||
if @current_icon != @prior_icon
|
if @current_icon != @prior_icon
|
||||||
if !@icons[@current_icon]
|
if !@icons[@current_icon]
|
||||||
@icons[@current_icon] = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
|
@icons[@current_icon] = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
|
||||||
|
@icons["large-#{@current_icon}"] = Qt::Icon.new(File.expand_path("../../assets/large-#{@current_icon}.png", __FILE__))
|
||||||
end
|
end
|
||||||
|
|
||||||
@icon.icon = @icons[@current_icon]
|
@icon.icon = @icons[@current_icon]
|
||||||
@icon.toolTip = "Unison Agent\nUsing #{ENV['PROFILE']} profile"
|
self.windowIcon = @icons["large-#{@current_icon}"]
|
||||||
|
@icon.toolTip = "Unison Agent\nUsing #{@profiles.join(', ')} profile"
|
||||||
if !@prior_icon
|
if !@prior_icon
|
||||||
@icon.show
|
@icon.show
|
||||||
end
|
end
|
||||||
@ -175,6 +185,7 @@ class UnisonWatcher < Qt::Application
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ui
|
def ui
|
||||||
|
|
||||||
@icon = Qt::SystemTrayIcon.new
|
@icon = Qt::SystemTrayIcon.new
|
||||||
@icon.contextMenu = menu
|
@icon.contextMenu = menu
|
||||||
|
|
||||||
@ -182,8 +193,6 @@ class UnisonWatcher < Qt::Application
|
|||||||
@prior_icon = nil
|
@prior_icon = nil
|
||||||
@prior_text = nil
|
@prior_text = nil
|
||||||
|
|
||||||
s = nil
|
|
||||||
|
|
||||||
@icons = {}
|
@icons = {}
|
||||||
|
|
||||||
@remote_sync_check = SYNC_CHECK_COUNT
|
@remote_sync_check = SYNC_CHECK_COUNT
|
||||||
@ -198,6 +207,8 @@ class UnisonWatcher < Qt::Application
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
self.objectName = "cats"
|
||||||
|
|
||||||
watch
|
watch
|
||||||
ui
|
ui
|
||||||
end
|
end
|
||||||
@ -212,18 +223,20 @@ class UnisonWatcher < Qt::Application
|
|||||||
@done = false
|
@done = false
|
||||||
|
|
||||||
runner = Thread.new do
|
runner = Thread.new do
|
||||||
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
|
@profiles.each do |profile|
|
||||||
|
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{profile}'}
|
||||||
|
end
|
||||||
@done = true
|
@done = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
index = 0
|
||||||
while !@done
|
while !@done
|
||||||
@current_icon = 'working-1'
|
@current_icon = "working-#{index + 1}"
|
||||||
update_ui
|
update_ui
|
||||||
sleep 0.25
|
break if @done
|
||||||
|
|
||||||
@current_icon = 'working-2'
|
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
update_ui
|
index = (index + 1) % 2
|
||||||
end
|
end
|
||||||
|
|
||||||
@current_icon = 'idle'
|
@current_icon = 'idle'
|
||||||
@ -257,5 +270,18 @@ class UnisonWatcher < Qt::Application
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
UnisonWatcher.new(ARGV).start
|
class UnisonCLI < Thor
|
||||||
|
desc 'start profile <profile> ...', 'Run Unison Watch using the provided profiles'
|
||||||
|
def start(*profiles)
|
||||||
|
UnisonWatcher.new(profiles, ARGV).start
|
||||||
|
end
|
||||||
|
|
||||||
|
default_task :run
|
||||||
|
|
||||||
|
def method_missing(*args)
|
||||||
|
start(*args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
UnisonCLI.start
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user