Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #651 from OpenBazaar/fixAutoUpdate
Browse files Browse the repository at this point in the history
Patch for Auto Update
  • Loading branch information
rmisio authored Aug 17, 2017
2 parents 15c6862 + a797249 commit eb00aa8
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ deploy:
file:
- "dist/win32/*.exe"
- "dist/win32/*.nupkg"
- "dist/win32/RELEASES"
- "dist/win64/*.exe"
- "dist/win64/*.nupkg"
- "dist/win64/RELEASES-x64"
- "dist/osx/*.dmg"
- "dist/osx/*.zip"
- "dist/linux32/*.deb"
Expand Down
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ case "$TRAVIS_OS_NAME" in
echo 'Building Installer...'
grunt create-windows-installer --obversion=$PACKAGE_VERSION --appdir=dist/OpenBazaar2-win32-ia32 --outdir=dist/win32
mv dist/win32/OpenBazaar2Setup.exe dist/win32/OpenBazaar2-$PACKAGE_VERSION-Setup-32.exe
mv dist/win64/RELEASES dist/win32/RELEASES

echo 'Sign the installer'
signcode -t http://timestamp.digicert.com -a sha1 -spc .travis/ob1.cert.spc -pvk .travis/ob1.pvk -n "OpenBazaar $PACKAGE_VERSION" dist/win32/OpenBazaar2-$PACKAGE_VERSION-Setup-32.exe
Expand All @@ -168,6 +169,7 @@ case "$TRAVIS_OS_NAME" in
echo 'Building Installer...'
grunt create-windows-installer --obversion=$PACKAGE_VERSION --appdir=dist/OpenBazaar2-win32-x64 --outdir=dist/win64
mv dist/win64/OpenBazaar2Setup.exe dist/win64/OpenBazaar2-$PACKAGE_VERSION-Setup-64.exe
mv dist/win64/RELEASES dist/win64/RELEASES-x64

echo 'Sign the installer'
signcode -t http://timestamp.digicert.com -a sha1 -spc .travis/ob1.cert.spc -pvk .travis/ob1.pvk -n "OpenBazaar $PACKAGE_VERSION" dist/win64/OpenBazaar2-$PACKAGE_VERSION-Setup-64.exe
Expand Down
12 changes: 12 additions & 0 deletions js/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
"restartLater": "Restart Later",
"langChangeRestartTitle": "Restart needed for language change",
"langChangeRestartMessage": "In order for your language change to fully take effect, you must restart the app. If any saves or publishes are still in progress, please wait until they are done.",
"update": {
"checking": "Checking for updates.",
"error": "There was an error checking for updates. Error: %{error}",
"available": "An update is downloading now. You can choose to install it when the download is complete.",
"notAvailable": "No updates are available.",
"cancel": "Cancel",
"ready": {
"title": "The Update is Ready",
"msg": "Your update has downloaded. Click below to install it."
},
"install": "Install Now"
},
"addressBarPlaceholder": "Type a @handle, OpenBazaar ID or search term",
"testnet": "Test Mode",
"testnetTooltip": "Test Mode uses testnet coins, which are intended for testing purposes only.",
Expand Down
15 changes: 15 additions & 0 deletions js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import LocalSettings from './models/LocalSettings';
import ObRouter from './router';
import { getChatContainer, getBody } from './utils/selectors';
import { setFeedbackOptions, addFeedback } from './utils/feedback';
import { showUpdateStatus, updateReady } from './utils/autoUpdate';
import Chat from './views/chat/Chat.js';
import ChatHeads from './collections/ChatHeads';
import PageNav from './views/PageNav.js';
Expand Down Expand Up @@ -622,6 +623,20 @@ $(window).on('beforeunload', () => {
// Handle 'show debug log' requests from the main process.
ipcRenderer.on('show-server-log', () => launchDebugLogModal());

// Handle update events from main.js
ipcRenderer.on('updateChecking', () =>
showUpdateStatus(app.polyglot.t('update.checking'), 'pending'));
ipcRenderer.on('updateAvailable', () =>
showUpdateStatus(app.polyglot.t('update.available'), 'pending'));
ipcRenderer.on('updateNotAvailable', () =>
showUpdateStatus(app.polyglot.t('update.notAvailable')));
ipcRenderer.on('updateError', (e, msg) =>
showUpdateStatus(app.polyglot.t('update.error', { error: msg }), 'warning'));
ipcRenderer.on('updateReadyForInstall', (e, opts) => updateReady(opts));

// Allow main.js to send messages to the console
ipcRenderer.on('consoleMsg', (e, msg) => console.log(msg));

// manage publishing sockets
// todo: break the publishing socket startup functionality
// into its own micro-module in js/startup/
Expand Down
2 changes: 2 additions & 0 deletions js/templates/modals/about/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ <h2 id=tabTitle class="h3 clrT txCtr flexExpand"></h2>
<%= ob.polyT('about.bothVersions', { cVer: ob.version, sVer: ob.serverVersion }) %>
<% } %>
</div>
<% if (ob.isBundledApp) { %>
<a class="btn clrP clrBAttGrad clrBrDec1 clrTOnEmph js-checkForUpdate">
<%= ob.polyT('about.btnUpdateCheck') %>
</a>
<% } %>
</div>
</div>
<hr class="clrBr" />
Expand Down
56 changes: 56 additions & 0 deletions js/utils/autoUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import $ from 'jquery';
import { ipcRenderer } from 'electron';
import app from '../app';
import Dialog from '../views/modals/Dialog';

let statusMsg;
let removeStatusMsgTimout;

export function showUpdateStatus(status = '', type = 'message') {
clearTimeout(removeStatusMsgTimout);

if (!statusMsg) {
statusMsg = app.statusBar.pushMessage({
msg: status,
type,
duration: 9999999999,
});
} else {
statusMsg.update(status);
}

// updates may arrive multiple times, manually remove the message when no new message
// arrives for 6 seconds
removeStatusMsgTimout = setTimeout(() => {
statusMsg.remove();
statusMsg = null;
}, 6000);

return statusMsg;
}

let updateReadyDialog;

export function updateReady(opts = {}) {
if (updateReadyDialog) updateReadyDialog.close();

let displayData = '';
$.each(opts, (key, val) => {
displayData += `<b>${key}:</b> <br>${val}<br>`;
});

updateReadyDialog = new Dialog({
title: app.polyglot.t('update.ready.title'),
message: `${app.polyglot.t('update.ready.msg')}<br><br>${displayData}`,
buttons: [{
text: app.polyglot.t('update.install'),
fragment: 'installUpdate',
}, {
text: app.polyglot.t('update.cancel'),
fragment: 'cancelInstall',
}],
}).on('click-installUpdate', () => ipcRenderer.send('installUpdate'))
.on('click-cancelInstall', () => updateReadyDialog.close())
.render()
.open();
}
8 changes: 5 additions & 3 deletions js/views/modals/about/About.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { version } from '../../../../package.json';
import { remote, ipcRenderer } from 'electron';
import $ from 'jquery';
import app from '../../../app';
import loadTemplate from '../../../utils/loadTemplate';
Expand All @@ -7,7 +9,6 @@ import Contributors from './Contributors';
import Donations from './Donations';
import License from './License';
import BTCTicker from '../../BTCTicker';
import { version } from '../../../../package.json';

export default class extends BaseModal {
constructor(options = {}) {
Expand All @@ -28,6 +29,7 @@ export default class extends BaseModal {
};

this.currentTabName = 'Story';
this.isBundledApp = remote.getGlobal('isBundledApp')();
}

className() {
Expand Down Expand Up @@ -72,8 +74,7 @@ export default class extends BaseModal {
}

checkForUpdateClick() {
console.log('checking for an update');
// TODO: wire this in
ipcRenderer.send('checkForUpdate');
}

render() {
Expand All @@ -93,6 +94,7 @@ export default class extends BaseModal {
serverVersion,
...this.options,
version,
isBundledApp: this.isBundledApp,
}));
super.render();

Expand Down
122 changes: 74 additions & 48 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ let mainWindow;
let trayMenu;
let closeConfirmed = false;
const version = app.getVersion();
const feedURL = `https://updates2.openbazaar.org:5001/update/${process.platform}/${version}`;

function isOSWin64() {
return process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
}

const plat = process.platform === 'win32' ? `${isOSWin64() ? 'win64' : 'win32'}` : process.platform;

const feedURL = `https://updates2.openbazaar.org:5001/update/${plat}/${version}`;

global.serverLog = '';

const handleStartupEvent = function () {
Expand Down Expand Up @@ -85,6 +93,7 @@ if (handleStartupEvent()) {
console.log('OpenBazaar started on Windows...');
}


const serverPath = `${__dirname}${path.sep}..${path.sep}openbazaar-go${path.sep}`;
const serverFilename = process.platform === 'darwin' || process.platform === 'linux' ?
'openbazaard' : 'openbazaard.exe';
Expand Down Expand Up @@ -161,6 +170,41 @@ function preventWindowNavigation(win) {
}

function createWindow() {
// Check for updates an hour after the last check
let checkForUpdatesInterval;

const checkForUpdates = () => {
clearInterval(checkForUpdatesInterval);
autoUpdater.checkForUpdates();
checkForUpdatesInterval = setInterval(() => {
autoUpdater.checkForUpdates();
}, 60 * 60 * 1000);
};

let helpSubmenu = [
{
label: 'Documentation',
click() {
shell.openExternal('https://docs.openbazaar.org');
},
},
];

if (isBundledApp()) {
helpSubmenu = [
{
label: 'Check for Updates...',
click() {
checkForUpdates();
},
},
{
type: 'separator',
},
...helpSubmenu,
];
}

const template = [
{
label: 'Edit',
Expand Down Expand Up @@ -240,29 +284,7 @@ function createWindow() {
},
{
role: 'help',
submenu: [
// {
// label: 'Report Issue...',
// click() {
// // TODO: Open an issue tracking window
// },
// },
{
label: 'Check for Updates...',
click() {
autoUpdater.checkForUpdates();
},
},
{
type: 'separator',
},
{
label: 'Documentation',
click() {
shell.openExternal('https://docs.openbazaar.org');
},
},
],
submenu: helpSubmenu,
},
];

Expand Down Expand Up @@ -476,26 +498,24 @@ function createWindow() {
}
});

// Set up protocol
app.setAsDefaultProtocolClient('ob2');

// Check for URL hijacking in the browser
preventWindowNavigation(mainWindow);

/**
* For OS X users Squirrel manages the auto-updating code.
* If there is an update available then we will send an IPC message to the
* render process to notify the user. If the user wants to update
* the software then they will send an IPC message back to the main process and we will
* begin to download the file and update the software.
*/
if (process.platform === 'darwin') {
if (isBundledApp()) {
autoUpdater.on('checking-for-update', () => {
mainWindow.send('updateChecking');
mainWindow.send('consoleMsg', `Checking for update at ${autoUpdater.getFeedURL()}`);
});

autoUpdater.on('error', (err, msg) => {
console.log(msg);
mainWindow.send('consoleMsg', msg);
mainWindow.send('updateError', msg);
});

autoUpdater.on('update-not-available', (msg) => {
console.log(msg);
autoUpdater.on('update-not-available', () => {
mainWindow.send('updateNotAvailable');
});

Expand All @@ -504,12 +524,13 @@ function createWindow() {
});

autoUpdater.on('update-downloaded', (e, releaseNotes, releaseName,
releaseDate, updateUrl, quitAndUpdate) => {
// Old way of doing things
// mainWindow.webContents.executeJavaScript('$(".js-softwareUpdate")
// .removeClass("softwareUpdateHidden");');
console.log(quitAndUpdate);
mainWindow.send('updateReadyForInstall');
releaseDate, updateUrl) => {
const opts = {};
opts.Name = releaseName;
opts.URL = updateUrl;
opts.Date = releaseDate;
opts.Notes = releaseNotes;
mainWindow.send('updateReadyForInstall', opts);
});

// Listen for installUpdate command to install the update
Expand All @@ -519,17 +540,22 @@ function createWindow() {

// Listen for checkForUpdate command to manually check for new versions
ipcMain.on('checkForUpdate', () => {
autoUpdater.checkForUpdates();
checkForUpdates();
});

autoUpdater.setFeedURL(feedURL);

// Check for updates every hour
autoUpdater.checkForUpdates();
setInterval(() => {
autoUpdater.checkForUpdates();
}, 60 * 60 * 1000);
}

mainWindow.webContents.on('dom-ready', () => {
// Check for an update once the DOM is ready so the update dialog box can be shown
if (isBundledApp()) checkForUpdates();
});

// Set up protocol
app.setAsDefaultProtocolClient('ob2');

// Check for URL hijacking in the browser
preventWindowNavigation(mainWindow);
}

// This method will be called when Electron has finished
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "openbazaar-desktop",
"version": "2.0.6",
"productName": "OpenBazaar Desktop Client",
"version": "2.0.7",
"description": "Decentralized p2p marketplace for Bitcoin",
"main": "bootstrapper.js",
"scripts": {
Expand All @@ -25,7 +26,7 @@
"type": "git",
"url": "git+https://github.com/OpenBazaar/ob-desktop.git"
},
"author": "",
"author": "OB1",
"license": "MIT",
"bugs": {
"url": "https://github.com/OpenBazaar/ob-desktop/issues"
Expand Down

0 comments on commit eb00aa8

Please sign in to comment.