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

Commit eb00aa8

Browse files
authored
Merge pull request #651 from OpenBazaar/fixAutoUpdate
Patch for Auto Update
2 parents 15c6862 + a797249 commit eb00aa8

File tree

9 files changed

+171
-53
lines changed

9 files changed

+171
-53
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ deploy:
2525
file:
2626
- "dist/win32/*.exe"
2727
- "dist/win32/*.nupkg"
28+
- "dist/win32/RELEASES"
2829
- "dist/win64/*.exe"
2930
- "dist/win64/*.nupkg"
31+
- "dist/win64/RELEASES-x64"
3032
- "dist/osx/*.dmg"
3133
- "dist/osx/*.zip"
3234
- "dist/linux32/*.deb"

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ case "$TRAVIS_OS_NAME" in
143143
echo 'Building Installer...'
144144
grunt create-windows-installer --obversion=$PACKAGE_VERSION --appdir=dist/OpenBazaar2-win32-ia32 --outdir=dist/win32
145145
mv dist/win32/OpenBazaar2Setup.exe dist/win32/OpenBazaar2-$PACKAGE_VERSION-Setup-32.exe
146+
mv dist/win64/RELEASES dist/win32/RELEASES
146147

147148
echo 'Sign the installer'
148149
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
@@ -168,6 +169,7 @@ case "$TRAVIS_OS_NAME" in
168169
echo 'Building Installer...'
169170
grunt create-windows-installer --obversion=$PACKAGE_VERSION --appdir=dist/OpenBazaar2-win32-x64 --outdir=dist/win64
170171
mv dist/win64/OpenBazaar2Setup.exe dist/win64/OpenBazaar2-$PACKAGE_VERSION-Setup-64.exe
172+
mv dist/win64/RELEASES dist/win64/RELEASES-x64
171173

172174
echo 'Sign the installer'
173175
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

js/languages/en-US.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
"restartLater": "Restart Later",
1515
"langChangeRestartTitle": "Restart needed for language change",
1616
"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.",
17+
"update": {
18+
"checking": "Checking for updates.",
19+
"error": "There was an error checking for updates. Error: %{error}",
20+
"available": "An update is downloading now. You can choose to install it when the download is complete.",
21+
"notAvailable": "No updates are available.",
22+
"cancel": "Cancel",
23+
"ready": {
24+
"title": "The Update is Ready",
25+
"msg": "Your update has downloaded. Click below to install it."
26+
},
27+
"install": "Install Now"
28+
},
1729
"addressBarPlaceholder": "Type a @handle, OpenBazaar ID or search term",
1830
"testnet": "Test Mode",
1931
"testnetTooltip": "Test Mode uses testnet coins, which are intended for testing purposes only.",

js/start.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import LocalSettings from './models/LocalSettings';
1616
import ObRouter from './router';
1717
import { getChatContainer, getBody } from './utils/selectors';
1818
import { setFeedbackOptions, addFeedback } from './utils/feedback';
19+
import { showUpdateStatus, updateReady } from './utils/autoUpdate';
1920
import Chat from './views/chat/Chat.js';
2021
import ChatHeads from './collections/ChatHeads';
2122
import PageNav from './views/PageNav.js';
@@ -622,6 +623,20 @@ $(window).on('beforeunload', () => {
622623
// Handle 'show debug log' requests from the main process.
623624
ipcRenderer.on('show-server-log', () => launchDebugLogModal());
624625

626+
// Handle update events from main.js
627+
ipcRenderer.on('updateChecking', () =>
628+
showUpdateStatus(app.polyglot.t('update.checking'), 'pending'));
629+
ipcRenderer.on('updateAvailable', () =>
630+
showUpdateStatus(app.polyglot.t('update.available'), 'pending'));
631+
ipcRenderer.on('updateNotAvailable', () =>
632+
showUpdateStatus(app.polyglot.t('update.notAvailable')));
633+
ipcRenderer.on('updateError', (e, msg) =>
634+
showUpdateStatus(app.polyglot.t('update.error', { error: msg }), 'warning'));
635+
ipcRenderer.on('updateReadyForInstall', (e, opts) => updateReady(opts));
636+
637+
// Allow main.js to send messages to the console
638+
ipcRenderer.on('consoleMsg', (e, msg) => console.log(msg));
639+
625640
// manage publishing sockets
626641
// todo: break the publishing socket startup functionality
627642
// into its own micro-module in js/startup/

js/templates/modals/about/about.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ <h2 id=tabTitle class="h3 clrT txCtr flexExpand"></h2>
2323
<%= ob.polyT('about.bothVersions', { cVer: ob.version, sVer: ob.serverVersion }) %>
2424
<% } %>
2525
</div>
26+
<% if (ob.isBundledApp) { %>
2627
<a class="btn clrP clrBAttGrad clrBrDec1 clrTOnEmph js-checkForUpdate">
2728
<%= ob.polyT('about.btnUpdateCheck') %>
2829
</a>
30+
<% } %>
2931
</div>
3032
</div>
3133
<hr class="clrBr" />

js/utils/autoUpdate.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import $ from 'jquery';
2+
import { ipcRenderer } from 'electron';
3+
import app from '../app';
4+
import Dialog from '../views/modals/Dialog';
5+
6+
let statusMsg;
7+
let removeStatusMsgTimout;
8+
9+
export function showUpdateStatus(status = '', type = 'message') {
10+
clearTimeout(removeStatusMsgTimout);
11+
12+
if (!statusMsg) {
13+
statusMsg = app.statusBar.pushMessage({
14+
msg: status,
15+
type,
16+
duration: 9999999999,
17+
});
18+
} else {
19+
statusMsg.update(status);
20+
}
21+
22+
// updates may arrive multiple times, manually remove the message when no new message
23+
// arrives for 6 seconds
24+
removeStatusMsgTimout = setTimeout(() => {
25+
statusMsg.remove();
26+
statusMsg = null;
27+
}, 6000);
28+
29+
return statusMsg;
30+
}
31+
32+
let updateReadyDialog;
33+
34+
export function updateReady(opts = {}) {
35+
if (updateReadyDialog) updateReadyDialog.close();
36+
37+
let displayData = '';
38+
$.each(opts, (key, val) => {
39+
displayData += `<b>${key}:</b> <br>${val}<br>`;
40+
});
41+
42+
updateReadyDialog = new Dialog({
43+
title: app.polyglot.t('update.ready.title'),
44+
message: `${app.polyglot.t('update.ready.msg')}<br><br>${displayData}`,
45+
buttons: [{
46+
text: app.polyglot.t('update.install'),
47+
fragment: 'installUpdate',
48+
}, {
49+
text: app.polyglot.t('update.cancel'),
50+
fragment: 'cancelInstall',
51+
}],
52+
}).on('click-installUpdate', () => ipcRenderer.send('installUpdate'))
53+
.on('click-cancelInstall', () => updateReadyDialog.close())
54+
.render()
55+
.open();
56+
}

js/views/modals/about/About.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { version } from '../../../../package.json';
2+
import { remote, ipcRenderer } from 'electron';
13
import $ from 'jquery';
24
import app from '../../../app';
35
import loadTemplate from '../../../utils/loadTemplate';
@@ -7,7 +9,6 @@ import Contributors from './Contributors';
79
import Donations from './Donations';
810
import License from './License';
911
import BTCTicker from '../../BTCTicker';
10-
import { version } from '../../../../package.json';
1112

1213
export default class extends BaseModal {
1314
constructor(options = {}) {
@@ -28,6 +29,7 @@ export default class extends BaseModal {
2829
};
2930

3031
this.currentTabName = 'Story';
32+
this.isBundledApp = remote.getGlobal('isBundledApp')();
3133
}
3234

3335
className() {
@@ -72,8 +74,7 @@ export default class extends BaseModal {
7274
}
7375

7476
checkForUpdateClick() {
75-
console.log('checking for an update');
76-
// TODO: wire this in
77+
ipcRenderer.send('checkForUpdate');
7778
}
7879

7980
render() {
@@ -93,6 +94,7 @@ export default class extends BaseModal {
9394
serverVersion,
9495
...this.options,
9596
version,
97+
isBundledApp: this.isBundledApp,
9698
}));
9799
super.render();
98100

main.js

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ let mainWindow;
2727
let trayMenu;
2828
let closeConfirmed = false;
2929
const version = app.getVersion();
30-
const feedURL = `https://updates2.openbazaar.org:5001/update/${process.platform}/${version}`;
30+
31+
function isOSWin64() {
32+
return process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
33+
}
34+
35+
const plat = process.platform === 'win32' ? `${isOSWin64() ? 'win64' : 'win32'}` : process.platform;
36+
37+
const feedURL = `https://updates2.openbazaar.org:5001/update/${plat}/${version}`;
38+
3139
global.serverLog = '';
3240

3341
const handleStartupEvent = function () {
@@ -85,6 +93,7 @@ if (handleStartupEvent()) {
8593
console.log('OpenBazaar started on Windows...');
8694
}
8795

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

163172
function createWindow() {
173+
// Check for updates an hour after the last check
174+
let checkForUpdatesInterval;
175+
176+
const checkForUpdates = () => {
177+
clearInterval(checkForUpdatesInterval);
178+
autoUpdater.checkForUpdates();
179+
checkForUpdatesInterval = setInterval(() => {
180+
autoUpdater.checkForUpdates();
181+
}, 60 * 60 * 1000);
182+
};
183+
184+
let helpSubmenu = [
185+
{
186+
label: 'Documentation',
187+
click() {
188+
shell.openExternal('https://docs.openbazaar.org');
189+
},
190+
},
191+
];
192+
193+
if (isBundledApp()) {
194+
helpSubmenu = [
195+
{
196+
label: 'Check for Updates...',
197+
click() {
198+
checkForUpdates();
199+
},
200+
},
201+
{
202+
type: 'separator',
203+
},
204+
...helpSubmenu,
205+
];
206+
}
207+
164208
const template = [
165209
{
166210
label: 'Edit',
@@ -240,29 +284,7 @@ function createWindow() {
240284
},
241285
{
242286
role: 'help',
243-
submenu: [
244-
// {
245-
// label: 'Report Issue...',
246-
// click() {
247-
// // TODO: Open an issue tracking window
248-
// },
249-
// },
250-
{
251-
label: 'Check for Updates...',
252-
click() {
253-
autoUpdater.checkForUpdates();
254-
},
255-
},
256-
{
257-
type: 'separator',
258-
},
259-
{
260-
label: 'Documentation',
261-
click() {
262-
shell.openExternal('https://docs.openbazaar.org');
263-
},
264-
},
265-
],
287+
submenu: helpSubmenu,
266288
},
267289
];
268290

@@ -476,26 +498,24 @@ function createWindow() {
476498
}
477499
});
478500

479-
// Set up protocol
480-
app.setAsDefaultProtocolClient('ob2');
481-
482-
// Check for URL hijacking in the browser
483-
preventWindowNavigation(mainWindow);
484-
485501
/**
486-
* For OS X users Squirrel manages the auto-updating code.
487502
* If there is an update available then we will send an IPC message to the
488503
* render process to notify the user. If the user wants to update
489504
* the software then they will send an IPC message back to the main process and we will
490505
* begin to download the file and update the software.
491506
*/
492-
if (process.platform === 'darwin') {
507+
if (isBundledApp()) {
508+
autoUpdater.on('checking-for-update', () => {
509+
mainWindow.send('updateChecking');
510+
mainWindow.send('consoleMsg', `Checking for update at ${autoUpdater.getFeedURL()}`);
511+
});
512+
493513
autoUpdater.on('error', (err, msg) => {
494-
console.log(msg);
514+
mainWindow.send('consoleMsg', msg);
515+
mainWindow.send('updateError', msg);
495516
});
496517

497-
autoUpdater.on('update-not-available', (msg) => {
498-
console.log(msg);
518+
autoUpdater.on('update-not-available', () => {
499519
mainWindow.send('updateNotAvailable');
500520
});
501521

@@ -504,12 +524,13 @@ function createWindow() {
504524
});
505525

506526
autoUpdater.on('update-downloaded', (e, releaseNotes, releaseName,
507-
releaseDate, updateUrl, quitAndUpdate) => {
508-
// Old way of doing things
509-
// mainWindow.webContents.executeJavaScript('$(".js-softwareUpdate")
510-
// .removeClass("softwareUpdateHidden");');
511-
console.log(quitAndUpdate);
512-
mainWindow.send('updateReadyForInstall');
527+
releaseDate, updateUrl) => {
528+
const opts = {};
529+
opts.Name = releaseName;
530+
opts.URL = updateUrl;
531+
opts.Date = releaseDate;
532+
opts.Notes = releaseNotes;
533+
mainWindow.send('updateReadyForInstall', opts);
513534
});
514535

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

520541
// Listen for checkForUpdate command to manually check for new versions
521542
ipcMain.on('checkForUpdate', () => {
522-
autoUpdater.checkForUpdates();
543+
checkForUpdates();
523544
});
524545

525546
autoUpdater.setFeedURL(feedURL);
526-
527-
// Check for updates every hour
528-
autoUpdater.checkForUpdates();
529-
setInterval(() => {
530-
autoUpdater.checkForUpdates();
531-
}, 60 * 60 * 1000);
532547
}
548+
549+
mainWindow.webContents.on('dom-ready', () => {
550+
// Check for an update once the DOM is ready so the update dialog box can be shown
551+
if (isBundledApp()) checkForUpdates();
552+
});
553+
554+
// Set up protocol
555+
app.setAsDefaultProtocolClient('ob2');
556+
557+
// Check for URL hijacking in the browser
558+
preventWindowNavigation(mainWindow);
533559
}
534560

535561
// This method will be called when Electron has finished

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "openbazaar-desktop",
3-
"version": "2.0.6",
3+
"productName": "OpenBazaar Desktop Client",
4+
"version": "2.0.7",
45
"description": "Decentralized p2p marketplace for Bitcoin",
56
"main": "bootstrapper.js",
67
"scripts": {
@@ -25,7 +26,7 @@
2526
"type": "git",
2627
"url": "git+https://github.com/OpenBazaar/ob-desktop.git"
2728
},
28-
"author": "",
29+
"author": "OB1",
2930
"license": "MIT",
3031
"bugs": {
3132
"url": "https://github.com/OpenBazaar/ob-desktop/issues"

0 commit comments

Comments
 (0)