From b2c5f334627dd07a6832293d48b168ad0678191a Mon Sep 17 00:00:00 2001 From: Prozilla Date: Sun, 30 Jul 2023 10:35:16 +0200 Subject: [PATCH] Fixed window focus bug Windows (e.g.: media viewer) opened by other windows (e.g.: file explorer) were unfocused after opening. --- .../applications/media-viewer/MediaViewer.jsx | 14 +++++++++--- src/components/task-bar/HomeMenu.jsx | 4 ++-- src/components/windows/Window.jsx | 5 ++++- src/features/windows/windows.js | 22 ++++++++++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/components/applications/media-viewer/MediaViewer.jsx b/src/components/applications/media-viewer/MediaViewer.jsx index a37f6b0..bc60629 100644 --- a/src/components/applications/media-viewer/MediaViewer.jsx +++ b/src/components/applications/media-viewer/MediaViewer.jsx @@ -1,5 +1,6 @@ // eslint-disable-next-line no-unused-vars import { VirtualFile } from "../../../features/virtual-drive/virtual-file.js" +import { useWindowsManager } from "../../../hooks/windows/WindowsManagerContext.js"; import styles from "./MediaViewer.module.css"; /** @@ -8,9 +9,16 @@ import styles from "./MediaViewer.module.css"; * @param {VirtualFile} props.file * @returns */ -export function MediaViewer({ file }) { - if (file == null) - return (

Use the File Explorer to open an image.

); +export function MediaViewer({ file, close }) { + const windowsManager = useWindowsManager(); + + if (file == null) { + setTimeout(() => { + windowsManager.open("file-explorer", { startPath: "~/Images" }); + close(); + }, 10); + return; + } if (!["png"].includes(file.extension)) return (

Invalid file format.

); diff --git a/src/components/task-bar/HomeMenu.jsx b/src/components/task-bar/HomeMenu.jsx index 9099372..afcea73 100644 --- a/src/components/task-bar/HomeMenu.jsx +++ b/src/components/task-bar/HomeMenu.jsx @@ -55,8 +55,8 @@ export function HomeMenu({ active, setActive }) {