mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove duplication for getting visible windows
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
d0b9a0d8f0
commit
8f248a7f23
@ -5,23 +5,19 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||||
import electronAppInjectable from "../../electron-app.injectable";
|
import electronAppInjectable from "../../electron-app.injectable";
|
||||||
import { lensWindowInjectionToken } from "../../../start-main-application/lens-window/application-window/lens-window-injection-token";
|
import { isEmpty } from "lodash/fp";
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
import getVisibleWindowsInjectable from "../../../start-main-application/lens-window/get-visible-windows.injectable";
|
||||||
import { filter, isEmpty } from "lodash/fp";
|
|
||||||
|
|
||||||
const hideDockForLastClosedWindowInjectable = getInjectable({
|
const hideDockForLastClosedWindowInjectable = getInjectable({
|
||||||
id: "hide-dock-when-there-are-no-windows",
|
id: "hide-dock-when-there-are-no-windows",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const app = di.inject(electronAppInjectable);
|
const app = di.inject(electronAppInjectable);
|
||||||
const getLensWindows = () => di.injectMany(lensWindowInjectionToken);
|
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
run: () => {
|
run: () => {
|
||||||
const visibleWindows = pipeline(
|
const visibleWindows = getVisibleWindows();
|
||||||
getLensWindows(),
|
|
||||||
filter(window => !!window.isVisible),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isEmpty(visibleWindows)) {
|
if (isEmpty(visibleWindows)) {
|
||||||
app.dock?.hide();
|
app.dock?.hide();
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { filter } from "lodash/fp";
|
||||||
|
import { lensWindowInjectionToken } from "./application-window/lens-window-injection-token";
|
||||||
|
|
||||||
|
const getVisibleWindowsInjectable = getInjectable({
|
||||||
|
id: "get-visible-windows",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const getAllLensWindows = () => di.injectMany(lensWindowInjectionToken);
|
||||||
|
|
||||||
|
return () =>
|
||||||
|
pipeline(
|
||||||
|
getAllLensWindows(),
|
||||||
|
filter((lensWindow) => !!lensWindow.isVisible),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default getVisibleWindowsInjectable;
|
||||||
@ -2,31 +2,24 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { lensWindowInjectionToken } from "../../start-main-application/lens-window/application-window/lens-window-injection-token";
|
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { filter } from "lodash/fp";
|
|
||||||
import { messageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
|
import { messageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
import type { MessageChannel } from "../../../common/utils/channel/message-channel-injection-token";
|
import type { MessageChannel } from "../../../common/utils/channel/message-channel-injection-token";
|
||||||
import { tentativeStringifyJson } from "../../../common/utils/tentative-stringify-json";
|
import { tentativeStringifyJson } from "../../../common/utils/tentative-stringify-json";
|
||||||
|
import getVisibleWindowsInjectable from "../../start-main-application/lens-window/get-visible-windows.injectable";
|
||||||
|
|
||||||
const messageToChannelInjectable = getInjectable({
|
const messageToChannelInjectable = getInjectable({
|
||||||
id: "message-to-channel",
|
id: "message-to-channel",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const getAllLensWindows = () => di.injectMany(lensWindowInjectionToken);
|
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||||
|
|
||||||
// TODO: Figure out way to improve typing in internals
|
// TODO: Figure out way to improve typing in internals
|
||||||
// Notice that this should be injected using "messageToChannelInjectionToken" which is typed correctly.
|
// Notice that this should be injected using "messageToChannelInjectionToken" which is typed correctly.
|
||||||
return (channel: MessageChannel<any>, message?: unknown) => {
|
return (channel: MessageChannel<any>, message?: unknown) => {
|
||||||
const stringifiedMessage = tentativeStringifyJson(message);
|
const stringifiedMessage = tentativeStringifyJson(message);
|
||||||
|
|
||||||
const visibleWindows = pipeline(
|
getVisibleWindows().forEach((lensWindow) =>
|
||||||
getAllLensWindows(),
|
|
||||||
filter((lensWindow) => !!lensWindow.isVisible),
|
|
||||||
);
|
|
||||||
|
|
||||||
visibleWindows.forEach((lensWindow) =>
|
|
||||||
lensWindow.send({ channel: channel.id, data: stringifiedMessage ? [stringifiedMessage] : [] }),
|
lensWindow.send({ channel: channel.id, data: stringifiedMessage ? [stringifiedMessage] : [] }),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user