From c0797b385a077d2507b4f5c3898ab915a2ccc878 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 6 Apr 2026 19:34:08 +0200 Subject: [PATCH] Show file extensions in browser (user option) --- lib/I18n/translations/english.yaml | 1 + lib/I18n/translations/german.yaml | 1 + src/CrossPointSettings.h | 2 ++ src/SettingsList.h | 2 ++ src/activities/home/FileBrowserActivity.cpp | 3 +++ src/network/html/FilesPage.html | 27 +++++++++++++++++++-- 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/I18n/translations/english.yaml b/lib/I18n/translations/english.yaml index 77fc741d..67f65d55 100644 --- a/lib/I18n/translations/english.yaml +++ b/lib/I18n/translations/english.yaml @@ -87,6 +87,7 @@ STR_PARA_ALIGNMENT: "Reader Paragraph Alignment" STR_HYPHENATION: "Hyphenation" STR_TIME_TO_SLEEP: "Time to Sleep" STR_SHOW_HIDDEN_FILES: "Show Hidden Files" +STR_SHOW_FILE_EXTENSIONS: "Show File Extensions" STR_USE_CLOCK: "Use Clock" STR_CLOCK_SETTINGS: "Clock Settings" STR_CLOCK_SETTINGS_WARNING: "Uses more battery; clock may drift" diff --git a/lib/I18n/translations/german.yaml b/lib/I18n/translations/german.yaml index f70f56f6..8ec0c7c9 100644 --- a/lib/I18n/translations/german.yaml +++ b/lib/I18n/translations/german.yaml @@ -300,6 +300,7 @@ STR_IMAGES_DISPLAY: "Darstellung" STR_IMAGES_PLACEHOLDER: "Platzhalter" STR_IMAGES_SUPPRESS: "Unterdrücken" STR_SHOW_HIDDEN_FILES: "Versteckte Dateien anzeigen" +STR_SHOW_FILE_EXTENSIONS: "Dateierweiterungen anzeigen" STR_PAGE_OVERLAY: "Seiten-Overlay" STR_RECENTS: "Zuletzt" STR_MAPPING_REMOTE: "Externe Position zuordnen..." diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 7c6ea750..94d110c1 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -231,6 +231,8 @@ class CrossPointSettings { uint8_t embeddedStyle = 1; // Show hidden files/directories (starting with '.') in the file browser (0 = hidden, 1 = show) uint8_t showHiddenFiles = 0; + // Show file extensions in the file browser (0 = hidden, 1 = show) + uint8_t showFileExtensions = 0; // Image rendering mode in EPUB reader uint8_t imageRendering = IMAGES_DISPLAY; // Dithering mode for decoded images (EPUB/JPG/PNG) diff --git a/src/SettingsList.h b/src/SettingsList.h index 8bfa98e3..c8a41249 100644 --- a/src/SettingsList.h +++ b/src/SettingsList.h @@ -92,6 +92,8 @@ inline const std::vector& getSettingsList() { "sleepTimeout", StrId::STR_CAT_SYSTEM), SettingInfo::Toggle(StrId::STR_SHOW_HIDDEN_FILES, &CrossPointSettings::showHiddenFiles, "showHiddenFiles", StrId::STR_CAT_SYSTEM), + SettingInfo::Toggle(StrId::STR_SHOW_FILE_EXTENSIONS, &CrossPointSettings::showFileExtensions, + "showFileExtensions", StrId::STR_CAT_SYSTEM), SettingInfo::Enum(StrId::STR_CLOCK_FORMAT, &CrossPointSettings::clockFormat12h, {StrId::STR_24H, StrId::STR_12H}, "clockFormat12h", StrId::STR_CAT_SYSTEM), SettingInfo::Enum(StrId::STR_TIMEZONE, &CrossPointSettings::timeZone, diff --git a/src/activities/home/FileBrowserActivity.cpp b/src/activities/home/FileBrowserActivity.cpp index 557ef8cb..a4e771df 100644 --- a/src/activities/home/FileBrowserActivity.cpp +++ b/src/activities/home/FileBrowserActivity.cpp @@ -263,6 +263,9 @@ std::string getFileName(std::string filename) { } return filename; } + if (SETTINGS.showFileExtensions) { + return filename; + } const auto pos = filename.rfind('.'); return filename.substr(0, pos); } diff --git a/src/network/html/FilesPage.html b/src/network/html/FilesPage.html index 884708d6..d574063d 100644 --- a/src/network/html/FilesPage.html +++ b/src/network/html/FilesPage.html @@ -2109,8 +2109,9 @@ } async function hydrate() { - // Fetch CrossPoint version + // Fetch CrossPoint version and file extension setting fetchVersion(); + await fetchShowFileExtensions(); // Close modals when clicking overlay - call proper cleanup functions document.querySelectorAll('.modal-overlay').forEach(function (overlay) { @@ -2207,7 +2208,7 @@ fileTableContent += ``; fileTableContent += ``; fileTableContent += `${file.isEpub ? '📗' : '📄'}`; - fileTableContent += `${escapeHtml(file.name)}`; + fileTableContent += `${escapeHtml(displayFileName(file.name))}`; if (file.isEpub) fileTableContent += 'EPUB'; fileTableContent += ''; fileTableContent += `${file.name.split('.').pop().toUpperCase()}`; @@ -3292,6 +3293,28 @@ const logContainer = document.getElementById('log-container'); const exportLogCheckbox = document.getElementById('export-log-checkbox'); + // Show file extensions setting (fetched from API) + let showFileExtensions = false; + + async function fetchShowFileExtensions() { + try { + const response = await fetch('/api/settings'); + if (response.ok) { + const settings = await response.json(); + const entry = settings.find(s => s.key === 'showFileExtensions'); + if (entry) showFileExtensions = !!entry.value; + } + } catch (e) { + console.error('Failed to fetch settings:', e); + } + } + + function displayFileName(name) { + if (showFileExtensions) return name; + const dot = name.lastIndexOf('.'); + return dot > 0 ? name.substring(0, dot) : name; + } + // CrossPoint version (fetched from API) let crosspointVersion = 'Unknown';