From 175dc9850d447aedaa824dca96ebcb82aec1569b Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Sat, 16 Jul 2016 13:36:24 -0700 Subject: [PATCH 1/9] only add fitbit dependencies if the user has fitbit in their config --- js/services/fitbit.js | 86 +++++++++++++++++++++---------------------- main.js | 5 ++- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/js/services/fitbit.js b/js/services/fitbit.js index edd1c5609..2c7f34c5b 100644 --- a/js/services/fitbit.js +++ b/js/services/fitbit.js @@ -1,10 +1,5 @@ (function() { 'use strict'; - - var express = require('express'); - var app = express(); - var fs = require( 'fs' ); - var Fitbit = require( 'fitbit-oauth2' ); function FitbitService($http) { @@ -56,53 +51,58 @@ var fitbit = {}; if (typeof config.fitbit != 'undefined') { fitbit = new Fitbit(config.fitbit); - } - // In a browser, http://localhost:4000/fitbit to authorize a user for the first time. - // - app.get('/fitbit', function (req, res) { - res.redirect(fitbit.authorizeURL()); - }); + var express = require('express'); + var app = express(); + var fs = require( 'fs' ); + var Fitbit = require( 'fitbit-oauth2' ); - // Callback service parsing the authorization token and asking for the access token. This - // endpoint is refered to in config.fitbit.authorization_uri.redirect_uri. See example - // config below. - // - app.get('/fitbit_auth_callback', function (req, res, next) { - var code = req.query.code; - fitbit.fetchToken( code, function(err, token) { - if (err) return next(err); + // In a browser, http://localhost:4000/fitbit to authorize a user for the first time. + // + app.get('/fitbit', function (req, res) { + res.redirect(fitbit.authorizeURL()); + }); - // persist the token - persist.write(tfile, token, function(err) { + // Callback service parsing the authorization token and asking for the access token. This + // endpoint is refered to in config.fitbit.authorization_uri.redirect_uri. See example + // config below. + // + app.get('/fitbit_auth_callback', function (req, res, next) { + var code = req.query.code; + fitbit.fetchToken( code, function(err, token) { if (err) return next(err); - res.redirect('/fb-profile'); - }); - }); - }); - // Call an API. fitbit.request() mimics nodejs request() library, automatically - // adding the required oauth2 headers. The callback is a bit different, called - // with ( err, body, token ). If token is non-null, this means a refresh has happened - // and you should persist the new token. - // - app.get( '/fb-profile', function(req, res, next) { - fitbit.request({ - uri: "https://api.fitbit.com/1/user/-/profile.json", - method: 'GET', - }, function(err, body, token) { - if (err) return next(err); - var profile = JSON.parse(body); - // if token is not null, a refesh has happened and we need to persist the new token - if (token) + // persist the token persist.write(tfile, token, function(err) { if (err) return next(err); - res.send('
' + JSON.stringify(profile, null, 2) + '
'); + res.redirect('/fb-profile'); }); - else - res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); + }); + + // Call an API. fitbit.request() mimics nodejs request() library, automatically + // adding the required oauth2 headers. The callback is a bit different, called + // with ( err, body, token ). If token is non-null, this means a refresh has happened + // and you should persist the new token. + // + app.get( '/fb-profile', function(req, res, next) { + fitbit.request({ + uri: "https://api.fitbit.com/1/user/-/profile.json", + method: 'GET', + }, function(err, body, token) { + if (err) return next(err); + var profile = JSON.parse(body); + // if token is not null, a refesh has happened and we need to persist the new token + if (token) + persist.write(tfile, token, function(err) { + if (err) return next(err); + res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); + else + res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); }); - }); + } // Only start up express and enable the fitbit service to start making API calls if the fitbit config is present in config.js. if (typeof config.fitbit != 'undefined') { diff --git a/main.js b/main.js index d02fa9a1b..cff2fa678 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,9 @@ const BrowserWindow = electron.BrowserWindow const powerSaveBlocker = electron.powerSaveBlocker powerSaveBlocker.start('prevent-display-sleep') +// Launching the mirror in dev mode +const DevelopmentMode = process.argv[2] == "dev"; + // Load the smart mirror config var config; try{ @@ -59,7 +62,7 @@ function createWindow () { mainWindow.loadURL('file://' + __dirname + '/index.html') // Open the DevTools if run with "npm start dev" - if(process.argv[2] == "dev"){ + if(DevelopmentMode){ mainWindow.webContents.openDevTools(); } From b12bfb6eca2acd7ae309a7610c261ad5a26672bc Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Sat, 16 Jul 2016 13:50:33 -0700 Subject: [PATCH 2/9] using ng-if for binding intensive elements. 7% perf improvement :smile: --- index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index a782fe506..a2247bce9 100644 --- a/index.html +++ b/index.html @@ -57,7 +57,7 @@
{{date.format('dddd')}}, {{date.format('LL')}}
{{date.format('LT')}}
-
    +
    • {{event.start.calendar() | uppercase}} @@ -143,7 +143,7 @@

      {{scTrack}}

-
+
{{timer.countdown | secondsToDateTime | date:"mm:ss"}}
{{timer.duration | secondsToDateTime | date:"mm:ss"}}
@@ -153,7 +153,7 @@

{{scTrack}}

-
+

{{ 'commands.title' | translate }}

{{command['text']}}
@@ -169,7 +169,7 @@

{{ 'commands.title' | translate }}

-
+
Source: {{news.title}}, Last Updated: {{news.lastUpdated.format('MMM DD, h:mm a')}} @@ -183,7 +183,7 @@

{{ 'commands.title' | translate }}

-
+
{{'fitbit.statsFor' | translate}} {{fbDailyAverage.fullName}}
{{'fitbit.averageSteps' | translate}}: {{fbDailyAverage.averageDailySteps}}
From ac225cf36de5e64243472ef7fbd9f2f6fc63167a Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Sat, 16 Jul 2016 14:27:28 -0700 Subject: [PATCH 3/9] improve performance of digest binding --- index.html | 61 ++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/index.html b/index.html index a2247bce9..54cf706b7 100644 --- a/index.html +++ b/index.html @@ -55,15 +55,15 @@
-
{{date.format('dddd')}}, {{date.format('LL')}}
-
{{date.format('LT')}}
+
,
+
  • - {{event.start.calendar() | uppercase}} -
    {{event.calendarName}}
    - {{event.SUMMARY}} -
    {{event.start.format('LLL')}}
    + +
    + +
@@ -73,20 +73,20 @@
- {{currentForecast.temperature}}° +
- {{minutelyForecast.summary}} - {{hourlyForecast.summary}} - {{weeklyForecast.summary}} + + +
- {{forecast.day}} + - {{forecast.temperatureMin}}° - {{forecast.temperatureMax}}° + +
@@ -96,23 +96,21 @@
- {{ 'traffic.time_to' | translate:traffic }} - {{traffic.duration.humanize()}} + +
- {{quote.resource.fields.issuer_name}}: ${{quote.resource.fields.price | number : 3}} + : $
-

{{greeting}}

-

{{user.name}}

- +

@@ -121,7 +119,7 @@

{{user.name}}

-

{{scTrack}}

+

@@ -134,19 +132,19 @@

{{scTrack}}

-
{{dilbert.title}}
+
  • - {{reminder}} +
-
{{timer.countdown | secondsToDateTime | date:"mm:ss"}}
-
{{timer.duration | secondsToDateTime | date:"mm:ss"}}
+
+
@@ -154,28 +152,23 @@

{{scTrack}}

-

{{ 'commands.title' | translate }}

+

-
{{command['text']}}
-
{{command['description']}}
+
+
Show my walking
Refreshes fitbit data.
- - We are using node , - Chrome , - and Electron . -
- Source: {{news.title}}, Last Updated: {{news.lastUpdated.format('MMM DD, h:mm a')}} + Source: , Last Updated:
- {{news.content}} +
From adff6384bd6cde13a5508e2fb8c9ff5e612b0a50 Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Sat, 16 Jul 2016 13:36:24 -0700 Subject: [PATCH 4/9] only add fitbit dependencies if the user has fitbit in their config --- js/services/fitbit.js | 86 +++++++++++++++++++++---------------------- main.js | 5 ++- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/js/services/fitbit.js b/js/services/fitbit.js index edd1c5609..2c7f34c5b 100644 --- a/js/services/fitbit.js +++ b/js/services/fitbit.js @@ -1,10 +1,5 @@ (function() { 'use strict'; - - var express = require('express'); - var app = express(); - var fs = require( 'fs' ); - var Fitbit = require( 'fitbit-oauth2' ); function FitbitService($http) { @@ -56,53 +51,58 @@ var fitbit = {}; if (typeof config.fitbit != 'undefined') { fitbit = new Fitbit(config.fitbit); - } - // In a browser, http://localhost:4000/fitbit to authorize a user for the first time. - // - app.get('/fitbit', function (req, res) { - res.redirect(fitbit.authorizeURL()); - }); + var express = require('express'); + var app = express(); + var fs = require( 'fs' ); + var Fitbit = require( 'fitbit-oauth2' ); - // Callback service parsing the authorization token and asking for the access token. This - // endpoint is refered to in config.fitbit.authorization_uri.redirect_uri. See example - // config below. - // - app.get('/fitbit_auth_callback', function (req, res, next) { - var code = req.query.code; - fitbit.fetchToken( code, function(err, token) { - if (err) return next(err); + // In a browser, http://localhost:4000/fitbit to authorize a user for the first time. + // + app.get('/fitbit', function (req, res) { + res.redirect(fitbit.authorizeURL()); + }); - // persist the token - persist.write(tfile, token, function(err) { + // Callback service parsing the authorization token and asking for the access token. This + // endpoint is refered to in config.fitbit.authorization_uri.redirect_uri. See example + // config below. + // + app.get('/fitbit_auth_callback', function (req, res, next) { + var code = req.query.code; + fitbit.fetchToken( code, function(err, token) { if (err) return next(err); - res.redirect('/fb-profile'); - }); - }); - }); - // Call an API. fitbit.request() mimics nodejs request() library, automatically - // adding the required oauth2 headers. The callback is a bit different, called - // with ( err, body, token ). If token is non-null, this means a refresh has happened - // and you should persist the new token. - // - app.get( '/fb-profile', function(req, res, next) { - fitbit.request({ - uri: "https://api.fitbit.com/1/user/-/profile.json", - method: 'GET', - }, function(err, body, token) { - if (err) return next(err); - var profile = JSON.parse(body); - // if token is not null, a refesh has happened and we need to persist the new token - if (token) + // persist the token persist.write(tfile, token, function(err) { if (err) return next(err); - res.send('
' + JSON.stringify(profile, null, 2) + '
'); + res.redirect('/fb-profile'); }); - else - res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); + }); + + // Call an API. fitbit.request() mimics nodejs request() library, automatically + // adding the required oauth2 headers. The callback is a bit different, called + // with ( err, body, token ). If token is non-null, this means a refresh has happened + // and you should persist the new token. + // + app.get( '/fb-profile', function(req, res, next) { + fitbit.request({ + uri: "https://api.fitbit.com/1/user/-/profile.json", + method: 'GET', + }, function(err, body, token) { + if (err) return next(err); + var profile = JSON.parse(body); + // if token is not null, a refesh has happened and we need to persist the new token + if (token) + persist.write(tfile, token, function(err) { + if (err) return next(err); + res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); + else + res.send('
' + JSON.stringify(profile, null, 2) + '
'); + }); }); - }); + } // Only start up express and enable the fitbit service to start making API calls if the fitbit config is present in config.js. if (typeof config.fitbit != 'undefined') { diff --git a/main.js b/main.js index fc990baf0..c79e3e659 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,9 @@ const BrowserWindow = electron.BrowserWindow const powerSaveBlocker = electron.powerSaveBlocker powerSaveBlocker.start('prevent-display-sleep') +// Launching the mirror in dev mode +const DevelopmentMode = process.argv[2] == "dev"; + // Load the smart mirror config var config; try{ @@ -59,7 +62,7 @@ function createWindow () { mainWindow.loadURL('file://' + __dirname + '/index.html') // Open the DevTools if run with "npm start dev" - if(process.argv[2] == "dev"){ + if(DevelopmentMode){ mainWindow.webContents.openDevTools(); } From 23814814d8d1a074e15494b0445feccec776e534 Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Thu, 21 Jul 2016 11:25:30 -0700 Subject: [PATCH 5/9] rebasing calendar fixes onto performance --- index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 1c10c075c..e3e5fb13b 100644 --- a/index.html +++ b/index.html @@ -149,7 +149,7 @@

{{scTrack}}

-
+
{{timer.countdown | secondsToDateTime | date:"mm:ss"}}
{{timer.duration | secondsToDateTime | date:"mm:ss"}}
@@ -159,7 +159,7 @@

{{scTrack}}

-
+

{{ 'commands.title' | translate }}

{{command['text']}}
@@ -175,7 +175,7 @@

{{ 'commands.title' | translate }}

-
+
Source: {{news.title}}, Last Updated: {{news.lastUpdated.format('MMM DD, h:mm a')}} @@ -189,8 +189,8 @@

{{ 'commands.title' | translate }}

-
-
+
+
{{'fitbit.statsFor' | translate}} {{fbDailyAverage.fullName}}
{{'fitbit.averageSteps' | translate}}: {{fbDailyAverage.averageDailySteps}}
{{'fitbit.todaysSteps' | translate}}: {{fbToday.summary.steps}}
From 56b2b2674bafb6c053f80dccb368057b89e98bbe Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Thu, 21 Jul 2016 11:33:27 -0700 Subject: [PATCH 6/9] using ng-bind for calendar --- index.html | 65 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/index.html b/index.html index e3e5fb13b..528036dcd 100644 --- a/index.html +++ b/index.html @@ -56,20 +56,20 @@
-
{{date.format('dddd')}}, {{date.format('LL')}}
-
{{date.format('LT')}}
+
,
+
  • - {{event.startName}} - - {{event.endName}} + + - -
    {{event.calendarName}}
    - {{event.SUMMARY}} +
    +
    - {{event.start.format('M/D')}} {{event.start.format('LT')}} - {{event.end.format('M/D')}} {{event.end.format('LT')}} - {{event.start.format('LT')}} - {{event.end.format('LT')}} + - + -
    All day
    @@ -81,20 +81,20 @@
    - {{currentForecast.temperature}}° +
    - {{minutelyForecast.summary}} - {{hourlyForecast.summary}} - {{weeklyForecast.summary}} + + +
    - {{forecast.day}} + - {{forecast.temperatureMin}}° - {{forecast.temperatureMax}}° + +
    @@ -104,21 +104,25 @@
- {{ 'traffic.time_to' | translate:traffic }} - {{traffic.duration.humanize()}} + +
- {{quote.resource.fields.issuer_name}}: ${{quote.resource.fields.price | number : 3}} + : $
+<<<<<<< 23814814d8d1a074e15494b0445feccec776e534

{{greeting}}

+======= +

+>>>>>>> improve performance of digest binding
@@ -127,7 +131,7 @@

{{greeting}}

-

{{scTrack}}

+

@@ -140,19 +144,19 @@

{{scTrack}}

-
{{dilbert.title}}
+
  • - {{reminder}} +
-
{{timer.countdown | secondsToDateTime | date:"mm:ss"}}
-
{{timer.duration | secondsToDateTime | date:"mm:ss"}}
+
+
@@ -160,28 +164,23 @@

{{scTrack}}

-

{{ 'commands.title' | translate }}

+

-
{{command['text']}}
-
{{command['description']}}
+
+
Show my walking
Refreshes fitbit data.
- - We are using node , - Chrome , - and Electron . -
- Source: {{news.title}}, Last Updated: {{news.lastUpdated.format('MMM DD, h:mm a')}} + Source: , Last Updated:
- {{news.content}} +
From d5254777aa8c13d81f39270a768b5480e9a83d53 Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Thu, 21 Jul 2016 11:41:22 -0700 Subject: [PATCH 7/9] replacing missing closing parenthasese --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index e90fba092..9ac3fc1e3 100644 --- a/index.html +++ b/index.html @@ -57,7 +57,7 @@
,
-
+
  • From 981fa4643c640ebcade2f2f38743b4d8d2e22a9e Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Thu, 21 Jul 2016 11:43:09 -0700 Subject: [PATCH 8/9] replacing missing closing parenthasese and bonus char --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 9ac3fc1e3..bd0198f0e 100644 --- a/index.html +++ b/index.html @@ -118,7 +118,7 @@
    -

    a +

    From af64530d82803e9d76df54865bb76a23295c9c48 Mon Sep 17 00:00:00 2001 From: Evan Cohen Date: Thu, 21 Jul 2016 11:57:30 -0700 Subject: [PATCH 9/9] lastfm config object should be optional --- js/controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/controller.js b/js/controller.js index 7b196966e..b867414d6 100644 --- a/js/controller.js +++ b/js/controller.js @@ -259,7 +259,7 @@ }); } - if(typeof config.lastfm.key !== 'undefined' && config.lastfm.user !== 'undefined'){ + if(typeof config.lastfm !== 'undefined' && typeof config.lastfm.key !== 'undefined' && config.lastfm.user !== 'undefined'){ registerRefreshInterval(getScrobblingTrack, config.lastfm.refreshInterval || 0.6) }