Skip to content

Commit

Permalink
Github release publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish Jangir committed Sep 12, 2018
1 parent 088a03c commit bdc263a
Show file tree
Hide file tree
Showing 250 changed files with 667 additions and 87,963 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ app/build
node_modules
stats.json
app/node_modules
release

# Cruft
.DS_Store
npm-debug.log
.idea
.vscode
115 changes: 115 additions & 0 deletions app/electron/autoupdater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* eslint global-require: 0 */
import { app, dialog, shell } from 'electron';
import { autoUpdater } from 'electron-updater';
import es from 'electron-settings';
import isDev from 'electron-is-dev';

function appUpdater(updateFromMenu = false) {
// Don't initiate auto-updates in development
if (isDev) {
return;
}

if (process.platform === 'linux' && !process.env.APPIMAGE) {
// const { linuxUpdateNotification } = require('./linuxupdater');
// linuxUpdateNotification();
return;
}

let updateAvailable = false;

// Create Logs directory
const logsDir = `${app.getPath('userData')}/logs`;

// Log whats happening
const log = require('electron-log');

log.transports.file.file = `${logsDir}/updates.log`;
log.transports.file.level = 'info';
autoUpdater.logger = log;

// Handle auto updates for beta/pre releases
autoUpdater.allowPrerelease = es.get('allowPreRelease') || false;

const eventsListenerRemove = ['update-available', 'update-not-available'];

autoUpdater.on('update-available', info => {
if (updateFromMenu) {
dialog.showMessageBox({
message: `A new version ${info.version}, of Reactron is available`,
detail:
'The update will be downloaded in the background. You will be notified when it is ready to be installed.',
});

updateAvailable = true;

eventsListenerRemove.forEach(event => {
autoUpdater.removeAllListeners(event);
});
}
});

autoUpdater.on('update-not-available', () => {
if (updateFromMenu) {
dialog.showMessageBox({
message: 'No updates available',
detail: `You are running the latest version of Reactron.\nVersion: ${app.getVersion()}`,
});
autoUpdater.removeAllListeners();
}
});

autoUpdater.on('error', error => {
if (updateFromMenu) {
const messageText = updateAvailable
? 'Unable to download the updates'
: 'Unable to check for updates';
dialog.showMessageBox(
{
type: 'error',
buttons: ['Manual Download', 'Cancel'],
message: messageText,
detail: `${error.toString()}\n\nThe latest version of Reactron Website is available at -
\nhttps://github.com/mjangir/reactron/.\nCurrent Version: ${app.getVersion()}`,
},
response => {
if (response === 0) {
shell.openExternal('https://github.com/mjangir/reactron');
}
},
);
autoUpdater.removeAllListeners();
}
});

// Ask the user if update is available
// eslint-disable-next-line no-unused-vars
autoUpdater.on('update-downloaded', event => {
// Ask user to update the app
dialog.showMessageBox(
{
type: 'question',
buttons: ['Install and Relaunch', 'Install Later'],
defaultId: 0,
message: `A new update ${event.version} has been downloaded`,
detail:
'It will be installed the next time you restart the application',
},
response => {
if (response === 0) {
setTimeout(() => {
autoUpdater.quitAndInstall();
// force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app.
app.quit();
}, 1000);
}
},
);
});
// Init for updates
autoUpdater.checkForUpdates();
}

export default {
appUpdater,
};
4 changes: 3 additions & 1 deletion app/electron/main.dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint global-require: 0, flowtype-errors/show-errors: 0 */
/* eslint global-require: 0, flowtype-errors/show-errors: 0, no-console: 0 */

import { app, BrowserWindow } from 'electron';
import MenuBuilder from './menu';
import sentryUtil from '../utils/electronSentryUtil';

let mainWindow = null;

Expand Down Expand Up @@ -43,6 +44,7 @@ app.on('window-all-closed', () => {
});

app.on('ready', async () => {
sentryUtil.sentryInit();
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
Expand Down
1 change: 0 additions & 1 deletion app/electron/main.prod.js.map

This file was deleted.

5 changes: 3 additions & 2 deletions app/electron/menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, Menu, shell } from 'electron';
import autoUpdater from './autoupdater';

export default class MenuBuilder {
mainWindow;
Expand Down Expand Up @@ -201,9 +202,9 @@ export default class MenuBuilder {
label: 'Help',
submenu: [
{
label: 'Learn More',
label: `Check for Update`,
click() {
shell.openExternal('http://electron.atom.io');
autoUpdater.appUpdater(true);
},
},
{
Expand Down
Loading

0 comments on commit bdc263a

Please sign in to comment.