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:
parent
fe8ec7b4e0
commit
b2c5f33462
4 changed files with 38 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { VirtualFile } from "../../../features/virtual-drive/virtual-file.js"
|
import { VirtualFile } from "../../../features/virtual-drive/virtual-file.js"
|
||||||
|
import { useWindowsManager } from "../../../hooks/windows/WindowsManagerContext.js";
|
||||||
import styles from "./MediaViewer.module.css";
|
import styles from "./MediaViewer.module.css";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -8,9 +9,16 @@ import styles from "./MediaViewer.module.css";
|
||||||
* @param {VirtualFile} props.file
|
* @param {VirtualFile} props.file
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function MediaViewer({ file }) {
|
export function MediaViewer({ file, close }) {
|
||||||
if (file == null)
|
const windowsManager = useWindowsManager();
|
||||||
return (<p>Use the File Explorer to open an image.</p>);
|
|
||||||
|
if (file == null) {
|
||||||
|
setTimeout(() => {
|
||||||
|
windowsManager.open("file-explorer", { startPath: "~/Images" });
|
||||||
|
close();
|
||||||
|
}, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!["png"].includes(file.extension))
|
if (!["png"].includes(file.extension))
|
||||||
return (<p>Invalid file format.</p>);
|
return (<p>Invalid file format.</p>);
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ export function HomeMenu({ active, setActive }) {
|
||||||
</button>
|
</button>
|
||||||
<button title="Images" onClick={() => {
|
<button title="Images" onClick={() => {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
windowsManager.open("file-explorer", { startPath: "~/Images" }); }
|
windowsManager.open("file-explorer", { startPath: "~/Images" });
|
||||||
}>
|
}}>
|
||||||
<FontAwesomeIcon icon={faImage}/>
|
<FontAwesomeIcon icon={faImage}/>
|
||||||
</button>
|
</button>
|
||||||
<button title="Documents" onClick={() => {
|
<button title="Documents" onClick={() => {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,10 @@ export function Window({ id, app, size, position, focused = false, onInteract, o
|
||||||
width: maximized ? null : size.x,
|
width: maximized ? null : size.x,
|
||||||
height: maximized ? null : size.y,
|
height: maximized ? null : size.y,
|
||||||
}}
|
}}
|
||||||
onClick={onInteract}
|
onClick={(event) => {
|
||||||
|
if (!event.defaultPrevented)
|
||||||
|
onInteract(event);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className={`${styles.Header} Handle`}>
|
<div className={`${styles.Header} Handle`}>
|
||||||
<ReactSVG className={styles["Window-icon"]} src={process.env.PUBLIC_URL + `/media/applications/icons/${app.id}.svg`}/>
|
<ReactSVG className={styles["Window-icon"]} src={process.env.PUBLIC_URL + `/media/applications/icons/${app.id}.svg`}/>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ export default class WindowsManager {
|
||||||
this.updateWindows = () => {};
|
this.updateWindows = () => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} appId
|
||||||
|
* @param {Object|null} options
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
open(appId, options) {
|
open(appId, options) {
|
||||||
const app = ApplicationsManager.getApplication(appId);
|
const app = ApplicationsManager.getApplication(appId);
|
||||||
const size = new Vector2(700, 400);
|
const size = new Vector2(700, 400);
|
||||||
|
|
@ -34,18 +39,23 @@ export default class WindowsManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.updateWindows(this.windows);
|
this.updateWindows(this.windows);
|
||||||
|
return this.windows[id];
|
||||||
// console.log(this);
|
// console.log(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {VirtualFile} file
|
* @param {VirtualFile} file
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
openFile(file) {
|
openFile(file) {
|
||||||
const app = ApplicationsManager.getFileApplication(file.extension);
|
const app = ApplicationsManager.getFileApplication(file.extension);
|
||||||
if (app != null)
|
if (app != null)
|
||||||
this.open(app.id, { file });
|
return this.open(app.id, { file });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} windowId
|
||||||
|
*/
|
||||||
close(windowId) {
|
close(windowId) {
|
||||||
windowId = windowId.toString();
|
windowId = windowId.toString();
|
||||||
|
|
||||||
|
|
@ -61,11 +71,18 @@ export default class WindowsManager {
|
||||||
// console.log(this);
|
// console.log(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} window
|
||||||
|
*/
|
||||||
focus(window) {
|
focus(window) {
|
||||||
window.lastInteraction = new Date().valueOf();
|
window.lastInteraction = new Date().valueOf();
|
||||||
this.updateWindows(this.windows);
|
this.updateWindows(this.windows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} appId
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
isAppActive(appId) {
|
isAppActive(appId) {
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
|
|
@ -79,6 +96,9 @@ export default class WindowsManager {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Function} updateWindows
|
||||||
|
*/
|
||||||
setUpdateWindows(updateWindows) {
|
setUpdateWindows(updateWindows) {
|
||||||
this.updateWindows = updateWindows;
|
this.updateWindows = updateWindows;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue