Skip to content

Commit 62971f6

Browse files
committed
fix: fixes #356 notification about updates
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 8340ace commit 62971f6

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/app/scripts/arc/AdvancedRestClientApplication.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ document.adoptedStyleSheets = document.adoptedStyleSheets.concat(ContextMenuStyl
9090
/** @typedef {import('@advanced-rest-client/arc-types').Authorization.OAuth2Authorization} OAuth2Authorization */
9191
/** @typedef {import('@advanced-rest-client/electron-amf-service/types').ApiParseResult} ApiParseResult */
9292
/** @typedef {import('@advanced-rest-client/exchange-search-panel/src/types').ExchangeAsset} ExchangeAsset */
93+
/** @typedef {import('electron-updater').UpdateInfo} UpdateInfo */
9394

9495
const unhandledRejectionHandler = Symbol('unhandledRejectionHandler');
9596
const headerTemplate = Symbol('headerTemplate');
@@ -154,6 +155,8 @@ const unreadMessagesTemplate = Symbol('unreadMessagesTemplate');
154155
const appMessagesDialogTemplate = Symbol('appMessagesDialogTemplate');
155156
const openMessagesHandler = Symbol('openMessagesHandler');
156157
const arcLegacyProjectTemplate = Symbol('arcLegacyProjectTemplate');
158+
const updateIndicatorTemplate = Symbol('updateIndicatorTemplate');
159+
const updateClickHandler = Symbol('updateClickHandler');
157160

158161
/**
159162
* A routes that does not go through the router and should not be remembered in the history.
@@ -331,7 +334,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
331334
this.initObservableProperties(
332335
'route', 'routeParams', 'initializing', 'loadingStatus',
333336
'compatibility', 'oauth2RedirectUri',
334-
'navigationDetached', 'updateState', 'hasAppUpdate',
337+
'navigationDetached', 'updateState', 'hasAppUpdate', 'manualUpdateAvailable', 'updateVersion',
335338
'popupMenuEnabled', 'draggableEnabled', 'historyEnabled',
336339
'listType', 'detailedSearch', 'currentEnvironment',
337340
'workspaceSendButton', 'workspaceProgressInfo', 'workspaceBodyEditor', 'workspaceAutoEncode',
@@ -382,6 +385,10 @@ export class AdvancedRestClientApplication extends ApplicationPage {
382385
* Whether application update is available.
383386
*/
384387
this.hasAppUpdate = false;
388+
/**
389+
* Set whe an update is available but it has to be triggered manually.
390+
*/
391+
this.manualUpdateAvailable = false;
385392
/**
386393
* The current state of checking for update.
387394
* @type {string}
@@ -620,9 +627,18 @@ export class AdvancedRestClientApplication extends ApplicationPage {
620627
this.logger.info('Checking for application update');
621628
this.updateState = 'checking-for-update';
622629
});
623-
ipc.on('update-available', () => {
630+
ipc.on('update-available',
631+
/**
632+
* @param {Electron.IpcRendererEvent} e
633+
* @param {UpdateInfo} info
634+
*/
635+
(e, info) => {
636+
this.updateVersion = info.version;
624637
this.logger.info('Application update available.');
625638
this.updateState = 'update-available';
639+
if (process.platform === 'linux' || this.config.updater && this.config.updater.auto === false) {
640+
this.manualUpdateAvailable = true;
641+
}
626642
});
627643
ipc.on('update-not-available', () => {
628644
this.logger.info('Application update not available.');
@@ -1361,6 +1377,23 @@ export class AdvancedRestClientApplication extends ApplicationPage {
13611377
this.unreadAppMessages = 0;
13621378
}
13631379

1380+
/**
1381+
* A handler for the application update notification click.
1382+
* It installs the update when manual installation is not requested.
1383+
* If manual installation is requested then it opens the release page.
1384+
*/
1385+
[updateClickHandler]() {
1386+
const { manualUpdateAvailable, hasAppUpdate } = this;
1387+
if (manualUpdateAvailable) {
1388+
const { updateVersion } = this;
1389+
const base = 'https://github.com/advanced-rest-client/arc-electron/releases/tag';
1390+
const url = `${base}/v${updateVersion}`;
1391+
ipc.send('open-external-url', url);
1392+
} else if (hasAppUpdate) {
1393+
ipc.send('install-update');
1394+
}
1395+
}
1396+
13641397
appTemplate() {
13651398
const { initializing } = this;
13661399
if (initializing) {
@@ -1406,11 +1439,26 @@ export class AdvancedRestClientApplication extends ApplicationPage {
14061439
</anypoint-icon-button>`}
14071440
API Client
14081441
<span class="spacer"></span>
1442+
${this[updateIndicatorTemplate]()}
14091443
${this[unreadMessagesTemplate]()}
14101444
${this[environmentTemplate]()}
14111445
</header>`;
14121446
}
14131447

1448+
/**
1449+
* @returns {TemplateResult|string} The template for the app update indicator
1450+
*/
1451+
[updateIndicatorTemplate]() {
1452+
const { manualUpdateAvailable, hasAppUpdate } = this;
1453+
if (!manualUpdateAvailable && !hasAppUpdate) {
1454+
return '';
1455+
}
1456+
return html`
1457+
<anypoint-icon-button title="Application update available" class="header-action-button" @click="${this[updateClickHandler]}">
1458+
<arc-icon icon="cloudDownload"></arc-icon>
1459+
</anypoint-icon-button>`;
1460+
}
1461+
14141462
/**
14151463
* @returns {TemplateResult|string} The template for the unread notifications icon button
14161464
*/

src/preload/arc-preload.esm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { GoogleAnalytics } from './GoogleAnalytics.js';
1818

1919
const env = {};
2020
const APP_VERSION = process.env.ARC_VERSION;
21+
const PLATFORM = process.platform;
2122
Object.keys(process.env).forEach((key) => {
2223
if (key.indexOf('npm_') === 0 || key.indexOf('ARC_') === 0) {
2324
return;
@@ -70,6 +71,7 @@ process.once('loaded', () => {
7071
global.process = {
7172
// @ts-ignore
7273
env,
74+
platform: PLATFORM,
7375
};
7476

7577
// @ts-ignore

0 commit comments

Comments
 (0)