mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
refactor: add full documentation and fix theme loading robustness
- Add JSDoc comments across frontend and backend modules - Improve code readability and maintainability with consistent documentation style - Document Electron IPC handlers, UI utilities, and theme system - Add missing function/class documentation in theme loader and app services - Minor structural improvements and cleanup across Electron main process modules - Minor fixes on variable names
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
/**
|
||||
* Initializes the download path system once the UI is ready.
|
||||
*
|
||||
* Responsibilities:
|
||||
* - Restore last known user-selected download path (localStorage)
|
||||
* - Validate it against backend rules
|
||||
* - Synchronize with backend authoritative path
|
||||
* - Setup folder selection UI interaction
|
||||
*/
|
||||
window.addEventListener("DOMContentLoaded", async () => {
|
||||
const savePathElem = document.getElementById("savePath");
|
||||
const form = document.getElementById("downloadForm");
|
||||
|
||||
// input caché = DERNIER chemin validé par le back
|
||||
/**
|
||||
* Hidden form field storing the validated download path
|
||||
* used during download submission.
|
||||
*
|
||||
* Created dynamically if not already present in DOM.
|
||||
*/
|
||||
let hidden = document.getElementById("savePathInput");
|
||||
|
||||
if (!hidden) {
|
||||
hidden = document.createElement("input");
|
||||
hidden.type = "hidden";
|
||||
@@ -12,6 +27,17 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
form.appendChild(hidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a validated download path received from backend.
|
||||
*
|
||||
* Updates:
|
||||
* - UI display (visible path)
|
||||
* - tooltip (full path)
|
||||
* - hidden form input (used for submission)
|
||||
* - localStorage cache (UX persistence only, not authoritative)
|
||||
*
|
||||
* @param {string} path - validated absolute download path
|
||||
*/
|
||||
async function applyPathFromBack(path) {
|
||||
savePathElem.textContent = path;
|
||||
savePathElem.title = path;
|
||||
@@ -19,6 +45,14 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
localStorage.setItem("customDownloadPath", path); // UX only
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the initial download path on application startup.
|
||||
*
|
||||
* Priority order:
|
||||
* 1. cached localStorage value (UX only, not trusted)
|
||||
* 2. backend validated version of cached path
|
||||
* 3. backend default fallback path if validation fails
|
||||
*/
|
||||
async function loadInitialPath() {
|
||||
// On affiche ce que le user a vu la dernière fois (UX)
|
||||
const cached = localStorage.getItem("customDownloadPath");
|
||||
@@ -42,13 +76,16 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
|
||||
await loadInitialPath();
|
||||
|
||||
document
|
||||
.getElementById("changePath")
|
||||
.addEventListener("click", async () => {
|
||||
/**
|
||||
* Opens system folder selector and updates download path.
|
||||
*
|
||||
* The selected folder is validated by Electron backend
|
||||
* before being applied to the UI and persisted.
|
||||
*/
|
||||
document.getElementById("changePath").addEventListener("click", async () => {
|
||||
try {
|
||||
// selectDownloadFolder already returns a validated path
|
||||
const validatedPath =
|
||||
await window.electronAPI.selectDownloadFolder();
|
||||
const validatedPath = await window.electronAPI.selectDownloadFolder();
|
||||
|
||||
if (!validatedPath) return; // cancelled
|
||||
|
||||
|
||||
Reference in New Issue
Block a user