1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Improved metrics for updating application (#5607)

This commit is contained in:
Janne Savolainen 2022-06-16 16:05:00 +03:00 committed by GitHub
parent 7b0521f3b2
commit 5c049ecca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 373 additions and 32 deletions

View File

@ -0,0 +1,225 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { CheckForPlatformUpdates } from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import appEventBusInjectable from "../../common/app-event-bus/app-event-bus.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable";
import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import appVersionInjectable from "../../common/get-configuration-file-model/app-version/app-version.injectable";
import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
describe("analytics for installing update", () => {
let applicationBuilder: ApplicationBuilder;
let checkForPlatformUpdatesMock: AsyncFnMock<CheckForPlatformUpdates>;
let downloadPlatformUpdateMock: AsyncFnMock<DownloadPlatformUpdate>;
let analyticsListenerMock: jest.Mock;
let mainDi: DiContainer;
beforeEach(async () => {
jest.useFakeTimers();
global.Date.now = () => new Date("2015-10-21T07:28:00Z").getTime();
applicationBuilder = getApplicationBuilder();
analyticsListenerMock = jest.fn();
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
mainDi.override(appVersionInjectable, () => "42.0.0");
checkForPlatformUpdatesMock = asyncFn();
mainDi.override(
checkForPlatformUpdatesInjectable,
() => checkForPlatformUpdatesMock,
);
downloadPlatformUpdateMock = asyncFn();
mainDi.override(downloadPlatformUpdateInjectable, () => downloadPlatformUpdateMock);
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
mainDi.override(publishIsConfiguredInjectable, () => true);
const eventBus = mainDi.inject(appEventBusInjectable);
eventBus.addListener(analyticsListenerMock);
});
mainDi = applicationBuilder.dis.mainDi;
});
describe("given application is started and checking updates periodically", () => {
beforeEach(async () => {
mainDi.unoverride(periodicalCheckForUpdatesInjectable);
mainDi.permitSideEffects(periodicalCheckForUpdatesInjectable);
await applicationBuilder.render();
});
it("sends event to analytics for being checked periodically", () => {
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "periodic",
},
});
});
it("when enough time passes to check for updates again, sends event to analytics for being checked periodically", () => {
analyticsListenerMock.mockClear();
jest.advanceTimersByTime(1000 * 60 * 60 * 2);
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "periodic",
},
});
});
});
describe("when application is started", () => {
beforeEach(async () => {
analyticsListenerMock.mockClear();
await applicationBuilder.render();
});
it("sends event to analytics about the current version", () => {
expect(analyticsListenerMock).toHaveBeenCalledWith({
name: "app",
action: "current-version",
params: {
version: "42.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
},
});
});
it("when checking for updates using tray, sends event to analytics for being checked from tray", async () => {
analyticsListenerMock.mockClear();
applicationBuilder.tray.click("check-for-updates");
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "tray",
},
},
],
]);
});
it("when checking for updates using application menu, sends event to analytics for being checked from application menu", async () => {
analyticsListenerMock.mockClear();
applicationBuilder.applicationMenu.click("root.check-for-updates");
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "checking-for-updates",
params: {
currentDateTime: "2015-10-21T07:28:00Z",
source: "application-menu",
},
},
],
]);
});
describe("given checking for updates, when check for updates resolves with new update being available", () => {
beforeEach(async () => {
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant");
analyticsListenerMock.mockClear();
await checkForPlatformUpdatesMock.resolve({
updateWasDiscovered: true,
version: "43.0.0",
});
});
it("sends event to analytics about new update being available", () => {
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "update-was-discovered",
params: {
version: "43.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
},
},
],
]);
});
describe("given update is downloaded", () => {
beforeEach(async () => {
analyticsListenerMock.mockClear();
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
});
it("does not send event to analytics about update downloaded being successful", () => {
expect(analyticsListenerMock).not.toHaveBeenCalled();
});
it("when installing the update, sends event to analytics about installing the update", () => {
const quitAndInstallUpdate = mainDi.inject(quitAndInstallUpdateInjectable);
quitAndInstallUpdate();
expect(analyticsListenerMock.mock.calls).toEqual([
[
{
name: "app",
action: "start-installing-update",
params: {
version: "43.0.0",
currentDateTime: "2015-10-21T07:28:00Z",
updateChannel: "latest",
},
},
],
]);
});
});
});
});
});

View File

@ -22,8 +22,6 @@ describe("downgrading version update", () => {
let mainDi: DiContainer; let mainDi: DiContainer;
beforeEach(() => { beforeEach(() => {
jest.useFakeTimers();
applicationBuilder = getApplicationBuilder(); applicationBuilder = getApplicationBuilder();
applicationBuilder.beforeApplicationStart(({ mainDi }) => { applicationBuilder.beforeApplicationStart(({ mainDi }) => {
@ -79,7 +77,7 @@ describe("downgrading version update", () => {
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(expect.any(Object), { allowDowngrade: downgradeIsAllowed }); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(expect.any(Object), { allowDowngrade: downgradeIsAllowed });
}); });

View File

@ -4,7 +4,7 @@
*/ */
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import quitAndInstallUpdateInjectable from "../../main/electron-app/features/quit-and-install-update.injectable"; import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import type { RenderResult } from "@testing-library/react"; import type { RenderResult } from "@testing-library/react";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable"; import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable"; import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
@ -67,7 +67,7 @@ describe("installing update", () => {
describe("when started", () => { describe("when started", () => {
let rendered: RenderResult; let rendered: RenderResult;
let processCheckingForUpdates: () => Promise<void>; let processCheckingForUpdates: (source: string) => Promise<void>;
beforeEach(async () => { beforeEach(async () => {
rendered = await applicationBuilder.render(); rendered = await applicationBuilder.render();
@ -83,7 +83,7 @@ describe("installing update", () => {
let processCheckingForUpdatesPromise: Promise<void>; let processCheckingForUpdatesPromise: Promise<void>;
beforeEach(async () => { beforeEach(async () => {
processCheckingForUpdatesPromise = processCheckingForUpdates(); processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
}); });
it("checks for updates", () => { it("checks for updates", () => {

View File

@ -4,7 +4,7 @@
*/ */
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import quitAndInstallUpdateInjectable from "../../main/electron-app/features/quit-and-install-update.injectable"; import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import type { RenderResult } from "@testing-library/react"; import type { RenderResult } from "@testing-library/react";
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable"; import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable"; import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
@ -72,7 +72,7 @@ describe("selection of update stability", () => {
describe("when started", () => { describe("when started", () => {
let rendered: RenderResult; let rendered: RenderResult;
let processCheckingForUpdates: () => Promise<void>; let processCheckingForUpdates: (source: string) => Promise<void>;
beforeEach(async () => { beforeEach(async () => {
rendered = await applicationBuilder.render(); rendered = await applicationBuilder.render();
@ -97,7 +97,7 @@ describe("selection of update stability", () => {
selectedUpdateChannel.setValue(updateChannels.alpha.id); selectedUpdateChannel.setValue(updateChannels.alpha.id);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
}); });
it('checks updates from update channel "alpha"', () => { it('checks updates from update channel "alpha"', () => {
@ -191,7 +191,7 @@ describe("selection of update stability", () => {
describe("when checking for updates", () => { describe("when checking for updates", () => {
beforeEach(() => { beforeEach(() => {
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
}); });
describe('when update from "beta" channel is discovered', () => { describe('when update from "beta" channel is discovered', () => {
@ -241,7 +241,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object)); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
}); });
@ -259,7 +259,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.latest, expect.any(Object)); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.latest, expect.any(Object));
}); });
@ -273,7 +273,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
updateChannels.latest, updateChannels.latest,
@ -290,7 +290,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.alpha, expect.any(Object)); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.alpha, expect.any(Object));
}); });
@ -304,7 +304,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object)); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
}); });
@ -324,7 +324,7 @@ describe("selection of update stability", () => {
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable); const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates(); processCheckingForUpdates("irrelevant");
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object)); expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
}); });

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import appEventBusInjectable from "./app-event-bus.injectable";
const emitEventInjectable = getInjectable({
id: "emit-event",
instantiate: (di) => di.inject(appEventBusInjectable).emit,
});
export default emitEventInjectable;

View File

@ -0,0 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import moment from "moment";
export const getCurrentDateTime = () => moment().utc().format();

View File

@ -59,7 +59,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
click: pipeline( click: pipeline(
async () => { async () => {
await processCheckingForUpdates(); await processCheckingForUpdates("tray");
await showApplicationWindow(); await showApplicationWindow();
}, },

View File

@ -8,11 +8,13 @@ import updatesAreBeingDiscoveredInjectable from "../../../common/application-upd
import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable"; import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable";
import { runInAction } from "mobx"; import { runInAction } from "mobx";
import askBooleanInjectable from "../../ask-boolean/ask-boolean.injectable"; 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"; import downloadUpdateInjectable from "../download-update/download-update.injectable";
import broadcastChangeInUpdatingStatusInjectable from "./broadcast-change-in-updating-status.injectable"; import broadcastChangeInUpdatingStatusInjectable from "./broadcast-change-in-updating-status.injectable";
import checkForUpdatesStartingFromChannelInjectable from "./check-for-updates-starting-from-channel.injectable"; import checkForUpdatesStartingFromChannelInjectable from "./check-for-updates-starting-from-channel.injectable";
import withOrphanPromiseInjectable from "../../../common/utils/with-orphan-promise/with-orphan-promise.injectable"; import withOrphanPromiseInjectable from "../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
import emitEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
import { getCurrentDateTime } from "../../../common/utils/date/get-current-date-time";
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
const processCheckingForUpdatesInjectable = getInjectable({ const processCheckingForUpdatesInjectable = getInjectable({
id: "process-checking-for-updates", id: "process-checking-for-updates",
@ -27,8 +29,15 @@ const processCheckingForUpdatesInjectable = getInjectable({
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable); const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
const checkForUpdatesStartingFromChannel = di.inject(checkForUpdatesStartingFromChannelInjectable); const checkForUpdatesStartingFromChannel = di.inject(checkForUpdatesStartingFromChannelInjectable);
const withOrphanPromise = di.inject(withOrphanPromiseInjectable); const withOrphanPromise = di.inject(withOrphanPromiseInjectable);
const emitEvent = di.inject(emitEventInjectable);
return async (source: string) => {
emitEvent({
name: "app",
action: "checking-for-updates",
params: { currentDateTime: getCurrentDateTime(), source },
});
return async () => {
broadcastChangeInUpdatingStatus({ eventId: "checking-for-updates" }); broadcastChangeInUpdatingStatus({ eventId: "checking-for-updates" });
runInAction(() => { runInAction(() => {
@ -50,6 +59,12 @@ const processCheckingForUpdatesInjectable = getInjectable({
const { version, actualUpdateChannel } = result; const { version, actualUpdateChannel } = result;
emitEvent({
name: "app",
action: "update-was-discovered",
params: { version, currentDateTime: getCurrentDateTime() },
});
broadcastChangeInUpdatingStatus({ broadcastChangeInUpdatingStatus({
eventId: "download-for-update-started", eventId: "download-for-update-started",
version, version,

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { afterApplicationIsLoadedInjectionToken } from "../start-main-application/runnable-tokens/after-application-is-loaded-injection-token";
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
import { getCurrentDateTime } from "../../common/utils/date/get-current-date-time";
import appVersionInjectable from "../../common/get-configuration-file-model/app-version/app-version.injectable";
const emitCurrentVersionToAnalyticsInjectable = getInjectable({
id: "emit-current-version-to-analytics",
instantiate: (di) => {
const emitEvent = di.inject(emitEventInjectable);
const appVersion = di.inject(appVersionInjectable);
return {
run: () => {
emitEvent({
name: "app",
action: "current-version",
params: {
version: appVersion,
currentDateTime: getCurrentDateTime(),
},
});
},
};
},
injectionToken: afterApplicationIsLoadedInjectionToken,
});
export default emitCurrentVersionToAnalyticsInjectable;

View File

@ -5,12 +5,12 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; import { computed } from "mobx";
import { trayMenuItemInjectionToken } from "../tray/tray-menu-item/tray-menu-item-injection-token"; import { trayMenuItemInjectionToken } from "../tray/tray-menu-item/tray-menu-item-injection-token";
import quitAndInstallUpdateInjectable from "../electron-app/features/quit-and-install-update.injectable";
import discoveredUpdateVersionInjectable from "../../common/application-update/discovered-update-version/discovered-update-version.injectable"; import discoveredUpdateVersionInjectable from "../../common/application-update/discovered-update-version/discovered-update-version.injectable";
import updateIsBeingDownloadedInjectable from "../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable"; import updateIsBeingDownloadedInjectable from "../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
import { withErrorSuppression } from "../../common/utils/with-error-suppression/with-error-suppression"; import { withErrorSuppression } from "../../common/utils/with-error-suppression/with-error-suppression";
import { pipeline } from "@ogre-tools/fp"; import { pipeline } from "@ogre-tools/fp";
import withErrorLoggingInjectable from "../../common/utils/with-error-logging/with-error-logging.injectable"; import withErrorLoggingInjectable from "../../common/utils/with-error-logging/with-error-logging.injectable";
import quitAndInstallUpdateInjectable from "./quit-and-install-update.injectable";
const installApplicationUpdateTrayItemInjectable = getInjectable({ const installApplicationUpdateTrayItemInjectable = getInjectable({
id: "install-update-tray-item", id: "install-update-tray-item",

View File

@ -5,22 +5,23 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import processCheckingForUpdatesInjectable from "../check-for-updates/process-checking-for-updates.injectable"; import processCheckingForUpdatesInjectable from "../check-for-updates/process-checking-for-updates.injectable";
import withOrphanPromiseInjectable from "../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
const periodicalCheckForUpdatesInjectable = getInjectable({ const periodicalCheckForUpdatesInjectable = getInjectable({
id: "periodical-check-for-updates", id: "periodical-check-for-updates",
instantiate: (di) => { instantiate: (di) => {
const processCheckingForUpdates = di.inject(processCheckingForUpdatesInjectable); const withOrphanPromise = di.inject(withOrphanPromiseInjectable);
const processCheckingForUpdates = withOrphanPromise(di.inject(processCheckingForUpdatesInjectable));
return getStartableStoppable("periodical-check-for-updates", () => { return getStartableStoppable("periodical-check-for-updates", () => {
const TWO_HOURS = 1000 * 60 * 60 * 2; const TWO_HOURS = 1000 * 60 * 60 * 2;
// Note: intentional orphan promise to make checking for updates happen in the background processCheckingForUpdates("periodic");
processCheckingForUpdates();
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
// Note: intentional orphan promise to make checking for updates happen in the background
processCheckingForUpdates(); processCheckingForUpdates("periodic");
}, TWO_HOURS); }, TWO_HOURS);
return () => { return () => {

View File

@ -0,0 +1,45 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import electronQuitAndInstallUpdateInjectable from "../electron-app/features/electron-quit-and-install-update.injectable";
import { getCurrentDateTime } from "../../common/utils/date/get-current-date-time";
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
import discoveredUpdateVersionInjectable from "../../common/application-update/discovered-update-version/discovered-update-version.injectable";
const quitAndInstallUpdateInjectable = getInjectable({
id: "quit-and-install-update",
instantiate: (di) => {
const electronQuitAndInstallUpdate = di.inject(
electronQuitAndInstallUpdateInjectable,
);
const emitEvent = di.inject(emitEventInjectable);
const discoveredUpdateVersion = di.inject(discoveredUpdateVersionInjectable);
return () => {
const discoveredVersion = discoveredUpdateVersion.value.get();
if (!discoveredVersion) {
throw new Error("Tried to install update but no update was discovered.");
}
emitEvent({
name: "app",
action: "start-installing-update",
params: {
version: discoveredVersion.version,
updateChannel: discoveredVersion.updateChannel.id,
currentDateTime: getCurrentDateTime(),
},
});
electronQuitAndInstallUpdate();
};
},
});
export default quitAndInstallUpdateInjectable;

View File

@ -5,8 +5,8 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import electronUpdaterInjectable from "./electron-updater.injectable"; import electronUpdaterInjectable from "./electron-updater.injectable";
const quitAndInstallUpdateInjectable = getInjectable({ const electronQuitAndInstallUpdateInjectable = getInjectable({
id: "quit-and-install-update", id: "electron-quit-and-install-update",
instantiate: (di) => { instantiate: (di) => {
const electronUpdater = di.inject(electronUpdaterInjectable); const electronUpdater = di.inject(electronUpdaterInjectable);
@ -17,4 +17,4 @@ const quitAndInstallUpdateInjectable = getInjectable({
}, },
}); });
export default quitAndInstallUpdateInjectable; export default electronQuitAndInstallUpdateInjectable;

View File

@ -72,7 +72,7 @@ import getElectronThemeInjectable from "./electron-app/features/get-electron-the
import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable"; import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable";
import platformInjectable from "../common/vars/platform.injectable"; import platformInjectable from "../common/vars/platform.injectable";
import productNameInjectable from "./app-paths/app-name/product-name.injectable"; import productNameInjectable from "./app-paths/app-name/product-name.injectable";
import quitAndInstallUpdateInjectable from "./electron-app/features/quit-and-install-update.injectable"; import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable";
import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable"; import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "./application-update/publish-is-configured.injectable"; import publishIsConfiguredInjectable from "./application-update/publish-is-configured.injectable";
import checkForPlatformUpdatesInjectable from "./application-update/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./application-update/check-for-platform-updates/check-for-platform-updates.injectable";
@ -250,7 +250,7 @@ const overrideElectronFeatures = (di: DiContainer) => {
di.override(ipcMainInjectable, () => ({})); di.override(ipcMainInjectable, () => ({}));
di.override(getElectronThemeInjectable, () => () => "dark"); di.override(getElectronThemeInjectable, () => () => "dark");
di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} })); di.override(syncThemeFromOperatingSystemInjectable, () => ({ start: () => {}, stop: () => {} }));
di.override(quitAndInstallUpdateInjectable, () => () => {}); di.override(electronQuitAndInstallUpdateInjectable, () => () => {});
di.override(setUpdateOnQuitInjectable, () => () => {}); di.override(setUpdateOnQuitInjectable, () => () => {});
di.override(downloadPlatformUpdateInjectable, () => async () => ({ downloadWasSuccessful: true })); di.override(downloadPlatformUpdateInjectable, () => async () => ({ downloadWasSuccessful: true }));

View File

@ -71,9 +71,10 @@ const applicationMenuItemsInjectable = getInjectable({
}, },
...ignoreIf(!updatingIsEnabled, [ ...ignoreIf(!updatingIsEnabled, [
{ {
id: "check-for-updates",
label: "Check for updates", label: "Check for updates",
click() { click() {
processCheckingForUpdates().then(() => showApplicationWindow()); processCheckingForUpdates("application-menu").then(() => showApplicationWindow());
}, },
}, },
]), ]),
@ -285,7 +286,7 @@ const applicationMenuItemsInjectable = getInjectable({
{ {
label: "Check for updates", label: "Check for updates",
click() { click() {
processCheckingForUpdates().then(() => processCheckingForUpdates("periodic").then(() =>
showApplicationWindow(), showApplicationWindow(),
); );
}, },