Skip to content

Commit

Permalink
Move update manager into main controller
Browse files Browse the repository at this point in the history
  • Loading branch information
lexun committed Apr 26, 2015
1 parent 8e93c76 commit 3940db9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 77 deletions.
1 change: 0 additions & 1 deletion lib/launchpad.rb
Expand Up @@ -2,7 +2,6 @@
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
30 changes: 24 additions & 6 deletions lib/launchpad/gui/controllers/main_controller.rb
@@ -1,20 +1,28 @@
module Launchpad
# Main application GUI controller
# Main application GUI controller.
class MainController
include JRubyFX::Controller
fxml 'main.fxml'

# @return [UpdateManager] manages client file scans and patches.
attr_reader :update_manager
# @return [Launchpad::Patcher]
attr_reader :patcher

# @return [Java::JavafxSceneControl::Label]
attr_reader :status

def initialize
super

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

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

# Triggered when the options button is pressed
# Triggered when the options button is pressed.
def show_options
@options ||=
stage title: 'Options',
Expand All @@ -26,5 +34,15 @@ def show_options

@options.show
end

private

def ready_to_launch
status.set_text 'Ready'
end

def ready_to_update
status.set_text 'Update required...'
end
end
end
25 changes: 0 additions & 25 deletions lib/launchpad/gui/controllers/update_manager.rb

This file was deleted.

55 changes: 42 additions & 13 deletions spec/lib/launchpad/gui/controllers/main_controller_spec.rb
@@ -1,23 +1,48 @@
require 'spec_helper'

describe Launchpad::MainController do
let(:patcher) { double 'patcher' }
let(:stage) { double 'stage', on_shown: true }
let(:status) { double 'status', set_text: nil }

before { allow(Launchpad::UpdateManager).to receive :new }
before do
allow(Launchpad::Patcher).to receive(:new).and_return patcher
allow(subject).to receive(:status).and_return status
end

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

it 'sets up an patcher' do
expect(subject.patcher).to be patcher
end

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

describe '#scan' do
before do
allow(Launchpad::UpdateManager).to receive(:new).and_return update_manager
subject
allow(Launchpad::Patcher).to receive(:new).and_return patcher
subject.scan
end

it 'sets up an update manager' do
expect(subject.update_manager).to be update_manager
context 'when files are in sync' do
let(:patcher) { double :patcher, in_sync?: true }

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

it 'sets up the on_shown hook' do
expect(stage_double).to have_received :on_shown
context 'when files 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(subject.status)
.to have_received(:set_text).with 'Update required...'
end
end
end

Expand Down Expand Up @@ -52,11 +77,15 @@
end

it 'sets the options stage attributes' do
expect(options_stage).to have_received(:title=).with 'Options'
expect(options_stage).to have_received(:always_on_top=).with true
expect(options_stage).to have_received(:resizable=).with false
expect(options_stage).to have_received(:x=).with 25
expect(options_stage).to have_received(:y=).with 45
options = { :title= => 'Options',
:always_on_top= => true,
:resizable= => false,
:x= => 25,
:y= => 45 }

options.each do |option, setting|
expect(options_stage).to have_received(option).with setting
end
end

it 'shows the options stage' do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/launchpad/gui/controllers/options_controller_spec.rb
Expand Up @@ -31,7 +31,7 @@
before { subject.accept }

it 'closes the stage' do
expect(stage_double).to have_received :close
expect(stage).to have_received :close
end

it 'updates all settings with values from the form' do
Expand All @@ -48,7 +48,7 @@
before { subject.cancel }

it 'closes the stage' do
expect(stage_double).to have_received :close
expect(stage).to have_received :close
end
end

Expand Down
30 changes: 0 additions & 30 deletions spec/lib/launchpad/gui/controllers/update_manager_spec.rb

This file was deleted.

0 comments on commit 3940db9

Please sign in to comment.