Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions electron/app/js/appUpdater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @license
* Copyright (c) 2021, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
'use strict';

const { dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const i18n = require('./i18next.config');
const { getLogger } = require('./wktLogging');
const errorUtils = require('./errorUtils');
const { sendToWindow } = require('./windowUtils');

let _isDevMode;
let _downloadWindow;

function initializeAutoUpdater(logger, isDevMode) {
_isDevMode = isDevMode;
autoUpdater.logger = logger;
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true;
}

function registerAutoUpdateListeners() {
autoUpdater.on('download-progress', progressObj => {
if(_downloadWindow) {
sendToWindow(_downloadWindow, 'app-download-progress', progressObj.percent);
}
});
}

// returns a Promise that may resolve to information about a new app update.
// if app is in dev mode, the Promise resolves to null without any check.
// if the application is current with the latest version, or an error occurs, the Promise resolves to null.
// if notifyOnFailures is true, dialogs are displayed when no result is provided.
async function getUpdateInformation(notifyOnFailures) {
if (!_isDevMode) {
try {
const checkResult = await autoUpdater.checkForUpdates();
const releaseName = checkResult.updateInfo.releaseName;
const updateAvailable = Object.prototype.hasOwnProperty.call(checkResult, 'downloadPromise');
if (updateAvailable) {
return {
releaseName,
releaseNotes: checkResult.updateInfo.releaseNotes
};
} else if (notifyOnFailures) {
dialog.showMessageBox({
title: i18n.t('auto-updater-update-not-available-title'),
message: i18n.t('auto-updater-update-not-available-message', {version: releaseName}),
type: 'info',
buttons: [i18n.t('button-ok')],
defaultId: 0,
cancelId: 0
}).then();
}
} catch(error) {
const errorMessage = errorUtils.getErrorMessage(error);
getLogger().error('Application auto-updater failed: %s', errorMessage);
if (error.stack) {
getLogger().error(error.stack.toString());
}
if (notifyOnFailures) {
dialog.showErrorBox(i18n.t('auto-updater-error-title'),
i18n.t('auto-updater-error-message', { error: errorMessage }));
}
}
} else if (notifyOnFailures) {
// Only show the prompt if the user used the menu to trigger checkForUpdates()
// If triggered on startup, no need to display...
//
dialog.showErrorBox(i18n.t('auto-updater-disabled-dev-mode-title'),
i18n.t('auto-updater-disabled-dev-mode-message'));
}

return null;
}

// check for updates and send information to the renderer if an update is available.
function checkForUpdates(focusedWindow, notifyOnFailures) {
getUpdateInformation(notifyOnFailures).then(updateResult => {
if (updateResult) {
sendToWindow(focusedWindow, 'app-update-available', updateResult);
}
});
}

async function installUpdates(window, installType) {
try {
_downloadWindow = window;
await autoUpdater.downloadUpdate();
_downloadWindow = null;

if(installType === 'now') {
autoUpdater.quitAndInstall();
}
} catch (error) {
_downloadWindow = null;

getLogger().error('Application auto-updater failed: %s', errorUtils.getErrorMessage(error));
if (error.stack) {
getLogger().error(error.stack.toString());
}

dialog.showErrorBox(i18n.t('auto-updater-error-title'),
i18n.t('auto-updater-error-message', { error: error }));
}
}

module.exports = {
checkForUpdates,
getUpdateInformation,
initializeAutoUpdater,
installUpdates,
registerAutoUpdateListeners
};
2 changes: 1 addition & 1 deletion electron/app/js/connectivityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CONNECT_TIMEOUT = 5000;
// test connectivity for user settings configuration
async function testConfiguredInternetConnectivity() {
const userSettings = require('./userSettings');
const httpsProxyUrl = await userSettings.getHttpsProxyUrl();
const httpsProxyUrl = userSettings.getHttpsProxyUrl();
return testInternetConnectivity(httpsProxyUrl);
}

Expand Down
16 changes: 8 additions & 8 deletions electron/app/js/helmUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ async function addOrUpdateWkoHelmChart(helmExe, helmOptions) {

async function addOrUpdateHelmChart(helmExe, repoName, repoUrl, helmOptions) {
const args = [ 'repo', 'add', repoName, repoUrl, '--force-update' ];
const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
const results = {
isSuccess: true
Expand All @@ -74,8 +74,8 @@ async function addOrUpdateHelmChart(helmExe, repoName, repoUrl, helmOptions) {

async function installIngressController(helmExe, ingressControllerName, ingressChartName, ingressControllerNamespace, valuesData, helmChartValues, helmOptions) {

const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
const results = {
isSuccess: true
Expand Down Expand Up @@ -133,8 +133,8 @@ async function helmListAllNamespaces(helmExe, helmOptions) {
}

async function _runHelmWko(helmExe, name, namespace, args, helmOptions, errorKey) {
const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
const results = {
isSuccess: true
Expand All @@ -153,8 +153,8 @@ async function _runHelmWko(helmExe, name, namespace, args, helmOptions, errorKey
}

async function _runHelmCommand(helmExe, args, helmOptions, errorKey) {
const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
const results = {
isSuccess: true
Expand Down
8 changes: 4 additions & 4 deletions electron/app/js/imageBuilderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ async function validateImageExistsLocally(imageBuilderExe, imageTag) {

async function doLogin(imageBuilderExe, options) {
const i18n = require('./i18next.config');
const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();

const result = { isSuccess: true };
if (!options.requiresLogin) {
Expand Down Expand Up @@ -101,8 +101,8 @@ async function doLogin(imageBuilderExe, options) {

async function doPushImage(currentWindow, stdoutChannel, stderrChannel, imageBuilderExe, imageTag, options) {
const i18n = require('./i18next.config');
const httpsProxyUrl = await getHttpsProxyUrl();
const bypassProxyHosts = await getBypassProxyHosts();
const httpsProxyUrl = getHttpsProxyUrl();
const bypassProxyHosts = getBypassProxyHosts();

const result = { isSuccess: true };
if (options.requiresLogin) {
Expand Down
4 changes: 4 additions & 0 deletions electron/app/js/ipcRendererPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ contextBridge.exposeInMainWorld(
'show-console-out-line',
'show-console-err-line',
'show-quickstart',
'show-startup-dialogs',
'app-update-available',
'blur-focused-item',
'start-prepare-model',
'start-create-image',
Expand All @@ -67,6 +69,7 @@ contextBridge.exposeInMainWorld(
'start-wko-install',
'start-ingress-install',
'add-ingress-routes',
'app-download-progress',
'start-k8s-domain-deploy',
'get-wko-domain-status',
'start-app-quit',
Expand Down Expand Up @@ -134,6 +137,7 @@ contextBridge.exposeInMainWorld(
'verify-file-exists',
'ok-or-cancel-prompt',
'yes-or-no-prompt',
'install-app-update',
'get-latest-wdt-installer',
'wit-cache-installers',
'do-image-registry-login',
Expand Down
Loading