Fix Library theme file path encoding - proper URI encoding for special characters and consistent file:// protocol usage

This commit is contained in:
dilgenfritz 2025-11-11 20:55:56 -06:00
parent 9d94fb8695
commit 2a27dee37b
1 changed files with 9 additions and 6 deletions

View File

@ -1458,19 +1458,22 @@
const randomImage = allImages[randomIndex];
if (randomImage) {
// Use different approaches for file paths based on environment
// Properly encode the file path for CSS url()
let imageUrl;
if (window.electronAPI) {
// In Electron, use the path as-is (Electron handles file protocol internally)
imageUrl = randomImage.path;
// In Electron, we need to properly encode the path for CSS
// Convert backslashes to forward slashes and encode special characters
const normalizedPath = randomImage.path.replace(/\\/g, '/');
// Use file:// protocol and encode the path
imageUrl = `file:///${encodeURI(normalizedPath)}`;
} else {
// In browser, use file protocol (though this may not work due to security restrictions)
const cleanPath = randomImage.path.replace(/\\/g, '/');
imageUrl = `file:///${cleanPath}`;
imageUrl = `file:///${encodeURI(cleanPath)}`;
}
element.style.backgroundImage = `url('${imageUrl}')`;
console.log(`📸 Panel ${index + 1}: Using ${randomImage.name} from ${imageUrl}`);
element.style.backgroundImage = `url("${imageUrl}")`;
console.log(`📸 Panel ${index + 1}: Using ${randomImage.name} from ${randomImage.path}`);
}
});