macoscope / GrandCentralBoard

Hang a TV in your open space or team room to show everyone what's up and get them up to speed.
http://macoscope.com/blog/grand-central-board-for-the-apple-tv/
GNU General Public License v3.0
203 stars 16 forks source link

Grand Central Board for the Apple TV

image

Build Status Swift2.2 Version License Platform Documentation

Hang a TV in your open space or team room to show everyone what's up and get them up to speed.

The board is a lightweight piece of code. The TV screen is to be used in landscape orientation and will be split into six rectangular widgets loaded from a remote configuration file. This is just a UIView, so you can use the space in any way you want. Updating the widgets is standardized, though, therefore you should not ignore this convention.

đź‘· Project maintained by: @nsmeme (Oktawian Chojnacki)

✋ Don't even ask - it's obviously written entirely in ♥️ Swift 2.2.

GCBCore

The small set of sources needed to load configuration, initialize and show the Board.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

To integrate GCBCore into your Xcode project using CocoaPods, add this to your Podfile:

pod 'GCBCore', '~> 1.0'

Then, run the following command:

$ pod install

Usage

This is how you configure Grand Central Board:

let autoStack = AutoStack()
let scheduler = Scheduler()
let dataDownloader = DataDownloader()

let availableBuilders: [WidgetBuilding] = [
    ImageWidgetBuilder(dataDownloader: dataDownloader),
]

let configFileName = NSBundle.localConfigurationFileName
let configurationFetching = LocalConfigurationLoader(configFileName: configFileName,
                                                     availableBuilders: availableBuilders)

let boardController = GrandCentralBoardController(scheduler: self.scheduler, stack: self.autoStack)

let configurationRefresher = ConfigurationRefresher(interval: configRefreshInterval,
                                                    configuree: boardController,
                                                    fetcher: configurationFetching)

// in ViewController:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    view = autoStack

    configurationRefresher.start()
}

Contributing

If you want to contribute, please add an issue and discuss your plans with us. This will allow us to give you assistance should you need it and to make sure that people aren’t working on the same things.

If you want to open a Pull Request, make sure you have SwiftLint installed, and check that your project does not generate warnings or errors. Any warning will cause Travis build script to fail.

Widgets

Adding a new Widget

There is a separate article (TUTORIAL.md) covering adding new widgets.

Components

A Widget consists of four main components:

Size

Widget canvas for 1080p:

This size is constant and won't change on tvOS.

The GCBCore v2.0 will support iOS target but the canvas sizes are yet to be defined.

Configuration

There are two ways to configure Grand Central Board: with a remote or bundled configuration file. A JSON file formatted like this is used to configure the Grand Central Board:

{ "widgets":[ 
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} },
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} },
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} },
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} },
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} },
    {"name":"somewatch", "settings":  {"timeZone":"Europe/Warsaw"} }
]}

NOTE: Each widget will have its own settings properties.

The way a configuration file is loaded is specified in Info.plist file. image

Remote configuration file

To have the configuration file loaded from a remote location, edit Info.plist and set GCBRemoteConfigurationPath to the desired location. Make sure GCBAlwaysUseLocalConfigurationFile is set to NO.

Bundled configuration file

To use a bundled configuration file, set GCBAlwaysUseLocalConfigurationFile in Info.plist to YES. If necessary edit GCBLocalConfigurationFileName and check if the file is listed under Copy Bundle Resources in Build Phases. For development purposes you can also launch the application via GrandCentralBoard-LocalConfig scheme.

View States

Widget view should show these states:

Source

The source should implement one of two protocols:

protocol Synchronous : Source {
    func read() -> ResultType
}
protocol Asynchronous : Source {
    func read(closure: (ResultType) -> Void)
}
public protocol Subscribable : Source {
    var subscriptionBlock: ((ResultType) -> Void)? { get set }
}

Fail can be handled silently, but there may be Widgets for which the fail state should be presented, the choice is up to you.

All strategies inherit the Source protocol:

public enum SourceType {
    case Cumulative
    case Momentary
}

public protocol UpdatingSource : class {
    var interval: NSTimeInterval { get }
}

public protocol Source : UpdatingSource {

    associatedtype ResultType

    var sourceType: SourceType { get }
}

Credits