mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 00:20:05 +01:00
Preload cached desktop icons
This commit is contained in:
parent
35be051c58
commit
dfa902a5e4
|
|
@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
|
|||
import {
|
||||
FAVICON_BASE_PATH,
|
||||
HIGH_PRIORITY_ELEMENT,
|
||||
ICON_CACHE_EXTENSION,
|
||||
ICON_PATH,
|
||||
PACKAGE_DATA,
|
||||
USER_ICON_PATH,
|
||||
|
|
@ -80,9 +81,11 @@ const Metadata: FC = () => {
|
|||
/>
|
||||
<meta content={description} name="description" />
|
||||
{desktopIcons.map((icon) => {
|
||||
const isCacheIcon = icon.endsWith(ICON_CACHE_EXTENSION);
|
||||
const isStaticIcon =
|
||||
(!icon.startsWith(ICON_PATH) || icon.includes("/16x16/")) &&
|
||||
!icon.startsWith(USER_ICON_PATH);
|
||||
isCacheIcon ||
|
||||
((!icon.startsWith(ICON_PATH) || icon.includes("/16x16/")) &&
|
||||
!icon.startsWith(USER_ICON_PATH));
|
||||
|
||||
return (
|
||||
<link
|
||||
|
|
@ -93,7 +96,7 @@ const Metadata: FC = () => {
|
|||
isStaticIcon ? undefined : imageSrcs(icon, 48, ".webp")
|
||||
}
|
||||
rel="preload"
|
||||
type="image/webp"
|
||||
type={isCacheIcon ? undefined : "image/webp"}
|
||||
{...HIGH_PRIORITY_ELEMENT}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { readdirSync, readFileSync, writeFileSync } = require("fs");
|
||||
const { readdirSync, readFileSync, writeFileSync, existsSync } = require("fs");
|
||||
const { extname, join } = require("path");
|
||||
const { parse } = require("ini");
|
||||
|
||||
|
|
@ -10,20 +10,68 @@ const ICON_PATH = "/System/Icons";
|
|||
const SHORTCUT_ICON = `${ICON_PATH}/shortcut.webp`;
|
||||
const NEW_FOLDER_ICON = `${ICON_PATH}/new_folder.webp`;
|
||||
|
||||
const getPublicDirectoryIcons = (directory, includeSubIcons = false) => {
|
||||
const USER_ICON_PATH = `${HOME}/Icons`;
|
||||
const ICON_CACHE = `${USER_ICON_PATH}/Cache`;
|
||||
const YT_ICON_CACHE = `${ICON_CACHE}/YouTube`;
|
||||
const ICON_CACHE_EXTENSION = ".cache";
|
||||
|
||||
const VLC_SUBICON = "/System/Icons/16x16/vlc.webp";
|
||||
|
||||
const isYouTubeUrl = (url) =>
|
||||
url.includes("youtube.com/") || url.includes("youtu.be/");
|
||||
|
||||
const getYouTubeUrlId = (url) => {
|
||||
try {
|
||||
const { pathname, searchParams } = new URL(url);
|
||||
|
||||
return searchParams.get("v") || pathname.split("/").pop() || "";
|
||||
} catch {
|
||||
// URL parsing failed
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
const getPublicDirectoryIcons = (directory) => {
|
||||
const isDesktop = directory === DESKTOP_PATH;
|
||||
const baseDirectory = join("./public", directory);
|
||||
|
||||
return readdirSync(baseDirectory).reduce((icons, file) => {
|
||||
if (extname(file) === ".url") {
|
||||
const {
|
||||
InternetShortcut: { BaseURL: pid = "", IconFile: icon = "" },
|
||||
InternetShortcut: {
|
||||
BaseURL: pid = "",
|
||||
IconFile: icon = "",
|
||||
URL: url = "",
|
||||
},
|
||||
} = parse(readFileSync(join(baseDirectory, file)).toString());
|
||||
|
||||
if (icon) icons.push(icon);
|
||||
|
||||
if (includeSubIcons) {
|
||||
if (isDesktop) {
|
||||
if (pid === "VideoPlayer") {
|
||||
icons.push("/System/Icons/16x16/vlc.webp");
|
||||
if (!icons.includes(VLC_SUBICON)) icons.push(VLC_SUBICON);
|
||||
if (isYouTubeUrl(url)) {
|
||||
const iconFileName = `/${getYouTubeUrlId(
|
||||
url
|
||||
)}${ICON_CACHE_EXTENSION}`;
|
||||
|
||||
if (
|
||||
existsSync(join("./public", YT_ICON_CACHE, `${iconFileName}`))
|
||||
) {
|
||||
icons.push(`${YT_ICON_CACHE}${iconFileName}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const iconPath = url || `${directory}/${file}`;
|
||||
const iconFileName = `${iconPath}${ICON_CACHE_EXTENSION}`;
|
||||
|
||||
if (
|
||||
extname(iconPath) &&
|
||||
existsSync(join("./public", ICON_CACHE, `${iconFileName}`))
|
||||
) {
|
||||
icons.push(`${ICON_CACHE}${iconFileName}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user