mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make application window appear even when its hidden underneath other apps (#5782)
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
667053cdf5
commit
4d99a46dfe
@ -13,6 +13,7 @@ import asyncFn from "@async-fn/jest";
|
|||||||
import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||||
|
import focusApplicationInjectable from "../../main/electron-app/features/focus-application.injectable";
|
||||||
|
|
||||||
describe("opening application window using tray", () => {
|
describe("opening application window using tray", () => {
|
||||||
describe("given application has started", () => {
|
describe("given application has started", () => {
|
||||||
@ -21,13 +22,18 @@ describe("opening application window using tray", () => {
|
|||||||
let expectWindowsToBeOpen: (windowIds: string[]) => void;
|
let expectWindowsToBeOpen: (windowIds: string[]) => void;
|
||||||
let callForSplashWindowHtmlMock: AsyncFnMock<() => void>;
|
let callForSplashWindowHtmlMock: AsyncFnMock<() => void>;
|
||||||
let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>;
|
let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>;
|
||||||
|
let focusApplicationMock: jest.Mock;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
callForSplashWindowHtmlMock = asyncFn();
|
callForSplashWindowHtmlMock = asyncFn();
|
||||||
callForApplicationWindowHtmlMock = asyncFn();
|
callForApplicationWindowHtmlMock = asyncFn();
|
||||||
|
|
||||||
|
focusApplicationMock = jest.fn();
|
||||||
|
|
||||||
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
|
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
|
||||||
({ mainDi }) => {
|
({ mainDi }) => {
|
||||||
|
mainDi.override(focusApplicationInjectable, () => focusApplicationMock);
|
||||||
|
|
||||||
mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory");
|
mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory");
|
||||||
|
|
||||||
const loadFileMock = jest
|
const loadFileMock = jest
|
||||||
@ -99,12 +105,18 @@ describe("opening application window using tray", () => {
|
|||||||
|
|
||||||
describe("when an application window is reopened using tray", () => {
|
describe("when an application window is reopened using tray", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
focusApplicationMock.mockClear();
|
||||||
|
|
||||||
callForSplashWindowHtmlMock.mockClear();
|
callForSplashWindowHtmlMock.mockClear();
|
||||||
callForApplicationWindowHtmlMock.mockClear();
|
callForApplicationWindowHtmlMock.mockClear();
|
||||||
|
|
||||||
applicationBuilder.tray.click("open-app");
|
applicationBuilder.tray.click("open-app");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("focuses the application", () => {
|
||||||
|
expect(focusApplicationMock).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("still no windows are open", () => {
|
it("still no windows are open", () => {
|
||||||
expectWindowsToBeOpen([]);
|
expectWindowsToBeOpen([]);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* 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 electronAppInjectable from "../electron-app.injectable";
|
||||||
|
|
||||||
|
const focusApplicationInjectable = getInjectable({
|
||||||
|
id: "focus-application",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const electronApp = di.inject(electronAppInjectable);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
electronApp.focus({ steal: true });
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
causesSideEffects: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default focusApplicationInjectable;
|
||||||
@ -100,6 +100,7 @@ import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-applicat
|
|||||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||||
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
||||||
import type { HotbarStore } from "../common/hotbars/store";
|
import type { HotbarStore } from "../common/hotbars/store";
|
||||||
|
import focusApplicationInjectable from "./electron-app/features/focus-application.injectable";
|
||||||
|
|
||||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||||
const {
|
const {
|
||||||
@ -261,6 +262,7 @@ const overrideElectronFeatures = (di: DiContainer) => {
|
|||||||
di.override(electronQuitAndInstallUpdateInjectable, () => () => {});
|
di.override(electronQuitAndInstallUpdateInjectable, () => () => {});
|
||||||
di.override(setUpdateOnQuitInjectable, () => () => {});
|
di.override(setUpdateOnQuitInjectable, () => () => {});
|
||||||
di.override(downloadPlatformUpdateInjectable, () => async () => ({ downloadWasSuccessful: true }));
|
di.override(downloadPlatformUpdateInjectable, () => async () => ({ downloadWasSuccessful: true }));
|
||||||
|
di.override(focusApplicationInjectable, () => () => {});
|
||||||
|
|
||||||
di.override(checkForPlatformUpdatesInjectable, () => () => {
|
di.override(checkForPlatformUpdatesInjectable, () => () => {
|
||||||
throw new Error("Tried to check for platform updates without explicit override.");
|
throw new Error("Tried to check for platform updates without explicit override.");
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import splashWindowInjectable from "./splash-window/splash-window.injectable";
|
import splashWindowInjectable from "./splash-window/splash-window.injectable";
|
||||||
import applicationWindowInjectable from "./application-window/application-window.injectable";
|
import applicationWindowInjectable from "./application-window/application-window.injectable";
|
||||||
import { identity, some } from "lodash/fp";
|
import { identity, some } from "lodash/fp";
|
||||||
|
import focusApplicationInjectable from "../../electron-app/features/focus-application.injectable";
|
||||||
const someIsTruthy = some(identity);
|
const someIsTruthy = some(identity);
|
||||||
|
|
||||||
const showApplicationWindowInjectable = getInjectable({
|
const showApplicationWindowInjectable = getInjectable({
|
||||||
@ -14,8 +15,11 @@ const showApplicationWindowInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const applicationWindow = di.inject(applicationWindowInjectable);
|
const applicationWindow = di.inject(applicationWindowInjectable);
|
||||||
const splashWindow = di.inject(splashWindowInjectable);
|
const splashWindow = di.inject(splashWindowInjectable);
|
||||||
|
const focusApplication = di.inject(focusApplicationInjectable);
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
|
focusApplication();
|
||||||
|
|
||||||
if (applicationWindow.isStarting) {
|
if (applicationWindow.isStarting) {
|
||||||
applicationWindow.show();
|
applicationWindow.show();
|
||||||
splashWindow.close();
|
splashWindow.close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user