1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/behaviours/application-update/sub-features/tray/main/install-application-update-tray-item.injectable.ts
Janne Savolainen 1d267c63fd
Relocate stuff under sub-features for application update
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-07-13 11:23:11 +03:00

55 lines
2.2 KiB
TypeScript

/**
* 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 { computed } from "mobx";
import { trayMenuItemInjectionToken } from "../../../../tray/main/tray-menu-item/tray-menu-item-injection-token";
import discoveredUpdateVersionInjectable from "../../../common/discovered-update-version/discovered-update-version.injectable";
import { withErrorSuppression } from "../../../../../common/utils/with-error-suppression/with-error-suppression";
import { pipeline } from "@ogre-tools/fp";
import withErrorLoggingInjectable from "../../../../../common/utils/with-error-logging/with-error-logging.injectable";
import quitAndInstallUpdateInjectable from "../../../main/quit-and-install-update.injectable";
import updateIsReadyToBeInstalledInjectable from "../../../main/update-is-ready-to-be-installed.injectable";
const installApplicationUpdateTrayItemInjectable = getInjectable({
id: "install-update-tray-item",
instantiate: (di) => {
const quitAndInstallUpdate = di.inject(quitAndInstallUpdateInjectable);
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
const updateIsReadyToBeInstalled = di.inject(updateIsReadyToBeInstalledInjectable);
return {
id: "install-update",
parentId: null,
orderNumber: 50,
label: computed(() => {
const versionToBeInstalled = discoveredVersionState.value.get()?.version;
return `Install update ${versionToBeInstalled}`;
}),
enabled: computed(() => true),
visible: updateIsReadyToBeInstalled,
click: pipeline(
quitAndInstallUpdate,
withErrorLoggingFor(() => "[TRAY]: Update installation failed."),
// TODO: Find out how to improve typing so that instead of
// x => withErrorSuppression(x) there could only be withErrorSuppression
(x) => withErrorSuppression(x),
),
};
},
injectionToken: trayMenuItemInjectionToken,
});
export default installApplicationUpdateTrayItemInjectable;