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:
parent
cce8ec5e17
commit
632365a3b9
@ -10,6 +10,12 @@ export interface SendMessageToChannel {
|
|||||||
<Message>(channel: MessageChannel<Message>, message: Message): void;
|
<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>({
|
export const sendMessageToChannelInjectionToken = getInjectionToken<SendMessageToChannel>({
|
||||||
id: "send-message-to-message-channel",
|
id: "send-message-to-message-channel",
|
||||||
});
|
});
|
||||||
|
|||||||
10
src/features/shell-sync/common/failure-channel.ts
Normal file
10
src/features/shell-sync/common/failure-channel.ts
Normal 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",
|
||||||
|
};
|
||||||
19
src/features/shell-sync/main/emit-failure.injectable.ts
Normal file
19
src/features/shell-sync/main/emit-failure.injectable.ts
Normal 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;
|
||||||
@ -10,6 +10,7 @@ import isSnapPackageInjectable from "../../../common/vars/is-snap-package.inject
|
|||||||
import electronAppInjectable from "../../../main/electron-app/electron-app.injectable";
|
import electronAppInjectable from "../../../main/electron-app/electron-app.injectable";
|
||||||
import computeShellEnvironmentInjectable from "./compute-shell-environment.injectable";
|
import computeShellEnvironmentInjectable from "./compute-shell-environment.injectable";
|
||||||
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
|
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
|
||||||
|
import emitShellSyncFailedInjectable from "./emit-failure.injectable";
|
||||||
|
|
||||||
const setupShellInjectable = getInjectable({
|
const setupShellInjectable = getInjectable({
|
||||||
id: "setup-shell",
|
id: "setup-shell",
|
||||||
@ -20,6 +21,7 @@ const setupShellInjectable = getInjectable({
|
|||||||
const electronApp = di.inject(electronAppInjectable);
|
const electronApp = di.inject(electronAppInjectable);
|
||||||
const resolvedUserShellSetting = di.inject(userShellSettingInjectable);
|
const resolvedUserShellSetting = di.inject(userShellSettingInjectable);
|
||||||
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
|
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
|
||||||
|
const emitShellSyncFailed = di.inject(emitShellSyncFailedInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "setup-shell",
|
id: "setup-shell",
|
||||||
@ -29,7 +31,10 @@ const setupShellInjectable = getInjectable({
|
|||||||
const result = await computeShellEnvironment(resolvedUserShellSetting.get());
|
const result = await computeShellEnvironment(resolvedUserShellSetting.get());
|
||||||
|
|
||||||
if (!result.callWasSuccessful) {
|
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;
|
const env = result.response;
|
||||||
|
|||||||
@ -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;
|
||||||
Loading…
Reference in New Issue
Block a user