mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove more usages of Singleton
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
257082e699
commit
9fee31a872
18 files changed
+152
-129
No files matched your search
@@ -5,9 +5,9 @@
|
||||
import type { IpcMainInvokeEvent } from "electron";
|
||||
import { BrowserWindow, Menu } from "electron";
|
||||
import { clusterFrameMap } from "../../../../common/cluster-frames";
|
||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterDisconnectHandler } from "../../../../common/ipc/cluster";
|
||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
||||
import type { CatalogEntityRegistry } from "../../../catalog";
|
||||
import { pushCatalogToRenderer } from "../../../catalog-pusher";
|
||||
@@ -23,7 +23,7 @@ import type { Composite } from "../../../../common/utils/composite/get-composite
|
||||
import { getApplicationMenuTemplate } from "../../../../features/application-menu/main/populate-application-menu.injectable";
|
||||
import type { MenuItemRoot } from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
|
||||
import type { EmitAppEvent } from "../../../../common/app-event-bus/emit-event.injectable";
|
||||
|
||||
import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable";
|
||||
interface Dependencies {
|
||||
applicationMenuItemComposite: IComputedValue<Composite<ApplicationMenuItemTypes | MenuItemRoot>>;
|
||||
catalogEntityRegistry: CatalogEntityRegistry;
|
||||
@@ -31,6 +31,7 @@ interface Dependencies {
|
||||
operatingSystemTheme: IComputedValue<Theme>;
|
||||
askUserForFilePaths: AskUserForFilePaths;
|
||||
emitAppEvent: EmitAppEvent;
|
||||
getClusterById: GetClusterById;
|
||||
}
|
||||
|
||||
export const setupIpcMainHandlers = ({
|
||||
@@ -40,15 +41,15 @@ export const setupIpcMainHandlers = ({
|
||||
operatingSystemTheme,
|
||||
askUserForFilePaths,
|
||||
emitAppEvent,
|
||||
getClusterById,
|
||||
}: Dependencies) => {
|
||||
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
|
||||
return ClusterStore.getInstance()
|
||||
.getById(clusterId)
|
||||
return getClusterById(clusterId)
|
||||
?.activate(force);
|
||||
});
|
||||
|
||||
ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
|
||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||
const cluster = getClusterById(clusterId);
|
||||
|
||||
if (cluster) {
|
||||
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
|
||||
@@ -60,7 +61,7 @@ export const setupIpcMainHandlers = ({
|
||||
|
||||
ipcMainHandle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
|
||||
emitAppEvent({ name: "cluster", action: "stop" });
|
||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||
const cluster = getClusterById(clusterId);
|
||||
|
||||
if (cluster) {
|
||||
cluster.disconnect();
|
||||
@@ -92,5 +93,10 @@ export const setupIpcMainHandlers = ({
|
||||
return operatingSystemTheme.get();
|
||||
});
|
||||
|
||||
clusterStore.provideInitialFromMain();
|
||||
ipcMainHandle(clusterStates, () => (
|
||||
clusterStore.clustersList.map(cluster => ({
|
||||
id: cluster.id,
|
||||
state: cluster.getState(),
|
||||
}))
|
||||
));
|
||||
};
|
||||
Reference in new issue
Block a user