diff --git a/index.html b/index.html index 98061ac8f..57a3c05c5 100644 --- a/index.html +++ b/index.html @@ -56,20 +56,20 @@
' + 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(); }