From d3331171db817c14b5ba026232cbbc4c791c872d Mon Sep 17 00:00:00 2001 From: Rob Misiorowski Date: Tue, 27 Dec 2016 09:20:56 -0800 Subject: [PATCH] integrated changes from #170 --- .gitignore | 1 + Gruntfile.js | 1 + build.sh | 7 +++-- main.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 5 ++-- 5 files changed, 83 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index db3fc0d7d..a3cf9c4dc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist prod mainBuilt.js error.log +.idea diff --git a/Gruntfile.js b/Gruntfile.js index 623f39982..454998d2f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,4 +1,5 @@ const path = require('path'); + module.exports = function (grunt) { // Project configuration. grunt.initConfig({ diff --git a/build.sh b/build.sh index 11d1c3ae0..3d6a8aa6f 100755 --- a/build.sh +++ b/build.sh @@ -119,7 +119,7 @@ case "$TRAVIS_OS_NAME" in mkdir dist/win32 echo 'Running Electron Packager...' - electron-packager . OpenBazaar2 --asar=true --out=dist --protocol-name=OpenBazaar --version-string.ProductName=OpenBazaar --protocol=ob --platform=win32 --arch=ia32 --icon=imgs/windows-icon.ico --version=${ELECTRONVER} --overwrite + electron-packager . OpenBazaar2 --asar=true --out=dist --protocol-name=OpenBazaar --win32metadata.ProductName="OpenBazaar2" --win32metadata.CompanyName="OpenBazaar" --win32metadata.FileDescription='Decentralized p2p marketplace for Bitcoin' --win32metadata.OriginalFilename=OpenBazaar2.exe --protocol=ob --platform=win32 --arch=ia32 --icon=imgs/windows-icon.ico --version=${ELECTRONVER} --overwrite echo 'Copying server binary into application folder...' cp -rf temp/openbazaar-go-windows-4.0-386.exe dist/OpenBazaar2-win32-ia32/resources/ @@ -139,7 +139,10 @@ case "$TRAVIS_OS_NAME" in mkdir dist/win64 echo 'Running Electron Packager...' - electron-packager . OpenBazaar2 --asar=true --out=dist --protocol-name=OpenBazaar --version-string.ProductName=OpenBazaar --protocol=ob --platform=win32 --arch=x64 --icon=imgs/windows-icon.ico --version=${ELECTRONVER} --overwrite + electron-packager . OpenBazaar2 --asar=true --out=dist --protocol-name=OpenBazaar --win32metadata.ProductName="OpenBazaar2" --win32metadata.CompanyName="OpenBazaar" --win32metadata.FileDescription='Decentralized p2p marketplace for Bitcoin' --win32metadata.OriginalFilename=OpenBazaar2.exe --protocol=ob --platform=win32 --arch=x64 --icon=imgs/windows-icon.ico --version=${ELECTRONVER} --overwrite + + echo 'Copying server binary into application folder...' + cp -rf temp/openbazaar-go-windows-4.0-amd64.exe dist/OpenBazaar2-win32-x64/resources/ echo 'Copying server binary into application folder...' cp -rf temp/openbazaar-go-windows-4.0-amd64.exe dist/OpenBazaar2-win32-x64/resources/ diff --git a/main.js b/main.js index bc27d6dc9..facd39660 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ import { - electron, app, BrowserWindow, ipcMain, + app, BrowserWindow, ipcMain, Menu, Tray, session, crashReporter, + autoUpdater, shell, } from 'electron'; import path from 'path'; import fs from 'fs'; @@ -14,6 +15,8 @@ import { bindLocalServerEvent } from './js/utils/mainProcLocalServerEvents'; let mainWindow; let trayMenu; let closeConfirmed = false; +const version = app.getVersion(); +const feedURL = `https://updates2.openbazaar.org:5001/update/${process.platform}/${version}`; global.serverLog = ''; const handleStartupEvent = function () { @@ -31,7 +34,7 @@ const handleStartupEvent = function () { function install(cb) { const target = path.basename(process.execPath); - exeSquirrelCommand(['--createShortcut', target], cb); + exeSquirrelCommand(['--createShortcut', target, ' --shortcut-locations=Desktop,StartMenu'], cb); } function uninstall(cb) { @@ -169,9 +172,26 @@ function createWindow() { { role: 'help', submenu: [ + // { + // label: 'Report Issue...', + // click() { + // // TODO: Open an issue tracking window + // }, + // }, { - label: 'Learn More', - click() { electron.shell.openExternal('https://openbazaar.org'); }, + label: 'Check for Updates...', + click() { + autoUpdater.checkForUpdates(); + }, + }, + { + type: 'separator', + }, + { + label: 'Documentation', + click() { + shell.openExternal('https://docs.openbazaar.org'); + }, }, ], }, @@ -369,6 +389,55 @@ function createWindow() { e.preventDefault(); } }); + + /** + * 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') { + autoUpdater.on('error', (err, msg) => { + console.log(msg); + }); + + autoUpdater.on('update-not-available', (msg) => { + console.log(msg); + mainWindow.send('updateNotAvailable'); + }); + + autoUpdater.on('update-available', () => { + mainWindow.send('updateAvailable'); + }); + + 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'); + }); + + // Listen for installUpdate command to install the update + ipcMain.on('installUpdate', () => { + autoUpdater.quitAndInstall(); + }); + + // Listen for checkForUpdate command to manually check for new versions + ipcMain.on('checkForUpdate', () => { + autoUpdater.checkForUpdates(); + }); + + autoUpdater.setFeedURL(feedURL); + + // Check for updates every hour + autoUpdater.checkForUpdates(); + setInterval(() => { + autoUpdater.checkForUpdates(); + }, 60 * 60 * 1000); + } } // This method will be called when Electron has finished @@ -438,4 +507,3 @@ const log = msg => { if (localServer) bindLocalServerEvent('log', (localServ, msg) => log(msg)); ipcMain.on('server-connect-log', (e, msg) => log(msg)); - diff --git a/package.json b/package.json index abb6e3390..db02ce35d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "openbazaar-desktop", "version": "2.0.0", - "description": "", + "description": "Decentralized p2p marketplace for Bitcoin", "main": "bootstrapper.js", "scripts": { "start": "cross-env NODE_ENV=development npm-run-all sass:build process-index --parallel sass:watch index:watch browsersync start-app", @@ -18,7 +18,8 @@ "process-index:build": "babel-node ./bin/processIndexForBuild.js", "copy-js-subfolders": "copyfiles -u 1 'js/languages/**/*' 'js/templates/**/*' prod", "babel": "babel js --out-dir prod; babel main.js --out-file mainBuilt.js", - "build": "npm-run-all sass:build --parallel babel process-index:build --sequential copy-js-subfolders" + "build": "npm-run-all sass:build --parallel babel process-index:build --sequential copy-js-subfolders", + "binaries": "./build.sh" }, "repository": { "type": "git",