Skip to content

Commit

Permalink
Scan and show status in progress bar on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
lexun committed Apr 25, 2015
1 parent 61fc063 commit 63d47a7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/launchpad.rb
@@ -1,6 +1,8 @@
require 'lib/launchpad/settings'
require 'lib/launchpad/patcher'
require 'lib/launchpad/index'
require 'lib/launchpad/gui/application'
require 'lib/launchpad/gui/controllers/update_manager'
require 'lib/launchpad/gui/controllers/main_controller'
require 'lib/launchpad/gui/controllers/options_controller'

Expand Down
9 changes: 9 additions & 0 deletions lib/launchpad/gui/controllers/main_controller.rb
Expand Up @@ -4,6 +4,15 @@ class MainController
include JRubyFX::Controller
fxml 'main.fxml'

attr_reader :update_manager, :status

def initialize
super

@update_manager = UpdateManager.new self
@stage.on_shown { update_manager.scan }
end

# Triggered when the options button is pressed
def show_options
@options ||=
Expand Down
25 changes: 25 additions & 0 deletions lib/launchpad/gui/controllers/update_manager.rb
@@ -0,0 +1,25 @@
module Launchpad
# Synchronizes the state of the patcher with the view
class UpdateManager
attr_reader :controller, :patcher

def initialize(controller)
@controller = controller
@patcher = Patcher.new
end

def scan
patcher.in_sync? ? ready_to_launch : ready_to_update
end

private

def ready_to_launch
controller.status.set_text 'Ready'
end

def ready_to_update
controller.status.set_text 'Update required...'
end
end
end
4 changes: 2 additions & 2 deletions lib/launchpad/gui/fxml/main.fxml
Expand Up @@ -12,7 +12,7 @@
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<AnchorPane prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<WebView prefHeight="350.0" />
<AnchorPane layoutY="350.0" prefHeight="46.0" prefWidth="800.0">
Expand All @@ -21,7 +21,7 @@
<Button layoutX="662.0" layoutY="11.0" mnemonicParsing="false" text="Scan" />
<Button layoutX="585.0" layoutY="11.0" mnemonicParsing="false" onAction="#show_options" text="Options" />
<ProgressBar layoutX="14.0" layoutY="11.0" prefHeight="27.0" prefWidth="559.0" progress="0.0" />
<Label layoutX="33.0" layoutY="17.0" text="Info" />
<Label fx:id="status" layoutX="33.0" layoutY="17.0" text="Info" />
</children>
</AnchorPane>
</children>
Expand Down
14 changes: 14 additions & 0 deletions lib/launchpad/patcher.rb
@@ -0,0 +1,14 @@
module Launchpad
# Updates installation directory with the required files
class Patcher
attr_reader :index

def initialize
@index = Index.new
end

def in_sync?
index.diff.empty?
end
end
end
21 changes: 20 additions & 1 deletion spec/lib/launchpad/gui/controllers/main_controller_spec.rb
Expand Up @@ -3,7 +3,26 @@
describe Launchpad::MainController, type: :controller do
subject { described_class.new stage: stage_double }

let(:stage_double) { double 'stage' }
let(:stage_double) { double 'stage', on_shown: true }

before { allow(Launchpad::UpdateManager).to receive :new }

describe '#initialize' do
let(:update_manager) { double 'update_manager' }

before do
allow(Launchpad::UpdateManager).to receive(:new).and_return update_manager
subject
end

it 'sets up an update manager' do
expect(subject.update_manager).to be update_manager
end

it 'sets up the on_shown hook' do
expect(stage_double).to have_received :on_shown
end
end

describe '#show_options' do
let(:options_stage) { double 'stage' }
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/launchpad/gui/controllers/update_manager_spec.rb
@@ -0,0 +1,30 @@
require 'spec_helper'

describe Launchpad::UpdateManager do
subject { described_class.new controller }

let(:controller) { double :controller, status: double(set_text: nil) }

before { allow(Launchpad::Patcher).to receive(:new).and_return patcher }

describe '#scan' do
before { subject.scan }

context 'when fils are in sync' do
let(:patcher) { double :patcher, in_sync?: true }

it 'displays a message that files are synced' do
expect(controller.status).to have_received(:set_text).with 'Ready'
end
end

context 'when fils are out of sync' do
let(:patcher) { double :patcher, in_sync?: false }

it 'displays a message that there are files that need syncing' do
expect(controller.status)
.to have_received(:set_text).with 'Update required...'
end
end
end
end
21 changes: 21 additions & 0 deletions spec/lib/launchpad/patcher_spec.rb
@@ -0,0 +1,21 @@
require 'spec_helper'

describe Launchpad::Patcher do
let(:index) { double :index }

before { allow(Launchpad::Index).to receive(:new).and_return index }

describe '#in_sync?' do
context 'when the index reports a diff' do
let(:index) { double diff: [:x, :y, :z] }

it { is_expected.to_not be_in_sync }
end

context 'when the index diff is empty' do
let(:index) { double diff: [] }

it { is_expected.to be_in_sync }
end
end
end

0 comments on commit 63d47a7

Please sign in to comment.