Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #147 from atdrago/feature/adam/auto-update
Browse files Browse the repository at this point in the history
Feature/adam/auto update
  • Loading branch information
atdrago authored Jun 14, 2016
2 parents da5c47b + 3425ded commit 9b14762
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
35 changes: 15 additions & 20 deletions lib/negative.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const {
ipcMain
} = require('electron');

const electronWindow = require('electron-window');
const path = require('path');
const objc = require('nodobjc');
const electronWindow = require('electron-window');
const path = require('path');
const objc = require('nodobjc');

const {
NEGATIVE_IGNORE_SETTINGS,
Expand Down Expand Up @@ -183,30 +183,25 @@ module.exports = {
},

initAutoUpdater() {
const appVersion = require('../package.json').version;
const appVersion = require('../package.json').version;
const shouldAutoUpdate = this.negativeSettings.get('shouldAutoUpdate');
const lastAutoUpdate = this.negativeSettings.get('lastAutoUpdate');
const nextAutoUpdate = this.negativeSettings.get('nextAutoUpdate');

autoUpdater.setFeedURL(`http://squirrel.negativeapp.com/update/darwin?zip=1&version=${appVersion}`);

if (shouldAutoUpdate) {
const now = Date.now();
const oneDay = 86400000;
const sevenDays = 604800000;
const now = Date.now();
let shouldCheckForUpdate = false;

// If we've never updated before, or it has been longer than 7 days
if (typeof lastAutoUpdate === 'undefined') {
shouldCheckForUpdate = true;
} else {
const delta = now - lastAutoUpdate;
if (delta >= sevenDays) {
shouldCheckForUpdate = true;
}
}

if (shouldCheckForUpdate) {
if (typeof nextAutoUpdate === 'undefined') {
// If we've never updated before, set nextAutoUpdate to tomorrow
// This gives the user enough time to opt out if they just downloaded
this.negativeSettings.set('nextAutoUpdate', now + oneDay);
} else if (now >= nextAutoUpdate) {
autoUpdater.checkForUpdates();
this.negativeSettings.set('lastAutoUpdate', now);
// Check again in 7 days
this.negativeSettings.set('nextAutoUpdate', now + sevenDays);
}
}

Expand Down Expand Up @@ -373,7 +368,7 @@ module.exports = {
acceptFirstMouse: true,
alwaysOnTop: true,
fullscreen: false,
height: 240,
height: 243,
resizable: false,
title: 'Negative - Preferences',
webPreferences: {
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
"license": "MIT",
"scripts": {
"start": "export NODE_ENV=development && export ELECTRON_ENABLE_LOGGING=true && export ELECTRON_ENABLE_STACK_DUMPING=true && export NEGATIVE_VERBOSE=true && electron .",

"prebuild": "rm -rf dist",
"build": "gulp release && mkdir -p ./release/node_modules && npm install --production --prefix ./release/ && gulp build",
"build-sign": "npm run build && ./scripts/sign-osx.sh",
"open": "open ./dist/Negative-darwin-x64/Negative.app",

"predmg": "npm run build-sign",
"dmg": "./scripts/dmg.sh",

"postinstall": "./node_modules/.bin/electron-rebuild",

"lint": "gulp js:lint",
"test": "mocha --recursive",
"travis": "npm run build-sign && npm test"
Expand Down Expand Up @@ -59,4 +55,4 @@
"os": [
"darwin"
]
}
}
2 changes: 1 addition & 1 deletion view/scss/_settings-window.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ legend {
}

a {
color: #08c;
color: #1a82fb;
text-decoration: none;
}

Expand Down
8 changes: 5 additions & 3 deletions view/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<fieldset>
<legend>Updates</legend>
<div class="form-group">
<label><input type="checkbox" id="shouldAutoUpdate" checked /> Automatically check for updates</label>
<label class="note" for="shouldAutoUpdate">At most, this will happen once per day.</label>
<label><input type="checkbox" id="shouldAutoUpdate" checked /> Automatically download and install updates</label>
<label class="note" for="shouldAutoUpdate">
If checked, updates will automatically be downloaded and installed every 7 days.
</label>
</div>
<div class="form-group">
<button id="checkForUpdates" type="button">Check Now</button>
<button id="checkForUpdates" type="button">Update Now</button>
<button id="restartAndInstall" class="primary hide" type="button">Restart and Install</button>
<img src="../resources/loading-indicator.gif" class="loading-indicator" id="checkForUpdatesLoadingIndicator" width="16" height="16" />
<label class="updates-label" id="checkForUpdatesLabel"></label>
Expand Down

0 comments on commit 9b14762

Please sign in to comment.