mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move too many hotbar items notification to injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
38de2edc50
commit
1dd172eafe
@ -8,10 +8,8 @@ import type { BaseStoreDependencies } from "../base-store/base-store";
|
||||
import { BaseStore } from "../base-store/base-store";
|
||||
import { toJS } from "../utils";
|
||||
import type { CatalogEntity } from "../catalog";
|
||||
import { broadcastMessage } from "../ipc";
|
||||
import type { Hotbar, CreateHotbarData, CreateHotbarOptions } from "./types";
|
||||
import { defaultHotbarCells, getEmptyHotbar } from "./types";
|
||||
import { hotbarTooManyItemsChannel } from "../ipc/hotbar";
|
||||
import type { GeneralEntity } from "../catalog-entities";
|
||||
import type { Logger } from "../logger";
|
||||
import assert from "assert";
|
||||
@ -24,6 +22,7 @@ export interface HotbarStoreModel {
|
||||
interface Dependencies extends BaseStoreDependencies {
|
||||
readonly catalogCatalogEntity: GeneralEntity;
|
||||
readonly logger: Logger;
|
||||
onTooManyHotbarItems: () => void;
|
||||
}
|
||||
|
||||
export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
@ -195,7 +194,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
if (emptyCellIndex != -1) {
|
||||
hotbar.items[emptyCellIndex] = newItem;
|
||||
} else {
|
||||
broadcastMessage(hotbarTooManyItemsChannel);
|
||||
this.dependencies.onTooManyHotbarItems();
|
||||
}
|
||||
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
|
||||
hotbar.items[cellIndex] = newItem;
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
|
||||
export const onTooManyHotbarItemsInjectionToken = getInjectionToken<() => void>({
|
||||
id: "on-too-many-hotbar-items-token",
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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 { noop } from "../../../../common/utils";
|
||||
import { onTooManyHotbarItemsInjectionToken } from "../common/on-too-many-items";
|
||||
|
||||
const onTooManyHotbarItemsInjectable = getInjectable({
|
||||
id: "on-too-many-hotbar-items",
|
||||
instantiate: () => noop,
|
||||
injectionToken: onTooManyHotbarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default onTooManyHotbarItemsInjectable;
|
||||
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 { defaultHotbarCells } from "../../../../common/hotbars/types";
|
||||
import showErrorNotificationInjectable from "../../../../renderer/components/notifications/show-error-notification.injectable";
|
||||
import { onTooManyHotbarItemsInjectionToken } from "../common/on-too-many-items";
|
||||
|
||||
const onTooManyHotbarItemsInjectable = getInjectable({
|
||||
id: "on-too-many-hotbar-items",
|
||||
instantiate: (di) => {
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
|
||||
return () => showErrorNotification(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
|
||||
},
|
||||
injectionToken: onTooManyHotbarItemsInjectionToken,
|
||||
});
|
||||
|
||||
export default onTooManyHotbarItemsInjectable;
|
||||
@ -3,20 +3,16 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import registerIpcListenersInjectable from "../../ipc/register-ipc-listeners.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import unmountRootComponentInjectable from "../../window/unmount-root-component.injectable";
|
||||
|
||||
const initRootFrameInjectable = getInjectable({
|
||||
id: "init-root-frame",
|
||||
instantiate: (di) => {
|
||||
const registerIpcListeners = di.inject(registerIpcListenersInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const unmountRootComponent = di.inject(unmountRootComponentInjectable);
|
||||
|
||||
return async () => {
|
||||
registerIpcListeners();
|
||||
|
||||
window.addEventListener("beforeunload", () => {
|
||||
logger.info("[ROOT-FRAME]: Unload app");
|
||||
unmountRootComponent();
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* 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 { defaultHotbarCells } from "../../common/hotbars/types";
|
||||
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
||||
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
||||
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
||||
|
||||
const registerIpcListenersInjectable = getInjectable({
|
||||
id: "register-ipc-listeners",
|
||||
|
||||
instantiate: (di) => {
|
||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
|
||||
return () => {
|
||||
ipcRenderer.on(hotbarTooManyItemsChannel, () => {
|
||||
showErrorNotification(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default registerIpcListenersInjectable;
|
||||
Loading…
Reference in New Issue
Block a user