Skip to content

Commit

Permalink
Merge branch 'consent' of https://github.com/FabMo/FabMo-Updater into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansturmer committed Nov 8, 2016
2 parents cf8605c + a52dfc7 commit 070fc49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
21 changes: 13 additions & 8 deletions beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ var Beacon = function(options) {
this.interval = options.interval || 1*60*60*1000;
this._timer = null;
this.running = false;
this.consent_for_beacon = "false";
}

function setURL(url) { this.set('url', url); }
function setInterval(interval) { this.set('interval', interval); }

// Changing any of the options provokes a new beacon report
Beacon.prototype.set = function(key, value) {
this[key] = value;
var wasRunning = this.running;
this.stop();
this[key] = value;
if(wasRunning) { this.run('config'); }
}

Expand All @@ -34,13 +35,17 @@ Beacon.prototype.start = function(reason) {

// Function called at intervals to report to the beacon
Beacon.prototype.run = function(reason) {
this.report(reason)
.catch(function(err) {
log.warn('Could not send a beacon message: ' + err);
})
.finally(function() {
this._timer = setTimeout(this.run.bind(this), this.interval);
}.bind(this));
if (this.consent_for_beacon === "true"){
this.report(reason)
.catch(function(err) {
log.warn('Could not send a beacon message: ' + err);
})
.finally(function() {
this._timer = setTimeout(this.run.bind(this), this.interval);
}.bind(this));
} else {
log.warn('Beacon is not enabled');
}
}

// Stops further beacon reports. Reports can be restarted with start()
Expand Down
1 change: 0 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ <h2>Configuration</h2>
<li>
<label class="settings" for="config-beacon_consent">Beacon Consent: </label>
<select class="config-input long" id="consent_for_beacon"/>
<option value="none">Not Answered</option>
<option value="true">True</option>
<option value="false">False</option>
</select>
Expand Down
16 changes: 12 additions & 4 deletions updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,20 @@ Updater.prototype.start = function(callback) {

function setup_config_events(callback) {
config.updater.on('change', function(evt) {

if(evt.packages_url) {
this.runAllPackageChecks();
}
if(evt.beacon_url) {
this.beacon.set(config.updater.get('beacon_url'));
this.beacon.set('url', config.updater.get('beacon_url'));
}
if(evt.name) {
this.beacon.once('config');
}
if (evt.consent_for_beacon) {
this.beacon.set("consent_for_beacon", evt.consent_for_beacon);
log.info("Consent for beacon is " + evt.consent_for_beacon);
}
}.bind(this));
callback();
}.bind(this),
Expand Down Expand Up @@ -635,7 +640,7 @@ Updater.prototype.start = function(callback) {
}
}.bind(this),

function start_beacon(callback) {
function start_beacon(callback) {
var url = config.updater.get('beacon_url');
var consent = config.updater.get('consent_for_beacon');

Expand All @@ -646,10 +651,13 @@ Updater.prototype.start = function(callback) {
});

if (consent === "true"){
this.beacon.start();
this.beacon.set("consent_for_beacon", consent);
log.info("Beacon is enabled");
} else if (consent === "false"){
log.error("Beacon is not consented to");
this.beacon.set("consent_for_beacon", consent);
log.info("Beacon is disabled");
}
this.beacon.start();
}.bind(this)
],
function(err, results) {
Expand Down

0 comments on commit 070fc49

Please sign in to comment.