Skip to content

Commit

Permalink
Merge pull request #440 from jjavierdguezas/feature/windows-portable-…
Browse files Browse the repository at this point in the history
…version

Add windows portable version to electron-builder config
  • Loading branch information
manojVivek committed Aug 31, 2020
2 parents 4a434a0 + 0bc8d0e commit ec18834
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions desktop-app/app/app-updater.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {autoUpdater} from 'electron-updater';
import log from 'electron-log';
import {pkg} from './utils/generalUtils';
import {shell, Notification} from 'electron';

const {EventEmitter} = require('events');

const AppUpdaterStatus = {
Idle: 'idle',
Checking: 'checking',
NoUpdate: 'noUpdate',
NewVersion: 'newVersion',
Downloading: 'downloading',
Downloaded: 'downloaded',
};
Expand All @@ -18,10 +21,13 @@ class AppUpdater extends EventEmitter {

timerId = null;

isPortableVersion = process.env.PORTABLE_EXECUTABLE_DIR != null && process.env.PORTABLE_EXECUTABLE_DIR.length !== 0;

constructor() {
super();
log.transports.file.level = 'info';
autoUpdater.logger = log;
autoUpdater.autoDownload = !this.isPortableVersion;
this.status = AppUpdaterStatus.Idle;

autoUpdater.on('checking-for-update', () =>
Expand All @@ -44,7 +50,27 @@ class AppUpdater extends EventEmitter {

checkForUpdatesAndNotify() {
if (this.status === AppUpdaterStatus.Idle)
{
if (this.isPortableVersion) {
return autoUpdater.checkForUpdates().then(r => {
if (r?.updateInfo?.version != null && r.updateInfo.version !== pkg.version) {
this.handleStatusChange(AppUpdaterStatus.NewVersion, true);
if (Notification.isSupported()) {
const notif = new Notification({
title: `New version ${r.updateInfo.version} available`,
body: 'You have an outdated version of Responsively. Click here to download the latest version'
});
notif.on('click', () => {
shell.openExternal('https://github.com/responsively-org/responsively-app/releases/latest');
});
notif.show();
}
}
return r;
});
}
return autoUpdater.checkForUpdatesAndNotify();
}
}

handleStatusChange(nextStatus: string, backToIdle: boolean) {
Expand Down
3 changes: 3 additions & 0 deletions desktop-app/app/components/StatusBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const AppUpdaterStatusInfoSection = () => {
case 'downloaded':
label = 'Update Info: Update Downloaded';
break;
case 'newVersion':
label = 'Update Info: New version available!';
break;
default:
label = null;
break;
Expand Down
4 changes: 4 additions & 0 deletions desktop-app/app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export default class MenuBuilder {
label = 'Downloading Update...';
enabled = false;
break;
case AppUpdaterStatus.NewVersion:
label = 'New version available';
enabled = false;
break;
case AppUpdaterStatus.Downloaded:
label = 'Update Downloaded';
enabled = false;
Expand Down
3 changes: 2 additions & 1 deletion desktop-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
},
"win": {
"target": [
"nsis"
"nsis",
"portable"
],
"fileAssociations": [
{
Expand Down

0 comments on commit ec18834

Please sign in to comment.