Log more recent opening of files
Some checks are pending
Tests / tests (push) Waiting to run

This commit is contained in:
Dustin Brett 2024-10-21 18:52:24 -07:00
parent 2738f37acb
commit 2640b53fce
5 changed files with 31 additions and 12 deletions

View File

@ -51,7 +51,7 @@ const Browser: FC<ComponentProcessProps> = ({ id }) => {
processes: { [id]: process }, processes: { [id]: process },
open, open,
} = useProcesses(); } = useProcesses();
const { setForegroundId } = useSession(); const { setForegroundId, updateRecentFiles } = useSession();
const { prependFileToTitle } = useTitle(id); const { prependFileToTitle } = useTitle(id);
const { initialTitle = "", url = "" } = process || {}; const { initialTitle = "", url = "" } = process || {};
const initialUrl = url || HOME_PAGE; const initialUrl = url || HOME_PAGE;
@ -263,8 +263,13 @@ const Browser: FC<ComponentProcessProps> = ({ id }) => {
fs, fs,
decodeURI(pathname), decodeURI(pathname),
getExtension(pathname), getExtension(pathname),
({ pid, url: infoUrl }) => ({ pid, url: infoUrl }) => {
open(pid || "OpenWith", { url: infoUrl }) open(pid || "OpenWith", { url: infoUrl });
if (pid && infoUrl) {
updateRecentFiles(infoUrl, pid);
}
}
); );
} }
}); });
@ -356,6 +361,7 @@ const Browser: FC<ComponentProcessProps> = ({ id }) => {
readdir, readdir,
setIcon, setIcon,
stat, stat,
updateRecentFiles,
] ]
); );

View File

@ -10,6 +10,7 @@ import Icon from "styles/common/Icon";
import { DISBALE_AUTO_INPUT_FEATURES, ROOT_NAME } from "utils/constants"; import { DISBALE_AUTO_INPUT_FEATURES, ROOT_NAME } from "utils/constants";
import { getExtension, label } from "utils/functions"; import { getExtension, label } from "utils/functions";
import { getProcessByFileExtension } from "components/system/Files/FileEntry/functions"; import { getProcessByFileExtension } from "components/system/Files/FileEntry/functions";
import { useSession } from "contexts/session";
type AddressBarProps = { type AddressBarProps = {
id: string; id: string;
@ -40,6 +41,7 @@ const AddressBar = forwardRef<HTMLInputElement, AddressBarProps>(
const displayName = basename(url) || ROOT_NAME; const displayName = basename(url) || ROOT_NAME;
const [addressBar, setAddressBar] = useState(displayName); const [addressBar, setAddressBar] = useState(displayName);
const { exists, stat, updateFolder } = useFileSystem(); const { exists, stat, updateFolder } = useFileSystem();
const { updateRecentFiles } = useSession();
useEffect(() => { useEffect(() => {
if (addressBarRef.current) { if (addressBarRef.current) {
@ -67,11 +69,15 @@ const AddressBar = forwardRef<HTMLInputElement, AddressBarProps>(
if (value && (await exists(value))) { if (value && (await exists(value))) {
if ((await stat(value)).isDirectory()) changeUrl(id, value); if ((await stat(value)).isDirectory()) changeUrl(id, value);
else { else {
open( const openPid = getProcessByFileExtension(
getProcessByFileExtension(getExtension(value)) || getExtension(value)
"OpenWith",
{ url: value }
); );
open(openPid || "OpenWith", { url: value });
if (openPid && value) {
updateRecentFiles(value, openPid);
}
} }
} }
addressBarRef.current.blur(); addressBarRef.current.blur();

View File

@ -1089,6 +1089,7 @@ const useCommandInterpreter = (
case "wsl": case "wsl":
case "linux": case "linux":
open("V86", { url: LINUX_IMAGE_PATH }); open("V86", { url: LINUX_IMAGE_PATH });
updateRecentFiles(LINUX_IMAGE_PATH, "V86");
break; break;
case "xlsx": { case "xlsx": {
const [file, format = "xlsx"] = commandArgs; const [file, format = "xlsx"] = commandArgs;

View File

@ -568,9 +568,7 @@ const useFolderContextMenu = (
} }
open("MonacoEditor", { url: INDEX_FILE }); open("MonacoEditor", { url: INDEX_FILE });
if (INDEX_FILE) { updateRecentFiles(INDEX_FILE, "MonacoEditor");
updateRecentFiles(INDEX_FILE, "MonacoEditor");
}
}, },
label: "View page source", label: "View page source",
}, },

View File

@ -4,6 +4,7 @@ import { isCorsUrl } from "components/apps/TinyMCE/functions";
import { getProcessByFileExtension } from "components/system/Files/FileEntry/functions"; import { getProcessByFileExtension } from "components/system/Files/FileEntry/functions";
import { useProcesses } from "contexts/process"; import { useProcesses } from "contexts/process";
import { haltEvent, isYouTubeUrl, getExtension } from "utils/functions"; import { haltEvent, isYouTubeUrl, getExtension } from "utils/functions";
import { useSession } from "contexts/session";
type LinkHandler = ( type LinkHandler = (
event: Event, event: Event,
@ -14,6 +15,7 @@ type LinkHandler = (
export const useLinkHandler = (): LinkHandler => { export const useLinkHandler = (): LinkHandler => {
const { open } = useProcesses(); const { open } = useProcesses();
const { updateRecentFiles } = useSession();
return useCallback( return useCallback(
(event: Event, url: string, pathName: string, title?: string) => { (event: Event, url: string, pathName: string, title?: string) => {
@ -37,11 +39,17 @@ export const useLinkHandler = (): LinkHandler => {
getExtension(pathName) getExtension(pathName)
); );
if (defaultProcess) open(defaultProcess, { url: decodeURI(pathName) }); if (defaultProcess) {
const pathUrl = decodeURI(pathName);
open(defaultProcess, { url: pathUrl });
if (pathUrl) updateRecentFiles(pathUrl, defaultProcess);
}
} else { } else {
window.open(url, "_blank", "noopener, noreferrer"); window.open(url, "_blank", "noopener, noreferrer");
} }
}, },
[open] [open, updateRecentFiles]
); );
}; };