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';
|
import { promptOSAuth } from '../ts/util/os/promptOSAuthMain';
|
||||||
|
|
||||||
const log = createLogger('app/main');
|
const log = createLogger('app/main');
|
||||||
|
const updaterLog = log.child('updater');
|
||||||
|
|
||||||
const animationSettings = systemPreferences.getAnimationSettings();
|
const animationSettings = systemPreferences.getAnimationSettings();
|
||||||
|
|
||||||
@@ -1156,20 +1157,23 @@ async function readyForUpdates() {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getMainWindow,
|
getMainWindow,
|
||||||
logger: log,
|
logger: updaterLog,
|
||||||
sql,
|
sql,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error('Error starting update checks:', Errors.toLogFormat(error));
|
updaterLog.error(
|
||||||
|
'Error starting update checks:',
|
||||||
|
Errors.toLogFormat(error)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function forceUpdate() {
|
async function forceUpdate() {
|
||||||
try {
|
try {
|
||||||
log.info('starting force update');
|
updaterLog.info('starting force update');
|
||||||
await updater.force();
|
await updater.force();
|
||||||
} catch (error) {
|
} 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(
|
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;
|
this.#restarting = false;
|
||||||
markShouldNotQuit();
|
markShouldNotQuit();
|
||||||
@@ -208,7 +208,7 @@ export abstract class Updater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async start(): Promise<void> {
|
public async start(): Promise<void> {
|
||||||
this.logger.info('updater/start: starting checks...');
|
this.logger.info('start: starting checks...');
|
||||||
|
|
||||||
this.#schedulePoll();
|
this.#schedulePoll();
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ export abstract class Updater {
|
|||||||
): void {
|
): void {
|
||||||
if (this.#markedCannotUpdate) {
|
if (this.#markedCannotUpdate) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
'updater/markCannotUpdate: already marked',
|
'markCannotUpdate: already marked',
|
||||||
Errors.toLogFormat(error)
|
Errors.toLogFormat(error)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -252,7 +252,7 @@ export abstract class Updater {
|
|||||||
this.#markedCannotUpdate = true;
|
this.#markedCannotUpdate = true;
|
||||||
|
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
'updater/markCannotUpdate: marking due to error: ' +
|
'markCannotUpdate: marking due to error: ' +
|
||||||
`${Errors.toLogFormat(error)}, ` +
|
`${Errors.toLogFormat(error)}, ` +
|
||||||
`dialogType: ${dialogType}`
|
`dialogType: ${dialogType}`
|
||||||
);
|
);
|
||||||
@@ -261,7 +261,7 @@ export abstract class Updater {
|
|||||||
mainWindow?.webContents.send('show-update-dialog', dialogType);
|
mainWindow?.webContents.send('show-update-dialog', dialogType);
|
||||||
|
|
||||||
this.setUpdateListener(async () => {
|
this.setUpdateListener(async () => {
|
||||||
this.logger.info('updater/markCannotUpdate: retrying after user action');
|
this.logger.info('markCannotUpdate: retrying after user action');
|
||||||
|
|
||||||
this.#markedCannotUpdate = false;
|
this.#markedCannotUpdate = false;
|
||||||
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
|
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
|
||||||
@@ -269,6 +269,9 @@ export abstract class Updater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected markRestarting(): void {
|
protected markRestarting(): void {
|
||||||
|
this.logger.info(
|
||||||
|
'markRestarting: preparing to restart application for update'
|
||||||
|
);
|
||||||
this.#restarting = true;
|
this.#restarting = true;
|
||||||
markShouldQuit();
|
markShouldQuit();
|
||||||
}
|
}
|
||||||
@@ -286,7 +289,7 @@ export abstract class Updater {
|
|||||||
);
|
);
|
||||||
const timeoutMs = selectedPollTime - now;
|
const timeoutMs = selectedPollTime - now;
|
||||||
|
|
||||||
this.logger.info(`updater/schedulePoll: polling in ${timeoutMs}ms`);
|
this.logger.info(`schedulePoll: polling in ${timeoutMs}ms`);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
drop(this.#safePoll());
|
drop(this.#safePoll());
|
||||||
@@ -296,16 +299,14 @@ export abstract class Updater {
|
|||||||
async #safePoll(): Promise<void> {
|
async #safePoll(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (this.#autoRetryAfter != null && Date.now() < this.#autoRetryAfter) {
|
if (this.#autoRetryAfter != null && Date.now() < this.#autoRetryAfter) {
|
||||||
this.logger.info(
|
this.logger.info(`safePoll: not polling until ${this.#autoRetryAfter}`);
|
||||||
`updater/safePoll: not polling until ${this.#autoRetryAfter}`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info('updater/safePoll: polling now');
|
this.logger.info('safePoll: polling now');
|
||||||
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
|
await this.#checkForUpdatesMaybeInstall(CheckType.Normal);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`updater/safePoll: ${Errors.toLogFormat(error)}`);
|
this.logger.error(`safePoll: ${Errors.toLogFormat(error)}`);
|
||||||
} finally {
|
} finally {
|
||||||
this.#schedulePoll();
|
this.#schedulePoll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,13 +156,13 @@ export function isTimeToUpdate({
|
|||||||
}): boolean {
|
}): boolean {
|
||||||
// Check that the release date is a proper number
|
// Check that the release date is a proper number
|
||||||
if (!Number.isFinite(releasedAt) || Number.isNaN(releasedAt)) {
|
if (!Number.isFinite(releasedAt) || Number.isNaN(releasedAt)) {
|
||||||
logger.warn('updater/isTimeToUpdate: invalid releasedAt');
|
logger.warn('isTimeToUpdate: invalid releasedAt');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the release date is not too far in the future
|
// Check that the release date is not too far in the future
|
||||||
if (releasedAt - HOUR > now) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +180,6 @@ export function isTimeToUpdate({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const remaining = Math.round((updateAt - now) / MINUTE);
|
const remaining = Math.round((updateAt - now) / MINUTE);
|
||||||
logger.info(`updater/isTimeToUpdate: updating in ${remaining} minutes`);
|
logger.info(`isTimeToUpdate: updating in ${remaining} minutes`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user