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

Add error notification on shell sync failure

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-24 13:24:32 -05:00
parent cce8ec5e17
commit 632365a3b9
5 changed files with 60 additions and 1 deletions

View File

@ -10,6 +10,12 @@ export interface SendMessageToChannel {
<Message>(channel: MessageChannel<Message>, message: Message): void;
}
export type MessageChannelSender<Channel> = Channel extends MessageChannel<void | undefined>
? () => void
: Channel extends MessageChannel<infer Message>
? (message: Message) => void
: never;
export const sendMessageToChannelInjectionToken = getInjectionToken<SendMessageToChannel>({
id: "send-message-to-message-channel",
});

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token";
export const shellSyncFailedChannel: MessageChannel<string> = {
id: "shell-sync-failed-channel",
};

View File

@ -0,0 +1,19 @@
/**
* 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 type { MessageChannelSender } from "../../../common/utils/channel/message-to-channel-injection-token";
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import { shellSyncFailedChannel } from "../common/failure-channel";
const emitShellSyncFailedInjectable = getInjectable({
id: "emit-shell-sync-failed",
instantiate: (di): MessageChannelSender<typeof shellSyncFailedChannel> => {
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
return (error) => sendMessageToChannel(shellSyncFailedChannel, error);
},
});
export default emitShellSyncFailedInjectable;

View File

@ -10,6 +10,7 @@ import isSnapPackageInjectable from "../../../common/vars/is-snap-package.inject
import electronAppInjectable from "../../../main/electron-app/electron-app.injectable";
import computeShellEnvironmentInjectable from "./compute-shell-environment.injectable";
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
import emitShellSyncFailedInjectable from "./emit-failure.injectable";
const setupShellInjectable = getInjectable({
id: "setup-shell",
@ -20,6 +21,7 @@ const setupShellInjectable = getInjectable({
const electronApp = di.inject(electronAppInjectable);
const resolvedUserShellSetting = di.inject(userShellSettingInjectable);
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
const emitShellSyncFailed = di.inject(emitShellSyncFailedInjectable);
return {
id: "setup-shell",
@ -29,7 +31,10 @@ const setupShellInjectable = getInjectable({
const result = await computeShellEnvironment(resolvedUserShellSetting.get());
if (!result.callWasSuccessful) {
return void logger.error(`[SHELL-SYNC]: ${result.error}`);
logger.error(`[SHELL-SYNC]: ${result.error}`);
emitShellSyncFailed(result.error);
return;
}
const env = result.response;

View File

@ -0,0 +1,19 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getMessageChannelListenerInjectable } from "../../../common/utils/channel/message-channel-listener-injection-token";
import showErrorNotificationInjectable from "../../../renderer/components/notifications/show-error-notification.injectable";
import { shellSyncFailedChannel } from "../common/failure-channel";
const shellSyncFailureListenerInjectable = getMessageChannelListenerInjectable({
id: "notification",
channel: shellSyncFailedChannel,
handler: (di) => {
const showErrorNotification = di.inject(showErrorNotificationInjectable);
return (errorMessage) => showErrorNotification(`Failed to sync shell environment: ${errorMessage}`);
},
});
export default shellSyncFailureListenerInjectable;