Skip to content

Commit

Permalink
Scan in separate thread to avoid blocking UI
Browse files Browse the repository at this point in the history
  • Loading branch information
lexun committed May 2, 2015
1 parent 2ee5c89 commit 232ad90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/launchpad/gui/controllers/main_controller.rb
Expand Up @@ -19,7 +19,9 @@ def initialize

# Compares local and remote files and updates the UI accordingly.
def scan
patcher.in_sync? ? ready_to_launch : ready_to_update
Thread.new do
patcher.in_sync? ? ready_to_launch : ready_to_update
end
end

# Triggered when the options button is pressed.
Expand All @@ -38,11 +40,15 @@ def show_options
private

def ready_to_launch
status.set_text 'Ready'
Platform.run_later do
status.set_text 'Ready'
end
end

def ready_to_update
status.set_text 'Update required...'
Platform.run_later do
status.set_text 'Update required...'
end
end
end
end
3 changes: 3 additions & 0 deletions spec/lib/launchpad/gui/controllers/main_controller_spec.rb
Expand Up @@ -24,6 +24,9 @@

describe '#scan' do
before do
stub_const 'Platform', double
allow(Thread).to receive(:new).and_yield
allow(Platform).to receive(:run_later).and_yield
allow(Launchpad::Patcher).to receive(:new).and_return patcher
subject.scan
end
Expand Down

0 comments on commit 232ad90

Please sign in to comment.