Fixed window focus bug

Windows (e.g.: media viewer) opened by other windows (e.g.: file explorer) were unfocused after opening.
This commit is contained in:
Prozilla 2023-07-30 10:35:16 +02:00
parent fe8ec7b4e0
commit b2c5f33462
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE
4 changed files with 38 additions and 7 deletions

View file

@ -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 (<p>Use the File Explorer to open an image.</p>);
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 (<p>Invalid file format.</p>);

View file

@ -55,8 +55,8 @@ export function HomeMenu({ active, setActive }) {
</button>
<button title="Images" onClick={() => {
setActive(false);
windowsManager.open("file-explorer", { startPath: "~/Images" }); }
}>
windowsManager.open("file-explorer", { startPath: "~/Images" });
}}>
<FontAwesomeIcon icon={faImage}/>
</button>
<button title="Documents" onClick={() => {

View file

@ -76,7 +76,10 @@ export function Window({ id, app, size, position, focused = false, onInteract, o
width: maximized ? null : size.x,
height: maximized ? null : size.y,
}}
onClick={onInteract}
onClick={(event) => {
if (!event.defaultPrevented)
onInteract(event);
}}
>
<div className={`${styles.Header} Handle`}>
<ReactSVG className={styles["Window-icon"]} src={process.env.PUBLIC_URL + `/media/applications/icons/${app.id}.svg`}/>

View file

@ -10,6 +10,11 @@ export default class WindowsManager {
this.updateWindows = () => {};
}
/**
* @param {String} appId
* @param {Object|null} options
* @returns {Object}
*/
open(appId, options) {
const app = ApplicationsManager.getApplication(appId);
const size = new Vector2(700, 400);
@ -34,18 +39,23 @@ export default class WindowsManager {
};
this.updateWindows(this.windows);
return this.windows[id];
// console.log(this);
}
/**
* @param {VirtualFile} file
* @returns {Object}
*/
openFile(file) {
const app = ApplicationsManager.getFileApplication(file.extension);
if (app != null)
this.open(app.id, { file });
return this.open(app.id, { file });
}
/**
* @param {String} windowId
*/
close(windowId) {
windowId = windowId.toString();
@ -61,11 +71,18 @@ export default class WindowsManager {
// console.log(this);
}
/**
* @param {Object} window
*/
focus(window) {
window.lastInteraction = new Date().valueOf();
this.updateWindows(this.windows);
}
/**
* @param {String} appId
* @returns {Boolean}
*/
isAppActive(appId) {
let active = false;
@ -79,6 +96,9 @@ export default class WindowsManager {
return active;
}
/**
* @param {Function} updateWindows
*/
setUpdateWindows(updateWindows) {
this.updateWindows = updateWindows;
}