Simplify interaction with updater and main process

This commit is contained in:
yash-signal
2025-08-18 11:38:13 -05:00
committed by GitHub
parent 27fd03f5f0
commit 9f7298c666
3 changed files with 23 additions and 18 deletions

View File

@@ -127,6 +127,7 @@ import { getAppErrorIcon } from '../ts/util/getAppErrorIcon';
import { promptOSAuth } from '../ts/util/os/promptOSAuthMain';
const log = createLogger('app/main');
const updaterLog = log.child('updater');
const animationSettings = systemPreferences.getAnimationSettings();
@@ -1156,20 +1157,23 @@ async function readyForUpdates() {
);
},
getMainWindow,
logger: log,
logger: updaterLog,
sql,
});
} catch (error) {
log.error('Error starting update checks:', Errors.toLogFormat(error));
updaterLog.error(
'Error starting update checks:',
Errors.toLogFormat(error)
);
}
}
async function forceUpdate() {
try {
log.info('starting force update');
updaterLog.info('starting force update');
await updater.force();
} catch (error) {
log.error('Error during force update:', Errors.toLogFormat(error));
updaterLog.error('Error during force update:', Errors.toLogFormat(error));
}
}

View File

@@ -200,7 +200,7 @@ export abstract class Updater {
}
this.logger.info(
'updater/onRestartCanceled: restart was canceled. forcing update to reset updater state'
'onRestartCanceled: restart was canceled. forcing update to reset updater state'
);
this.#restarting = false;
markShouldNotQuit();
@@ -208,7 +208,7 @@ export abstract class Updater {
}
public async start(): Promise<void> {
this.logger.info('updater/start: starting checks...');
this.logger.info('start: starting checks...');
this.#schedulePoll();
@@ -244,7 +244,7 @@ export abstract class Updater {
): void {
if (this.#markedCannotUpdate) {
this.logger.warn(
'updater/markCannotUpdate: already marked',
'markCannotUpdate: already marked',
Errors.toLogFormat(error)
);
return;
@@ -252,7 +252,7 @@ export abstract class Updater {
this.#markedCannotUpdate = true;
this.logger.error(
'updater/markCannotUpdate: marking due to error: ' +
'markCannotUpdate: marking due to error: ' +
`${Errors.toLogFormat(error)}, ` +
`dialogType: ${dialogType}`
);
@@ -261,7 +261,7 @@ export abstract class Updater {
mainWindow?.webContents.send('show-update-dialog', dialogType);
this.setUpdateListener(async () => {
this.logger.info('updater/markCannotUpdate: retrying after user action');
this.logger.info('markCannotUpdate: retrying after user action');
this.#markedCannotUpdate = false;
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
@@ -269,6 +269,9 @@ export abstract class Updater {
}
protected markRestarting(): void {
this.logger.info(
'markRestarting: preparing to restart application for update'
);
this.#restarting = true;
markShouldQuit();
}
@@ -286,7 +289,7 @@ export abstract class Updater {
);
const timeoutMs = selectedPollTime - now;
this.logger.info(`updater/schedulePoll: polling in ${timeoutMs}ms`);
this.logger.info(`schedulePoll: polling in ${timeoutMs}ms`);
setTimeout(() => {
drop(this.#safePoll());
@@ -296,16 +299,14 @@ export abstract class Updater {
async #safePoll(): Promise<void> {
try {
if (this.#autoRetryAfter != null && Date.now() < this.#autoRetryAfter) {
this.logger.info(
`updater/safePoll: not polling until ${this.#autoRetryAfter}`
);
this.logger.info(`safePoll: not polling until ${this.#autoRetryAfter}`);
return;
}
this.logger.info('updater/safePoll: polling now');
this.logger.info('safePoll: polling now');
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
} catch (error) {
this.logger.error(`updater/safePoll: ${Errors.toLogFormat(error)}`);
this.logger.error(`safePoll: ${Errors.toLogFormat(error)}`);
} finally {
this.#schedulePoll();
}

View File

@@ -156,13 +156,13 @@ export function isTimeToUpdate({
}): boolean {
// Check that the release date is a proper number
if (!Number.isFinite(releasedAt) || Number.isNaN(releasedAt)) {
logger.warn('updater/isTimeToUpdate: invalid releasedAt');
logger.warn('isTimeToUpdate: invalid releasedAt');
return true;
}
// Check that the release date is not too far in the future
if (releasedAt - HOUR > now) {
logger.warn('updater/isTimeToUpdate: releasedAt too far in the future');
logger.warn('isTimeToUpdate: releasedAt too far in the future');
return true;
}
@@ -180,6 +180,6 @@ export function isTimeToUpdate({
}
const remaining = Math.round((updateAt - now) / MINUTE);
logger.info(`updater/isTimeToUpdate: updating in ${remaining} minutes`);
logger.info(`isTimeToUpdate: updating in ${remaining} minutes`);
return false;
}