fix: ELECTRON-1431: add logic to update pod version dynamically (#743)

* ELECTRON-1431: add logic to update pod version dynamically

* ELECTRON-1431: refactor the code to keep version handler simple

* ELECTRON-1431: add safety check for setting about panel on macOS

* Merge branch 'master' into ELECTRON-1431

# Conflicts:
#	src/app/window-handler.ts
This commit is contained in:
Vishwas Shashidhar 2019-07-19 18:48:01 +05:30 committed by GitHub
parent f8ea6a778f
commit e1f7fa53d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 68 deletions

View File

@ -42,6 +42,7 @@ jest.mock('../src/app/window-handler', () => {
createScreenPickerWindow: jest.fn(),
createScreenSharingIndicatorWindow: jest.fn(),
isOnline: false,
updateVersionInfo: jest.fn(),
},
};
});

View File

@ -49,6 +49,9 @@ ipcMain.on(apiName.symphonyApi, (event: Electron.Event, arg: IApiArgs) => {
break;
case apiCmds.registerProtocolHandler:
protocolHandler.setPreloadWebContents(event.sender);
// Since we register the prococol handler window upon login,
// we make use of it and update the pod version info on SDA
windowHandler.updateVersionInfo();
break;
case apiCmds.badgeDataUrl:
if (typeof arg.dataUrl === 'string' && typeof arg.count === 'number') {

View File

@ -13,7 +13,6 @@ import './dialog-handler';
import './main-api-handler';
import { handlePerformanceSettings } from './perf-handler';
import { protocolHandler } from './protocol-handler';
import { IVersionInfo, versionHandler } from './version-handler';
import { ICustomBrowserWindow, windowHandler } from './window-handler';
logger.info(`App started with the args ${JSON.stringify(process.argv)}`);
@ -53,28 +52,11 @@ setChromeFlags();
// Electron sets the default protocol
app.setAsDefaultProtocolClient('symphony');
const setAboutPanel = (clientVersion: string, buildNumber: string) => {
const appName = app.getName();
const copyright = `Copyright \xA9 ${new Date().getFullYear()} ${appName}`;
app.setAboutPanelOptions({
applicationName: appName,
applicationVersion: clientVersion,
version: buildNumber,
copyright,
});
};
/**
* Main function that init the application
*/
const startApplication = async () => {
await app.whenReady();
versionHandler.getClientVersion()
.then((versionInfo: IVersionInfo) => {
if (isMac) {
setAboutPanel(versionInfo.clientVersion, versionInfo.buildNumber);
}
});
logger.info(`main: app is ready, performing initial checks`);
createAppCacheFile();
windowHandler.createApplication();

View File

@ -19,13 +19,14 @@ interface IVersionInfo {
aresVersion: string;
httpParserVersion: string;
swiftSearchVersion: string;
swiftSerchSupportedVersion: string;
swiftSearchSupportedVersion: string;
}
class VersionHandler {
private versionInfo: IVersionInfo;
public versionInfo: IVersionInfo;
private serverVersionInfo: any;
private mainUrl;
constructor() {
this.versionInfo = {
@ -43,32 +44,42 @@ class VersionHandler {
aresVersion: process.versions.ares,
httpParserVersion: process.versions.http_parser,
swiftSearchVersion: optionalDependencies['swift-search'],
swiftSerchSupportedVersion: searchAPIVersion,
swiftSearchSupportedVersion: searchAPIVersion,
};
this.mainUrl = null;
}
/**
* Get Symphony version from the pod
*/
public getClientVersion(): Promise<IVersionInfo> {
public getClientVersion(fetchFromServer: boolean = false, mainUrl?: string): Promise<IVersionInfo> {
return new Promise((resolve) => {
if (this.serverVersionInfo) {
if (this.serverVersionInfo && !fetchFromServer) {
this.versionInfo.clientVersion = this.serverVersionInfo['Implementation-Version'] || this.versionInfo.clientVersion;
this.versionInfo.buildNumber = this.serverVersionInfo['Implementation-Build'] || this.versionInfo.buildNumber;
resolve(this.versionInfo);
return;
}
if (mainUrl) {
this.mainUrl = mainUrl;
}
const { url: podUrl }: IConfig = config.getGlobalConfigFields(['url']);
if (!podUrl) {
if (!this.mainUrl || !nodeURL.parse(this.mainUrl)) {
this.mainUrl = podUrl;
}
if (!this.mainUrl) {
logger.error(`version-handler: Unable to get pod url for getting version data from server! Setting defaults!`);
resolve(this.versionInfo);
return;
}
const hostname = nodeURL.parse(podUrl).hostname;
const protocol = nodeURL.parse(podUrl).protocol;
const hostname = nodeURL.parse(this.mainUrl).hostname;
const protocol = nodeURL.parse(this.mainUrl).protocol;
const versionApiPath = '/webcontroller/HealthCheck/version/advanced';
const url = `${protocol}//${hostname}${versionApiPath}`;
@ -96,7 +107,7 @@ class VersionHandler {
}
});
res.on('error', (error) => {
res.on('error', (error: Error) => {
logger.error(`version-handler: Error getting version data from the server! ${error}`);
resolve(this.versionInfo);
return;
@ -104,7 +115,7 @@ class VersionHandler {
});
request.on('error', (error) => {
request.on('error', (error: Error) => {
logger.error(`version-handler: Error getting version data from the server! ${error}`);
resolve(this.versionInfo);
return;

View File

@ -16,7 +16,7 @@ import { config, IConfig } from './config-handler';
import { SpellChecker } from './spell-check-handler';
import { checkIfBuildExpired } from './ttl-handler';
import DesktopCapturerSource = Electron.DesktopCapturerSource;
import { IVersionInfo, versionHandler } from './version-handler';
import { versionHandler } from './version-handler';
import { handlePermissionRequests, monitorWindowActions } from './window-actions';
import {
createComponentWindow,
@ -120,6 +120,7 @@ export class WindowHandler {
} catch (e) {
throw new Error('failed to init crash report');
}
}
/**
@ -127,6 +128,7 @@ export class WindowHandler {
*/
public createApplication() {
this.updateVersionInfo();
this.spellchecker = new SpellChecker();
logger.info(`window-handler: initialized spellchecker module with locale ${this.spellchecker.locale}`);
@ -414,13 +416,16 @@ export class WindowHandler {
this.aboutAppWindow = createComponentWindow('about-app', opts);
this.aboutAppWindow.setVisibleOnAllWorkspaces(true);
this.aboutAppWindow.webContents.once('did-finish-load', async () => {
if (!this.aboutAppWindow || !windowExists(this.aboutAppWindow)) {
return;
}
const ABOUT_SYMPHONY_NAMESPACE = 'AboutSymphony';
const versionLocalised = i18n.t('Version', ABOUT_SYMPHONY_NAMESPACE)();
const { clientVersion, buildNumber }: IVersionInfo = await versionHandler.getClientVersion();
this.aboutAppWindow.webContents.send('about-app-data', { buildNumber, clientVersion, versionLocalised });
const aboutInfo = {
buildNumber: versionHandler.versionInfo.buildNumber,
clientVersion: versionHandler.versionInfo.clientVersion,
versionLocalised,
};
if (this.aboutAppWindow && windowExists(this.aboutAppWindow)) {
this.aboutAppWindow.webContents.send('about-app-data', aboutInfo);
}
});
}
@ -448,11 +453,9 @@ export class WindowHandler {
this.moreInfoWindow = createComponentWindow('more-info', opts);
this.moreInfoWindow.webContents.once('did-finish-load', async () => {
if (!this.moreInfoWindow || !windowExists(this.moreInfoWindow)) {
return;
if (this.moreInfoWindow && windowExists(this.moreInfoWindow)) {
this.moreInfoWindow.webContents.send('more-info-data', versionHandler.versionInfo);
}
const versionInfo: IVersionInfo = await versionHandler.getClientVersion();
this.moreInfoWindow.webContents.send('more-info-data', versionInfo);
});
}
@ -701,6 +704,14 @@ export class WindowHandler {
ipcMain.once('stop-screen-sharing', stopScreenSharing);
}
/**
* Update version info on the about app window and more info window
*/
public async updateVersionInfo() {
await versionHandler.getClientVersion(true, this.url);
this.setAboutPanel();
}
/**
* Opens an external url in the system's default browser
*
@ -732,6 +743,24 @@ export class WindowHandler {
delete this.windows[key];
}
/**
* Sets the about panel details for macOS
*/
private setAboutPanel() {
if (!isMac) {
return;
}
const appName = app.getName();
const copyright = `Copyright \xA9 ${new Date().getFullYear()} ${appName}`;
app.setAboutPanelOptions({
applicationName: appName,
applicationVersion: versionHandler.versionInfo.clientVersion,
version: versionHandler.versionInfo.buildNumber,
copyright,
});
}
/**
* Registers keyboard shortcuts or devtools
*/