mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Simplify interaction with updater and main process
This commit is contained in:
12
app/main.ts
12
app/main.ts
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user