LebToki / Laragon-Dashboard

A sleek, modern dashboard for Laragon that enhances your local development environment. With support for multiple languages, real-time server vitals monitoring, and easy navigation, this dashboard is designed to boost your productivity
23 stars 10 forks source link

Dynamic Favicons #3

Closed LebToki closed 8 months ago

LebToki commented 1 year ago

Requested by RobiNN1

Favicons: many sites have a favicon.ico file in the root of the site, so I would first check if it exists and then show a custom icon.

LebToki commented 1 year ago

I did come up with a solution but obviously takes some time to process all your directories (projects) to fetch the ico if it is existing otherwise reverts back to the hardcoded icon set by the webapp framework detected if all fails the unknown.png is then called from the assets/ directory and shows next to the app (overview card)

the function may take a long time to execute if there are a large number of directories to scan, and the user may perceive that the page has stalled. To address this issue, you can use an AJAX call to asynchronously fetch the data and update the page.

Here's an example of how you could implement an AJAX call:

-Add a loader/spinner to the page that indicates that the page is loading. -Create a new PHP file that contains only the code for the function, and returns the results as JSON. -Use JavaScript to send an AJAX request to the new PHP file. -When the response is received, hide the loader/spinner and display the results on the page.

Will do an exercise over the weekend.

LebToki commented 8 months ago

Create a new PHP script (e.g., fetch_icons.php) that will handle the scanning of directories and fetching of favicon information. This script will return data in JSON format. change your path data though

// fetch_icons.php <?php

// Function to fetch icons' paths or fallback to default function fetchIcons() { $projects = scandir('/path/to/your/projects/directory'); $icons = [];

foreach ($projects as $project) {
    if ($project === '.' || $project === '..') continue;

    $path = "/path/to/your/projects/directory/$project";
    $faviconPath = "$path/favicon.ico";

    if (file_exists($faviconPath)) {
        $icons[$project] = "/relative/path/to/$project/favicon.ico";
    } else {
        // Fallback to a predefined icon based on the webapp framework or unknown.png
        $icons[$project] = "/assets/unknown.png"; // Example fallback
    }
}

return $icons;

}

// Output icons as JSON header('Content-Type: application/json'); echo json_encode(fetchIcons());

add this to your html part in index.php