mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Show notifications and dialog for downloading update
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
b970e69165
commit
52303b170b
7 files changed
+126
-207
No files matched your search
@@ -9,6 +9,9 @@ import { trayMenuItemInjectionToken } from "../tray/tray-menu-item/tray-menu-ite
|
||||
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";
|
||||
import showNotificationInjectable from "../show-notification/show-notification.injectable";
|
||||
import askBooleanInjectable from "../ask-boolean/ask-boolean.injectable";
|
||||
import quitAndInstallUpdateInjectable from "../electron-app/features/quit-and-install-update.injectable";
|
||||
|
||||
const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||
id: "check-for-updates-tray-item",
|
||||
@@ -18,6 +21,9 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||
const updatingIsEnabled = di.inject(updatingIsEnabledInjectable);
|
||||
const versionUpdate = di.inject(versionUpdateInjectable);
|
||||
const progressOfUpdateDownload = di.inject(progressOfUpdateDownloadInjectable);
|
||||
const showNotification = di.inject(showNotificationInjectable);
|
||||
const askBoolean = di.inject(askBooleanInjectable);
|
||||
const quitAndInstallUpdate = di.inject(quitAndInstallUpdateInjectable);
|
||||
|
||||
return {
|
||||
id: "check-for-updates",
|
||||
@@ -26,7 +32,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||
|
||||
label: computed(() => {
|
||||
if (versionUpdate.downloading.get()) {
|
||||
return `Downloading update "${versionUpdate.discoveredVersion.get()}" (${progressOfUpdateDownload.value.get()}%)...`;
|
||||
return `Downloading update ${versionUpdate.discoveredVersion.get()} (${progressOfUpdateDownload.value.get()}%)...`;
|
||||
}
|
||||
|
||||
if (versionUpdate.checking.get()) {
|
||||
@@ -41,11 +47,19 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||
visible: computed(() => updatingIsEnabled),
|
||||
|
||||
click: async () => {
|
||||
const { updateWasDiscovered } = await versionUpdate.checkForUpdates();
|
||||
const { updateWasDiscovered, version } = await versionUpdate.checkForUpdates();
|
||||
|
||||
if (updateWasDiscovered) {
|
||||
showNotification(`Downloading update ${version}...`);
|
||||
|
||||
// Note: intentional orphan promise to make download happen in the background
|
||||
versionUpdate.downloadUpdate();
|
||||
versionUpdate.downloadUpdate().then(async () => {
|
||||
const userWantsToInstallUpdate = await askBoolean(`Do you want to install update ${version}?`);
|
||||
|
||||
if (userWantsToInstallUpdate) {
|
||||
quitAndInstallUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await showApplicationWindow();
|
||||
|
||||
@@ -23,7 +23,7 @@ const installApplicationUpdateTrayItemInjectable = getInjectable({
|
||||
label: computed(() => {
|
||||
const versionToBeInstalled = versionUpdate.discoveredVersion.get();
|
||||
|
||||
return `Install update "${versionToBeInstalled}"`;
|
||||
return `Install update ${versionToBeInstalled}`;
|
||||
}),
|
||||
|
||||
enabled: computed(() => true),
|
||||
|
||||
@@ -10,6 +10,7 @@ import downloadPlatformUpdateInjectable from "./download-platform-update.injecta
|
||||
import type { CheckForPlatformUpdates } from "./check-for-platform-updates.injectable";
|
||||
import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable";
|
||||
import type { UpdateChannel } from "./update-channels";
|
||||
import showNotificationInjectable from "../show-notification/show-notification.injectable";
|
||||
|
||||
const versionUpdateInjectable = getInjectable({
|
||||
id: "version-update",
|
||||
@@ -18,6 +19,7 @@ const versionUpdateInjectable = getInjectable({
|
||||
const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable);
|
||||
const downloadPlatformUpdate = di.inject(downloadPlatformUpdateInjectable);
|
||||
const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable);
|
||||
const showNotification = di.inject(showNotificationInjectable);
|
||||
|
||||
const discoveredVersionState = observable.box<string>();
|
||||
const downloadingState = observable.box<boolean>(false);
|
||||
@@ -36,6 +38,7 @@ const versionUpdateInjectable = getInjectable({
|
||||
checkingState,
|
||||
selectedUpdateChannel.value,
|
||||
discoveredFromUpdateChannelState,
|
||||
showNotification,
|
||||
),
|
||||
|
||||
downloadUpdate: downloadUpdateFor(
|
||||
@@ -72,6 +75,7 @@ const checkForUpdatesFor =
|
||||
checkingState: IObservableValue<boolean>,
|
||||
selectedUpdateChannel: IComputedValue<UpdateChannel>,
|
||||
discoveredFromUpdateChannelState: IObservableValue<UpdateChannel>,
|
||||
showNotification: (message: string) => void,
|
||||
) =>
|
||||
async () => {
|
||||
runInAction(() => {
|
||||
@@ -81,17 +85,23 @@ const checkForUpdatesFor =
|
||||
const checkForUpdatesStartingFromChannel =
|
||||
checkForUpdatesStartingFromChannelFor(checkForPlatformUpdates);
|
||||
|
||||
showNotification("Checking for updates...");
|
||||
|
||||
const { updateWasDiscovered, version, actualUpdateChannel } = await checkForUpdatesStartingFromChannel(
|
||||
selectedUpdateChannel.get(),
|
||||
);
|
||||
|
||||
if (!updateWasDiscovered) {
|
||||
showNotification("No new updates available");
|
||||
}
|
||||
|
||||
runInAction(() => {
|
||||
discoveredFromUpdateChannelState.set(actualUpdateChannel);
|
||||
discoveredVersionState.set(version);
|
||||
checkingState.set(false);
|
||||
});
|
||||
|
||||
return { updateWasDiscovered };
|
||||
return { updateWasDiscovered, version };
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user