From 231ef25a15603c3118799164feee3fd3b5260d3a Mon Sep 17 00:00:00 2001 From: John Thomson Date: Tue, 24 Mar 2026 14:54:17 -0500 Subject: [PATCH] Preserve QR code when switching to standard mode (BL-16060) --- src/BloomExe/Book/Book.cs | 8 +++++++- src/BloomExe/Book/BookStorage.cs | 10 ++++++++-- src/BloomExe/web/controllers/EditingViewApi.cs | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/BloomExe/Book/Book.cs b/src/BloomExe/Book/Book.cs index 1f6ca06d034a..21375ebeba25 100644 --- a/src/BloomExe/Book/Book.cs +++ b/src/BloomExe/Book/Book.cs @@ -5403,12 +5403,18 @@ var page in RawDom public void UpdateSupportFiles() { Storage.UpdateSupportFiles(); + UpdateQrCodeHtmlForCurrentSettings(); + } + + internal void UpdateQrCodeHtmlForCurrentSettings(bool updateQrCodeFileEvenIfItExists = true) + { BookStorage.UpdateQrCode( OurHtmlDom, CollectionSettings.ShowBlorgLanguageQrCode, Language1Tag, CollectionSettings.BadgeQrCodeLabelLocalizedWithLang, - FolderPath + FolderPath, + updateQrCodeFileEvenIfItExists ); } diff --git a/src/BloomExe/Book/BookStorage.cs b/src/BloomExe/Book/BookStorage.cs index 238f88310af2..40f375d24722 100644 --- a/src/BloomExe/Book/BookStorage.cs +++ b/src/BloomExe/Book/BookStorage.cs @@ -2789,7 +2789,8 @@ public static void UpdateQrCode( bool shouldHaveQrCode, string langCode, string badgeQrCodeLabelLocalizedWithLang, - string bookFolderPath + string bookFolderPath, + bool updateQrCodeFileEvenIfItExists = true ) { var qrWrappers = dom.SafeSelectNodes( @@ -2799,6 +2800,8 @@ string bookFolderPath var url = "https://bloomlibrary.org/language:" + langCode; string qrFileName = null; + const string kQrFileName = "lang-qr-code.png"; + var qrFilePath = Path.Combine(bookFolderPath, kQrFileName); foreach (var qrWrapper in qrWrappers) { @@ -2823,7 +2826,10 @@ string bookFolderPath if (qrFileName == null) { - qrFileName = GenerateQrCodeImage(bookFolderPath, url); + if (updateQrCodeFileEvenIfItExists || !RobustFile.Exists(qrFilePath)) + qrFileName = GenerateQrCodeImage(bookFolderPath, url); + else + qrFileName = kQrFileName; } AdjustHtmlForHavingQrCode( diff --git a/src/BloomExe/web/controllers/EditingViewApi.cs b/src/BloomExe/web/controllers/EditingViewApi.cs index f6af7d3c507e..682425de77e9 100644 --- a/src/BloomExe/web/controllers/EditingViewApi.cs +++ b/src/BloomExe/web/controllers/EditingViewApi.cs @@ -203,6 +203,10 @@ private void HandleToggleCustomCover(ApiRequest request) // Bring everything up to date consistent with the new // state. Might be enough just do the BookData update. book.EnsureUpToDateMemory(new NullProgress()); + // Toggling between custom and standard layout can replace the xMatter page HTML, + // so reapply branding QR-code HTML adjustments for the current book settings. + // This should not need to regenerate the QR code file. + book.UpdateQrCodeHtmlForCurrentSettings(updateQrCodeFileEvenIfItExists: false); var updatedPageElt = book.GetPage(pageId)?.GetDivNodeForThisPage(); if (updatedPageElt != null)