Skip to content

Commit

Permalink
SDA-4489 - Fix issue related to different env (finos#2137)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3b39725)
  • Loading branch information
KiranNiranjan committed May 3, 2024
1 parent d46bfe8 commit 9e0bd41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/app/auto-update-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export class AutoUpdate {
logger.info(
'auto-update-handler: update downloaded and isForceUpdate',
);
// Handle update and restart for macOS
if (isMac) {
windowHandler.setIsAutoUpdating(true);
}
this.autoUpdater?.quitAndInstall();
return;
}
Expand Down Expand Up @@ -124,7 +128,7 @@ export class AutoUpdate {
return;
}

const updaterFilePath = path.join(cacheDir, 'symphony-updater/pending');
const updaterFilePath = path.join(cacheDir, 'symphony-updater', 'pending');
if (!fs.existsSync(updaterFilePath)) {
logger.info(
'auto-update-handler: Updater directory not found, skipping forced auto-update.',
Expand Down Expand Up @@ -156,8 +160,9 @@ export class AutoUpdate {
return;
}

const hasPendingInstaller = files.some((item) =>
item.includes(latestVersionFromServer),
const hasPendingInstaller = files.some(
(item) =>
item.includes(latestVersionFromServer) && !item.startsWith('temp'),
);
if (hasPendingInstaller) {
logger.info('auto-update-handler: latest version found force installing');
Expand Down Expand Up @@ -263,24 +268,20 @@ export class AutoUpdate {
};

private fetchLatestVersion = async (): Promise<string | void> => {
await this.setAutoUpdateChannel();
return new Promise((resolve) => {
const url = this.getUpdateUrl();
const { autoUpdateChannel } = config.getConfigFields([
'autoUpdateChannel',
]);
const endpoint = `${url}/${autoUpdateChannel}.yml`;
return new Promise(async (resolve) => {
const opts = await this.getGenericServerOptions();
const url = opts.channel ? `${opts.url}/${opts.channel}.yml` : opts.url;
logger.info(
'auto-update-handler: fetching latest version info from',
endpoint,
url,
);
const controller = new AbortController();
const signal = controller.signal;
const timeoutId = setTimeout(
() => controller.abort(),
FORCE_UPDATE_TIMEOUT,
);
fetch(endpoint, { signal })
fetch(url, { signal })
.then((res) => res.blob())
.then((blob) => blob.text())
.then(async (response) => {
Expand All @@ -293,6 +294,8 @@ export class AutoUpdate {
if (match && match.length) {
logger.info('auto-update-handler: version found', match[1]);
resolve(match[1]);
} else {
resolve();
}
})
.catch(async (error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const startApplication = async () => {
// Validate user config before starting the application
await config.initializeUserConfig();
await config.readUserConfig();
await autoUpdate.performForcedAutoUpdate();
await config.checkFirstTimeLaunch();
const isFirstTimeLaunch = config.isFirstTimeLaunch();
if (isFirstTimeLaunch) {
Expand All @@ -109,6 +108,7 @@ const startApplication = async () => {
// Picks global config values and updates them in the user config
await config.updateUserConfigOnStart();
setSessionProperties();
await autoUpdate.performForcedAutoUpdate();
await windowHandler.createApplication();
logger.info(`main: created application`);
};
Expand Down

0 comments on commit 9e0bd41

Please sign in to comment.