1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/update-app/check-for-updates-tray-item.injectable.ts
Janne Savolainen 4b2aaa8923
Expand scope of behaviour for updating using tray also contain checking for updates
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-05-20 14:08:34 +03:00

60 lines
2.0 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 updatingIsEnabledInjectable from "./updating-is-enabled.injectable";
import { trayMenuItemInjectionToken } from "../tray/tray-menu-item/tray-menu-item-injection-token";
import versionUpdateInjectable from "./version-update.injectable";
import progressOfUpdateDownloadInjectable from "./progress-of-update-download.injectable";
import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable";
const checkForUpdatesTrayItemInjectable = getInjectable({
id: "check-for-updates-tray-item",
instantiate: (di) => {
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const updatingIsEnabled = di.inject(updatingIsEnabledInjectable);
const versionUpdate = di.inject(versionUpdateInjectable);
const progressOfUpdateDownload = di.inject(progressOfUpdateDownloadInjectable);
return {
id: "check-for-updates",
parentId: null,
orderNumber: 30,
label: computed(() => {
if (versionUpdate.downloading.get()) {
return `Downloading update "${versionUpdate.discoveredVersion.get()}" (${progressOfUpdateDownload.value.get()}%)...`;
}
if (versionUpdate.checking.get()) {
return "Checking for updates...";
}
return "Check for updates";
}),
enabled: computed(() => !versionUpdate.checking.get() && !versionUpdate.downloading.get()),
visible: computed(() => updatingIsEnabled),
click: async () => {
const { updateWasDiscovered } = await versionUpdate.checkForUpdates();
if (updateWasDiscovered) {
versionUpdate.downloadUpdate();
}
// await showApplicationWindow();
},
};
},
injectionToken: trayMenuItemInjectionToken,
});
export default checkForUpdatesTrayItemInjectable;