From 5aa8718f901d4ba3750efa06f797de0b67403f33 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 27 Jun 2022 13:01:00 +0300 Subject: [PATCH] Add sync box files allowing to restart & install update from renderer process Signed-off-by: Alex Andreev --- ...t-and-install-update-channel.injectable.ts | 20 ++++++++++++++ .../update-warning-level.injectable.ts | 4 +-- .../restart-and-install-update.listener.ts | 26 +++++++++++++++++++ .../set-update-warning-level.injectable.ts | 2 +- .../restart-and-install-update.injectable.ts | 18 +++++++++++++ .../update-button/update-button.tsx | 10 +++---- 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 src/common/application-update/update-warning-level/restart-and-install-update-channel.injectable.ts rename src/common/application-update/{ => update-warning-level}/update-warning-level.injectable.ts (71%) create mode 100644 src/main/application-update/update-warning-level/restart-and-install-update.listener.ts create mode 100644 src/renderer/components/update-button/restart-and-install-update.injectable.ts diff --git a/src/common/application-update/update-warning-level/restart-and-install-update-channel.injectable.ts b/src/common/application-update/update-warning-level/restart-and-install-update-channel.injectable.ts new file mode 100644 index 0000000000..9ee9f89ee0 --- /dev/null +++ b/src/common/application-update/update-warning-level/restart-and-install-update-channel.injectable.ts @@ -0,0 +1,20 @@ +/** + * 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 { MessageChannel, messageChannelInjectionToken } from "../../utils/channel/message-channel-injection-token"; + +export type RestartAndInstallUpdateChannel = MessageChannel; + +const restartAndInstallUpdateChannel = getInjectable({ + id: "restart-and-install-update-channel", + + instantiate: (): RestartAndInstallUpdateChannel => ({ + id: "restart-and-install-update-channel", + }), + + injectionToken: messageChannelInjectionToken, +}); + +export default restartAndInstallUpdateChannel; diff --git a/src/common/application-update/update-warning-level.injectable.ts b/src/common/application-update/update-warning-level/update-warning-level.injectable.ts similarity index 71% rename from src/common/application-update/update-warning-level.injectable.ts rename to src/common/application-update/update-warning-level/update-warning-level.injectable.ts index c589371ebf..694fff6842 100644 --- a/src/common/application-update/update-warning-level.injectable.ts +++ b/src/common/application-update/update-warning-level/update-warning-level.injectable.ts @@ -1,6 +1,6 @@ import { getInjectable } from "@ogre-tools/injectable"; -import createSyncBoxInjectable from "../utils/sync-box/create-sync-box.injectable"; -import { syncBoxInjectionToken } from "../utils/sync-box/sync-box-injection-token"; +import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable"; +import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token"; const updateWarningLevelInjectable = getInjectable({ id: "update-warning-level", diff --git a/src/main/application-update/update-warning-level/restart-and-install-update.listener.ts b/src/main/application-update/update-warning-level/restart-and-install-update.listener.ts new file mode 100644 index 0000000000..d1c612846d --- /dev/null +++ b/src/main/application-update/update-warning-level/restart-and-install-update.listener.ts @@ -0,0 +1,26 @@ +/** + * 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 restartAndInstallUpdateChannel from "../../../common/application-update/update-warning-level/restart-and-install-update-channel.injectable"; +import { messageChannelListenerInjectionToken } from "../../../common/utils/channel/message-channel-listener-injection-token"; +import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable"; + +const restartAndInstallUpdateListenerInjectable = getInjectable({ + id: "restart-and-install-update-listener", + + instantiate: (di) => { + const quitAndInstall = di.inject(quitAndInstallUpdateInjectable); + const channel = di.inject(restartAndInstallUpdateChannel); + + return { + channel, + handler: quitAndInstall, + }; + }, + + injectionToken: messageChannelListenerInjectionToken, +}); + +export default restartAndInstallUpdateListenerInjectable; diff --git a/src/main/application-update/update-warning-level/set-update-warning-level.injectable.ts b/src/main/application-update/update-warning-level/set-update-warning-level.injectable.ts index 124f2336bf..e1d54a7654 100644 --- a/src/main/application-update/update-warning-level/set-update-warning-level.injectable.ts +++ b/src/main/application-update/update-warning-level/set-update-warning-level.injectable.ts @@ -1,7 +1,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import updateDownloadedDateInjectable from "./update-downloaded-date.injectable"; import { UpdateWarningLevelCalculator } from "./update-warning-level-calculator"; -import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level.injectable"; +import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level/update-warning-level.injectable"; const setUpdateWarningLevelInjectable = getInjectable({ id: "set-update-warning", diff --git a/src/renderer/components/update-button/restart-and-install-update.injectable.ts b/src/renderer/components/update-button/restart-and-install-update.injectable.ts new file mode 100644 index 0000000000..fe1f7d2a27 --- /dev/null +++ b/src/renderer/components/update-button/restart-and-install-update.injectable.ts @@ -0,0 +1,18 @@ +import { getInjectable } from "@ogre-tools/injectable"; +import restartAndInstallUpdateChannel from "../../../common/application-update/update-warning-level/restart-and-install-update-channel.injectable"; +import messageToChannelInjectable from "../../utils/channel/message-to-channel.injectable"; + +const restartAndInstallUpdateInjectable = getInjectable({ + id: "restart-and-install-update", + + instantiate: (di) => { + const messageToChannel = di.inject(messageToChannelInjectable); + const channel = di.inject(restartAndInstallUpdateChannel); + + return () => { + messageToChannel(channel); + }; + }, +}); + +export default restartAndInstallUpdateInjectable; \ No newline at end of file diff --git a/src/renderer/components/update-button/update-button.tsx b/src/renderer/components/update-button/update-button.tsx index 51fd5b45fa..5654eaabf3 100644 --- a/src/renderer/components/update-button/update-button.tsx +++ b/src/renderer/components/update-button/update-button.tsx @@ -8,13 +8,14 @@ import styles from "./styles.module.scss"; import type { HTMLAttributes } from "react"; import React, { useState } from "react"; import { Menu, MenuItem } from "../menu"; -import { cssNames, noop } from "../../utils"; +import { cssNames } from "../../utils"; import type { IconProps } from "../icon"; import { Icon } from "../icon"; import { withInjectables } from "@ogre-tools/injectable-react"; import { observer } from "mobx-react"; -import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level.injectable"; +import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level/update-warning-level.injectable"; import { computed, IComputedValue } from "mobx"; +import restartAndInstallUpdateInjectable from "./restart-and-install-update.injectable"; interface UpdateButtonProps extends HTMLAttributes { } @@ -74,13 +75,10 @@ export const UpdateButton = withInjectables(Non getProps: (di, props) => { const warnignLevel = di.inject(updateWarningLevelInjectable); - // TODO: quit and install on update(); - const update = noop; - return { ...props, warningLevel: computed(() => warnignLevel.value.get()), - update, + update: di.inject(restartAndInstallUpdateInjectable), }; }, });