Skip to content

Commit

Permalink
consent totally working
Browse files Browse the repository at this point in the history
  • Loading branch information
wholetthedogsout committed Nov 8, 2016
1 parent 3cf9c7f commit a52dfc7
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 @@ -589,15 +589,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 @@ -628,7 +633,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 @@ -639,10 +644,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 a52dfc7

Please sign in to comment.