whoa it works better
This commit is contained in:
parent
773f5fdb1a
commit
fa5585fec5
135
bin/unison-watch
135
bin/unison-watch
@ -5,11 +5,9 @@ require 'bundler/setup'
|
|||||||
require 'Qt4'
|
require 'Qt4'
|
||||||
require 'thread'
|
require 'thread'
|
||||||
require 'atomic'
|
require 'atomic'
|
||||||
require 'daemons'
|
|
||||||
|
|
||||||
ENV['PROFILE'] ||= 'default'
|
ENV['PROFILE'] ||= 'default'
|
||||||
|
|
||||||
|
|
||||||
class UnisonProfile
|
class UnisonProfile
|
||||||
def initialize(which = ENV['PROFILE'])
|
def initialize(which = ENV['PROFILE'])
|
||||||
@which = which
|
@which = which
|
||||||
@ -108,92 +106,124 @@ class UnisonWatcher < Qt::Application
|
|||||||
watcher[:app] = self
|
watcher[:app] = self
|
||||||
end
|
end
|
||||||
|
|
||||||
def menu
|
def update_status(status)
|
||||||
menu = Qt::Menu.new
|
new_status = Qt::Action.new(status, @menu)
|
||||||
|
new_status.enabled = false
|
||||||
|
@menu.insertAction(@active_status, new_status)
|
||||||
|
@menu.removeAction(@status)
|
||||||
|
|
||||||
@status = Qt::Action.new("Unison watch idle.", menu)
|
@status = new_status
|
||||||
|
end
|
||||||
|
|
||||||
|
def menu
|
||||||
|
@menu = Qt::Menu.new
|
||||||
|
|
||||||
|
@current_text = 'Unison watch idle.'
|
||||||
|
|
||||||
|
@status = Qt::Action.new(@status_text, @menu)
|
||||||
@status.enabled = false
|
@status.enabled = false
|
||||||
|
|
||||||
sync_now = Qt::Action.new("Sync now", menu)
|
sync_now = Qt::Action.new("Sync now", @menu)
|
||||||
sync_now.connect(SIGNAL :triggered) { @sync_now = true }
|
sync_now.connect(SIGNAL :triggered) { @sync_now = true }
|
||||||
|
|
||||||
@active_status = Qt::Action.new("Pause syncing", menu)
|
@active_status = Qt::Action.new("Pause syncing", @menu)
|
||||||
@active_status.connect(SIGNAL :triggered) { toggle_status }
|
@active_status.connect(SIGNAL :triggered) { toggle_status }
|
||||||
|
|
||||||
@log = Qt::Action.new("View transfer log", menu)
|
@log = Qt::Action.new("View transfer log", @menu)
|
||||||
@log.connect(SIGNAL :triggered) { system %{open #{TRANSFER_LOG}} }
|
@log.connect(SIGNAL :triggered) { system %{open #{TRANSFER_LOG}} }
|
||||||
|
|
||||||
quit = Qt::Action.new("Quit", menu)
|
quit = Qt::Action.new("Quit", @menu)
|
||||||
quit.connect(SIGNAL :triggered) { @exiting = true }
|
quit.connect(SIGNAL :triggered) { @exiting = true }
|
||||||
|
|
||||||
menu.addAction @status
|
@menu.addAction @active_status
|
||||||
menu.addAction @active_status
|
@menu.addAction sync_now
|
||||||
menu.addAction sync_now
|
@menu.addSeparator
|
||||||
menu.addSeparator
|
@menu.addAction @log
|
||||||
menu.addAction @log
|
@menu.addAction quit
|
||||||
menu.addAction quit
|
|
||||||
|
|
||||||
menu
|
@current_text = 'Unison watch idle.'
|
||||||
|
update_status @current_text
|
||||||
|
|
||||||
|
@menu
|
||||||
end
|
end
|
||||||
|
|
||||||
def ui
|
def update_ui
|
||||||
icon = Qt::SystemTrayIcon.new
|
|
||||||
icon.contextMenu = menu
|
|
||||||
|
|
||||||
toggle_status true
|
|
||||||
@prior_icon = nil
|
|
||||||
|
|
||||||
while !@exiting
|
|
||||||
@log.enabled = File.file?(File.expand_path(TRANSFER_LOG))
|
|
||||||
|
|
||||||
if @current_icon != @prior_icon
|
if @current_icon != @prior_icon
|
||||||
icon.icon = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
|
if !@icons[@current_icon]
|
||||||
|
@icons[@current_icon] = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
|
||||||
if !@prior_icon
|
|
||||||
icon.show
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@icon.icon = @icons[@current_icon]
|
||||||
|
@icon.show if !@prior_icon
|
||||||
|
|
||||||
@prior_icon = @current_icon
|
@prior_icon = @current_icon
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @current_text!= @prior_text
|
||||||
|
update_status @current_text
|
||||||
|
|
||||||
|
@prior_text = @current_text
|
||||||
|
end
|
||||||
|
|
||||||
processEvents
|
processEvents
|
||||||
sleep 0.1
|
end
|
||||||
|
|
||||||
|
def ui
|
||||||
|
@icon = Qt::SystemTrayIcon.new
|
||||||
|
@icon.contextMenu = menu
|
||||||
|
|
||||||
|
toggle_status true
|
||||||
|
@prior_icon = nil
|
||||||
|
@prior_text = nil
|
||||||
|
|
||||||
|
s = nil
|
||||||
|
|
||||||
|
@icons = {}
|
||||||
|
|
||||||
|
@remote_sync_check = SYNC_CHECK_COUNT
|
||||||
|
|
||||||
|
while !@exiting
|
||||||
|
check
|
||||||
|
|
||||||
|
update_ui
|
||||||
|
|
||||||
|
sleep SYNC_CHECK_TIME
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
watch
|
watch
|
||||||
check
|
|
||||||
ui
|
ui
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
remote_sync_check = SYNC_CHECK_COUNT
|
|
||||||
|
|
||||||
Thread.new do
|
|
||||||
while true do
|
|
||||||
begin
|
begin
|
||||||
if @active && (@queue.value.length > 0 || remote_sync_check == 0 || @sync_now)
|
if @active && (@queue.value.length > 0 || @remote_sync_check == 0 || @sync_now)
|
||||||
dir = nil
|
dir = nil
|
||||||
|
|
||||||
@status.text = "Syncing..."
|
@current_text = "Syncing..."
|
||||||
|
|
||||||
animation = Thread.new do
|
@done = false
|
||||||
while !Thread.current[:done] do
|
|
||||||
|
runner = Thread.new do
|
||||||
|
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
|
||||||
|
@done = true
|
||||||
|
end
|
||||||
|
|
||||||
|
while !@done
|
||||||
@current_icon = 'working-1'
|
@current_icon = 'working-1'
|
||||||
|
update_ui
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
|
|
||||||
@current_icon = 'working-2'
|
@current_icon = 'working-2'
|
||||||
sleep 0.25
|
sleep 0.25
|
||||||
|
update_ui
|
||||||
end
|
end
|
||||||
|
|
||||||
@current_icon = 'idle'
|
@current_icon = 'idle'
|
||||||
end
|
|
||||||
|
|
||||||
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
|
@remote_sync_check = SYNC_CHECK_COUNT
|
||||||
|
|
||||||
animation[:done] = true
|
|
||||||
|
|
||||||
remote_sync_check = SYNC_CHECK_COUNT
|
|
||||||
@sync_now = false
|
@sync_now = false
|
||||||
@queue.update { [] }
|
@queue.update { [] }
|
||||||
end
|
end
|
||||||
@ -203,21 +233,14 @@ class UnisonWatcher < Qt::Application
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
remote_sync_check -= 1
|
@remote_sync_check -= 1
|
||||||
check_text = "Next check in #{sprintf("%.0d", SYNC_CHECK_TIME * remote_sync_check)} secs."
|
|
||||||
@status.text = check_text
|
|
||||||
|
|
||||||
if @active
|
if @active
|
||||||
sleep SYNC_CHECK_TIME
|
@current_text = "Next check in #{sprintf("%.0d", SYNC_CHECK_TIME * @remote_sync_check)} secs."
|
||||||
else
|
else
|
||||||
while !@active do
|
@current_text = "Syncing paused."
|
||||||
@status.text = "Syncing paused."
|
|
||||||
sleep SYNC_CHECK_TIME
|
|
||||||
end
|
|
||||||
|
|
||||||
remote_sync_check = SYNC_CHECK_COUNT
|
@remote_sync_check = SYNC_CHECK_COUNT
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user