Skip to content

Commit

Permalink
update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Apr 30, 2014
1 parent ab72cb0 commit e75ccff
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ module.exports = (grunt) ->
devbuild:
command: "./scripts/devbuild"

devbuildwatch:
command: "./scripts/devbuildwatch"

compress:
mac:
options:
Expand Down
3 changes: 2 additions & 1 deletion lib/boot_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ AppInjector
.value('nwgui', require('nw.gui'))
.value('smCore', require('subtitle-master'))
.value('request', require('request'))
.value('os', require('os'));
.value('os', require('os'))
.value('semver', require('semver'));

AppInjector.call(function (SubtitleMaster, SearchController, React, nwgui, _) {
window.React = React;
Expand Down
1 change: 1 addition & 0 deletions lib/injector.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ injector.factory('ExternalLink', require('./jsx/components/external-link.jsx'))
injector.factory('MultiPage', require('./jsx/components/multipage.jsx'))
injector.factory('MultiSelect', require('./jsx/components/multiselect.jsx'))
injector.factory('FileDropper', require('./jsx/components/file_dropper.jsx'))
injector.factory('Updater', require('./jsx/components/updater.jsx'))

# pages
injector.factory('SearchPage', require('./jsx/pages/search-page.jsx'))
Expand Down
6 changes: 6 additions & 0 deletions lib/integration/browser/sm.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ module.exports = (_, W) ->
setTimeout ->
resolve(null)
, 100

checkForUpdates: ->
W.promise (resolve) ->
setTimeout ->
resolve(!!(_.random(0, 1)))
, 2000
8 changes: 7 additions & 1 deletion lib/integration/node_webkit/sm.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (smCore, W, localStorage, SettingsController) ->
module.exports = (smCore, W, localStorage, SettingsController, request, nodefn, semver, pkg) ->
key = (hash) -> "upload-cache-#{hash}"

localCache =
Expand All @@ -10,3 +10,9 @@ module.exports = (smCore, W, localStorage, SettingsController) ->
operation.run()

scanPath: (path) -> smCore.VideoScan([path])

checkForUpdates: ->
nodefn.call(request, pkg.latestJson).then ([res, body]) ->
json = JSON.parse(body)

semver.gt(json.version, pkg.version)
34 changes: 34 additions & 0 deletions lib/jsx/components/updater.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** @jsx React.DOM */

module.exports = function (ExternalLink, sm, React) {
return React.createClass({
displayName: 'Updater',

getInitialState: function () {
return {
hasUpdate: false
};
},

componentDidMount: function () {
var _this = this;

sm.checkForUpdates().done(function (hasUpdates) {
_this.setState({hasUpdate: hasUpdates});
});
},

render: function () {
var classNames = React.addons.classSet({
notification: true,
active: this.state.hasUpdate
});

return (
<ExternalLink href="http://www.subtitlemaster.com/" className={classNames}>
<div>Atualização disponível! Clique aqui para baixar a versão mais recente.</div>
</ExternalLink>
);
}
});
};
3 changes: 2 additions & 1 deletion lib/jsx/subtitle-master.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsx React.DOM */

module.exports = function (track, SearchController, SearchPage, SettingsPage, ExternalLink, MultiPage, React) {
module.exports = function (track, SearchController, SearchPage, SettingsPage, ExternalLink, MultiPage, Updater, React) {
track.screen('search');

SearchController.addEventListener('search-completed', function (search) {
Expand Down Expand Up @@ -41,6 +41,7 @@ module.exports = function (track, SearchController, SearchPage, SettingsPage, Ex
render: function () {
return (
<div className="app-container flex-column">
<Updater />
<hr className="filmstrip shadow-down" />
<MultiPage className="flex flex-row auto-scroll" selected={this.state.selectedPage}>
<SearchPage page="search" />
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"author": "Wilker Lucio <[email protected]>",
"license": "MIT",
"latestJson": "https://raw.githubusercontent.com/subtitle-master/subtitlemaster/latest/package.json",
"dependencies": {
"subtitle-master": "2.0.0-beta1",
"inject-it": "~1.2.0",
Expand Down Expand Up @@ -44,6 +45,7 @@
"grunt-contrib-copy": "~0.5.0",
"grunt-json-massager": "~0.1.0",
"grunt-contrib-clean": "~0.5.0",
"load-grunt-tasks": "~0.4.0"
"load-grunt-tasks": "~0.4.0",
"semver": "~2.2.1"
}
}
24 changes: 23 additions & 1 deletion stylesheets/app.styl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ h1
overflow: auto

.shadow-down
box-shadow: 0px 1px 4px 0px rgba(#000, .5)
box-shadow: 0px 2px 3px 0px rgba(#000, .5)

.shadow-up
box-shadow: 0px -1px 4px 0px rgba(#000, .5)
Expand Down Expand Up @@ -175,5 +175,27 @@ h1
select
width: 160px

.notification
background: #2d2d2d
color: white
cursor: pointer
font-weight: bold
height: 0
overflow: hidden
text-align: center
text-decoration: none
transition: all 300ms

display: flex
align-items: center
flex-direction: column
justify-content: center

> div
cursor: pointer

&.active
height: 60px

.dragging
background-image: -webkit-radial-gradient(49% -6%, #4960d4 5%, #273473 100%)

0 comments on commit e75ccff

Please sign in to comment.