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

Rename interface for honesty

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-06-01 15:00:07 +03:00
parent 077b2089b3
commit 8a8a188dc3
2 changed files with 10 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import { BrowserWindow } from "electron";
import { openBrowser } from "../../../../common/utils"; import { openBrowser } from "../../../../common/utils";
import type { SendToViewArgs } from "./lens-window-injection-token"; import type { SendToViewArgs } from "./lens-window-injection-token";
import sendToChannelInElectronBrowserWindowInjectable from "./send-to-channel-in-electron-browser-window.injectable"; import sendToChannelInElectronBrowserWindowInjectable from "./send-to-channel-in-electron-browser-window.injectable";
import type { LensWindow } from "./create-lens-window.injectable"; import type { ElectronWindow } from "./create-lens-window.injectable";
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover"; export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";
@ -30,7 +30,7 @@ export interface ElectronWindowConfiguration {
onDomReady?: () => void; onDomReady?: () => void;
} }
export type CreateElectronWindow = () => Promise<LensWindow>; export type CreateElectronWindow = () => Promise<ElectronWindow>;
export type CreateElectronWindowFor = (config: ElectronWindowConfiguration) => CreateElectronWindow; export type CreateElectronWindowFor = (config: ElectronWindowConfiguration) => CreateElectronWindow;
const createElectronWindowFor = getInjectable({ const createElectronWindowFor = getInjectable({

View File

@ -3,11 +3,11 @@
* 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 { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { SendToViewArgs } from "./lens-window-injection-token"; import type { LensWindow, SendToViewArgs } from "./lens-window-injection-token";
import type { ElectronWindowTitleBarStyle } from "./create-electron-window-for.injectable"; import type { ElectronWindowTitleBarStyle } from "./create-electron-window-for.injectable";
import createElectronWindowForInjectable from "./create-electron-window-for.injectable"; import createElectronWindowForInjectable from "./create-electron-window-for.injectable";
export interface LensWindow { export interface ElectronWindow {
show: () => void; show: () => void;
close: () => void; close: () => void;
send: (args: SendToViewArgs) => void; send: (args: SendToViewArgs) => void;
@ -35,13 +35,14 @@ const createLensWindowInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const createElectronWindowFor = di.inject(createElectronWindowForInjectable); const createElectronWindowFor = di.inject(createElectronWindowForInjectable);
return (configuration: LensWindowConfiguration) => { return (configuration: LensWindowConfiguration): LensWindow => {
let browserWindow: LensWindow | undefined; let browserWindow: ElectronWindow | undefined;
const createElectronWindow = createElectronWindowFor(Object.assign( const createElectronWindow = createElectronWindowFor(Object.assign(
{ {
onClose: () => browserWindow = undefined, onClose: () => browserWindow = undefined,
}, },
configuration, configuration,
)); ));
@ -49,6 +50,7 @@ const createLensWindowInjectable = getInjectable({
get visible() { get visible() {
return !!browserWindow; return !!browserWindow;
}, },
show: async () => { show: async () => {
if (!browserWindow) { if (!browserWindow) {
browserWindow = await createElectronWindow(); browserWindow = await createElectronWindow();
@ -56,10 +58,12 @@ const createLensWindowInjectable = getInjectable({
browserWindow.show(); browserWindow.show();
}, },
close: () => { close: () => {
browserWindow?.close(); browserWindow?.close();
browserWindow = undefined; browserWindow = undefined;
}, },
send: (args: SendToViewArgs) => { send: (args: SendToViewArgs) => {
if (!browserWindow) { if (!browserWindow) {
throw new Error(`Tried to send message to window "${configuration.id}" but the window was closed`); throw new Error(`Tried to send message to window "${configuration.id}" but the window was closed`);