From 62ea050f945a43f05ee91e26da8bebfd585e9d8f Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 2 Jun 2022 15:32:18 -0400 Subject: [PATCH] Fix CheckForUpdate type errors Signed-off-by: Sebastian Malton --- .../check-for-platform-updates.injectable.ts | 9 ++++++++- ...k-for-updates-starting-from-channel.injectable.ts | 12 +++++++----- .../process-checking-for-updates.injectable.ts | 12 ++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/application-update/check-for-platform-updates/check-for-platform-updates.injectable.ts b/src/main/application-update/check-for-platform-updates/check-for-platform-updates.injectable.ts index edf36722c6..286999c484 100644 --- a/src/main/application-update/check-for-platform-updates/check-for-platform-updates.injectable.ts +++ b/src/main/application-update/check-for-platform-updates/check-for-platform-updates.injectable.ts @@ -8,7 +8,14 @@ import type { UpdateChannel } from "../../../common/application-update/update-ch import loggerInjectable from "../../../common/logger.injectable"; import type { UpdateCheckResult } from "electron-updater"; -export type CheckForPlatformUpdates = (updateChannel: UpdateChannel, opts: { allowDowngrade: boolean }) => Promise<{ updateWasDiscovered: boolean; version?: string }>; +export type CheckForUpdatesResult = { + updateWasDiscovered: false; +} | { + updateWasDiscovered: true; + version: string; +}; + +export type CheckForPlatformUpdates = (updateChannel: UpdateChannel, opts: { allowDowngrade: boolean }) => Promise; const checkForPlatformUpdatesInjectable = getInjectable({ id: "check-for-platform-updates", diff --git a/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts b/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts index dd13842036..caf695ff80 100644 --- a/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts +++ b/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts @@ -7,11 +7,13 @@ import type { UpdateChannel } from "../../../common/application-update/update-ch import checkForPlatformUpdatesInjectable from "../check-for-platform-updates/check-for-platform-updates.injectable"; import updateCanBeDowngradedInjectable from "./update-can-be-downgraded.injectable"; -interface CheckForUpdatesFromChannelResult { - updateWasDiscovered: boolean; - version?: string; - actualUpdateChannel?: UpdateChannel; -} +export type CheckForUpdatesFromChannelResult = { + updateWasDiscovered: false; +} | { + updateWasDiscovered: true; + version: string; + actualUpdateChannel: UpdateChannel; +}; const checkForUpdatesStartingFromChannelInjectable = getInjectable({ id: "check-for-updates-starting-from-channel", diff --git a/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts b/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts index 752d6cd01e..2688d00d4a 100644 --- a/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts +++ b/src/main/application-update/check-for-updates/process-checking-for-updates.injectable.ts @@ -7,7 +7,6 @@ import selectedUpdateChannelInjectable from "../../../common/application-update/ import updatesAreBeingDiscoveredInjectable from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable"; import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable"; import { runInAction } from "mobx"; -import assert from "assert"; import askBooleanInjectable from "../../ask-boolean/ask-boolean.injectable"; import quitAndInstallUpdateInjectable from "../../electron-app/features/quit-and-install-update.injectable"; import downloadUpdateInjectable from "../download-update/download-update.injectable"; @@ -36,10 +35,9 @@ const processCheckingForUpdatesInjectable = getInjectable({ checkingForUpdatesState.set(true); }); - const { updateWasDiscovered, version, actualUpdateChannel } = - await checkForUpdatesStartingFromChannel(selectedUpdateChannel.value.get()); + const result = await checkForUpdatesStartingFromChannel(selectedUpdateChannel.value.get()); - if (!updateWasDiscovered) { + if (!result.updateWasDiscovered) { broadcastChangeInUpdatingStatus({ eventId: "no-updates-available" }); runInAction(() => { @@ -50,16 +48,14 @@ const processCheckingForUpdatesInjectable = getInjectable({ return; } + const { version, actualUpdateChannel } = result; + broadcastChangeInUpdatingStatus({ eventId: "download-for-update-started", version, }); runInAction(() => { - // TODO: Unacceptable damage caused by strict mode - assert(version); - assert(actualUpdateChannel); - discoveredVersionState.set({ version, updateChannel: actualUpdateChannel,