Browse Source

In-app updates: verified end to end on Windows and Linux with a local fixture

- Updated bar: the version and notes being installed are kept beside the helper, so the first start after an update says the right version and offers What's new; no automatic check in that session
- The delayed clean-up after start removed a setup.exe downloaded in the first 15 s: it now only removes the helper copy, and only when no update is pending
- Release notes: GitHub alert markers (> [!IMPORTANT]) and HTML-only lines (the logo) leave no text; a bare '>' line no longer reads past an empty string
- REA_rodada166b.md: verification table
Ka1-S 1 month ago
parent
commit
d90edcfa42
4 changed files with 162 additions and 56 deletions
  1. 23 2
      docs/analise/REA_rodada166b.md
  2. 32 0
      src/core/UpdateCheck.cpp
  3. 95 54
      src/ui/Updater.cpp
  4. 12 0
      tests/Update166bTests.inc

+ 23 - 2
docs/analise/REA_rodada166b.md

@@ -7,7 +7,10 @@ the user-approved "In-app update check" section of the 0.1.21 plan.
 - Implemented: core/UpdateCheck (versions, release JSON, flavours, assets, checksums, release notes, settings),
   ui/Updater (check, bar, What's new, Update per flavour, `--apply-update` helper), Settings › General › Updates,
   Help › Check for updates..., PRIVACY.md, docs/STORE.md, NSIS silent-update choices, release.yml note, 15 languages.
-- Next: Windows end-to-end test with a local fixture (see "Verification"), then land.
+- Verified end to end on Windows (installer, portable, skip, manual check, damaged download, offline) and Linux
+  (AppImage) with a local fixture; see "Verification". Landed.
+- Left for later: macOS path (.dmg to Downloads + reveal) is built on the shared code but not run on a Mac; the first real
+  check against GitHub happens with the 0.1.21 release (0.1.20 has no updater, so 0.1.21 → 0.1.22 is the first real update).
 
 ## Design
 
@@ -29,4 +32,22 @@ the user-approved "In-app update check" section of the 0.1.21 plan.
 | AppImage | `scripts/package-linux.sh` | update information was already embedded (`gh-releases-zsync|Ka1-S|LYNX-SHARE|latest-all|LYNX-*-x86_64.AppImage.zsync`; `latest-all` because every LYNX release is a prerelease — `latest` would skip them) and the .zsync is published |
 
 ## Verification
-(filled in below as it is done)
+Fixture: `releases.json` in GitHub's shape (a draft 0.2.0 that must be skipped, 0.1.99-alpha with the real 0.1.20 notes as
+body, older releases), `SHA256SUMS.txt`, a `LYNX-0.1.99-alpha-setup-x64.exe` built by makensis from `LYNX.nsi` with a marker
+file, the portable zip; served by `python3 -m http.server`; `LYNX_UPDATE_URL` points at it, `LYNX_UPDATE_VERSION=0.1.20`
+fakes the old version. Every run: fresh `LYNX_PROFILE_DIR`, `LYNX_TEST_MODE=1`, install folder on E:, registry restored after.
+
+| Case | Result |
+|---|---|
+| Core tests (`Update166bTests.inc`, 7 tests) + a standalone harness of the same file | 129 checks, 0 failures |
+| Snapshot (`--snapshot`): bar and What's new | `-update-bar.png`, `-update-notes.png` look right |
+| Windows: silent install of 0.1.20 (`/S /D=`) | no desktop shortcut, no .flp "Open with" entry (`SilentKeepsChoices`) |
+| Windows installer flavour: bar → What's new → Update | download 0.6 s, checksum OK, helper waits for the pid, `setup /S` in 2 s, DisplayVersion 0.1.99, marker present, relaunched; next start shows "LYNX SHARE was updated to …" (no new check that session), temp files gone |
+| What's new with the real 45 KB notes | opens at once (a `TextEditor` took > 1 min to insert them; replaced by an `AttributedString` view) |
+| ✕ on the bar | `skipped=0.1.99-alpha` in updates.txt, bar gone; Help › Check for updates still offers it |
+| Portable flavour | zip saved to Downloads, bar "saved to … / Show in folder" |
+| Damaged download (bad SHA256SUMS) | "The update failed: the download is damaged…", Try again / Open the release page, file deleted |
+| Running the newest version, Help › Check for updates | "You're up to date: LYNX SHARE 0.1.99-alpha is the newest version." |
+| Offline (nothing listening) | automatic check silent: no bar, no dialog |
+| Linux AppImage (WSLg) | new AppImage downloaded and checked beside the old one, chmod +x, "Restart now" |
+| GitHub alert markers in notes (`> [!IMPORTANT]`) | dropped (seen raw in the first run; fixed + test) |

+ 32 - 0
src/core/UpdateCheck.cpp

@@ -702,9 +702,34 @@ namespace
 // inline Markdown to text: ![alt](url) goes, [text](url) keeps the text, <tags> go, ** __ ` go, \* escapes
 std::string inlineText (const std::string& s)
 {
+    // *emphasis* / _emphasis_: the pairs of single marks around words go (a lone '*' or snake_case stays)
+    std::vector<bool> drop (s.size(), false);
+    for (char mark : { '*', '_' })
+        for (std::size_t i = 0; i < s.size(); ++i)
+        {
+            const bool doubled = (i + 1 < s.size() && s[i + 1] == mark) || (i > 0 && s[i - 1] == mark);
+            if (s[i] != mark || doubled || (i > 0 && s[i - 1] == '\\') || i + 1 >= s.size() || std::isspace ((unsigned char) s[i + 1]))
+                continue;
+            if (mark == '_' && i > 0 && std::isalnum ((unsigned char) s[i - 1]))
+                continue;
+            for (std::size_t j = i + 2; j < s.size(); ++j)
+                if (s[j] == mark && ! std::isspace ((unsigned char) s[j - 1]) && s[j - 1] != '\\'
+                    && ! (j + 1 < s.size() && s[j + 1] == mark)
+                    && (mark == '*' || j + 1 >= s.size() || ! std::isalnum ((unsigned char) s[j + 1])))
+                {
+                    drop[i] = drop[j] = true;
+                    i = j;
+                    break;
+                }
+        }
     std::string out;
     for (std::size_t i = 0; i < s.size();)
     {
+        if (drop[i])
+        {
+            ++i;
+            continue;
+        }
         const char c = s[i];
         if (c == '\\' && i + 1 < s.size() && std::ispunct ((unsigned char) s[i + 1]))
         {
@@ -766,6 +791,8 @@ std::vector<NoteLine> releaseNotes (const std::string& markdown)
 {
     std::vector<NoteLine> lines;
     auto push = [&lines] (NoteLine line) {
+        if (line.kind == NoteLine::Kind::text && trim (line.text).empty())
+            line.kind = NoteLine::Kind::blank; // e.g. a line of HTML only (a centred logo)
         if (line.kind == NoteLine::Kind::blank && (lines.empty() || lines.back().kind == NoteLine::Kind::blank))
             return;
         lines.push_back (std::move (line));
@@ -826,7 +853,12 @@ std::vector<NoteLine> releaseNotes (const std::string& markdown)
         }
         auto text = t;
         if (text[0] == '>')
+        {
             text = trim (text.substr (1));
+            // a GitHub alert marker ("> [!IMPORTANT]") is not text; an empty quote line ends the paragraph
+            if (text.empty() || (text.size() > 3 && text.compare (0, 2, "[!") == 0 && text.back() == ']'))
+                continue;
+        }
         if (text.front() == '|' && text.back() == '|') // a table row: cells apart
         {
             std::string row;

+ 95 - 54
src/ui/Updater.cpp

@@ -52,7 +52,7 @@ juce::File downloadsFolder()
     {
         wchar_t expanded[MAX_PATH * 2] {};
         if (ExpandEnvironmentStringsW (known.toWideCharPointer(), expanded, (DWORD) std::size (expanded)) > 0)
-            if (const juce::File f (juce::String (expanded)); juce::File::isAbsolutePath (f.getFullPathName()) && f.isDirectory())
+            if (const juce::File f { juce::String (expanded) }; juce::File::isAbsolutePath (f.getFullPathName()) && f.isDirectory())
                 return f;
     }
    #endif
@@ -569,6 +569,9 @@ void installAndRestart (const juce::File& setup)
             return;
         }
         updateFolder().getChildFile ("result.txt").deleteFile();
+        // the version being installed, for the "was updated to" bar on the next start
+        updateFolder().getChildFile ("installing.txt").replaceWithText ("version=" + juce::String (c.release.version.text()) + "\n");
+        updateFolder().getChildFile ("installing-notes.md").replaceWithText (fromUtf8 (c.release.body));
         juce::StringArray args { helper.getFullPathName(), "--apply-update", setup.getFullPathName(), exe.getParentDirectory().getFullPathName(),
                                  juce::String ((juce::int64) currentPid()) };
         if (const auto project = c.host.currentProject ? c.host.currentProject() : juce::File(); project.existsAsFile())
@@ -742,9 +745,12 @@ void setAutomatic (bool on)
 
 void setHost (Host host) { controller().host = std::move (host); }
 
+// set when this start follows an update: no automatic check this session (the "updated" bar stays)
+static bool justUpdated = false;
+
 void startAutomaticCheck()
 {
-    if (! offered() || ! automatic())
+    if (! offered() || ! automatic() || justUpdated)
         return;
     // LYNX_TEST_MODE: no network, unless a test fixture is named
     if (platform::testMode() && overrideUrl().isEmpty())
@@ -788,17 +794,26 @@ void afterStart()
             if (line.startsWith ("version=")) version = line.fromFirstOccurrenceOf ("=", false, false).trim();
         }
         resultFile.deleteFile();
+        const auto installing = folder.getChildFile ("installing.txt");
+        if (version.isEmpty() && installing.existsAsFile())
+            version = installing.loadFileAsString().fromFirstOccurrenceOf ("version=", false, false).trim();
+        log ("after start: update result " + result + (detail.isNotEmpty() ? " (" + detail + ")" : juce::String()));
         if (result == "ok")
         {
+            justUpdated = true;
             auto& c = controller();
             // the release notes come from the cached list when there is one
             const auto list = update::parseReleases (utf8 (cachePath().loadFileAsString()));
             c.release = {};
+            const auto installed = version.isNotEmpty() ? update::parseVersion (utf8 (version)) : runningVersion();
             for (const auto& r : list)
-                if (update::compare (r.version, runningVersion()) == 0 || r.version.text() == utf8 (version))
+                if (update::compare (r.version, installed) == 0)
                     c.release = r;
             if (c.release.tag.empty())
-                c.release.version = runningVersion();
+            {
+                c.release.version = installed;
+                c.release.body = utf8 (folder.getChildFile ("installing-notes.md").loadFileAsString());
+            }
             c.setPhase (Phase::updated);
         }
         else
@@ -806,13 +821,19 @@ void afterStart()
                      tr ("The update could not be installed ({0}). This version of LYNX SHARE is still installed; details in {1}.",
                          { detail, folder.getChildFile ("update.log").getFullPathName() }));
     }
-    // the installer and the helper copy of LYNX.exe go (the helper may still be ending: once more a little later)
-    auto clean = [folder] {
-        for (const auto& f : folder.findChildFiles (juce::File::findFiles, false, "*.exe;*.part;*.tmp"))
-            f.deleteFile();
-    };
-    clean();
-    juce::Timer::callAfterDelay (15000, clean);
+    folder.getChildFile ("installing.txt").deleteFile();
+    folder.getChildFile ("installing-notes.md").deleteFile();
+    // the installer and the helper copy of LYNX.exe go (nothing has been downloaded yet in this session)
+    for (const auto& f : folder.findChildFiles (juce::File::findFiles, false, "*.exe;*.part;*.tmp"))
+        f.deleteFile();
+    // the helper may still be ending: its copy once more a little later, unless an update of this session needs the folder
+    // (a new download is already there by then, and "Install and restart" copies the helper again)
+    juce::Timer::callAfterDelay (15000, [folder] {
+        const auto phase = controller().phase;
+        if (phase == Phase::idle || phase == Phase::checking || phase == Phase::available || phase == Phase::updated
+            || phase == Phase::failed || phase == Phase::saved)
+            folder.getChildFile ("LYNX-updater.exe").deleteFile();
+    });
 }
 
 bool runApplyHelper (const juce::StringArray& args)
@@ -1087,60 +1108,71 @@ void UpdateBar::resized()
 // ================================================================================================================
 namespace
 {
-class NotesPanel final : public juce::Component
+// The release notes as one laid-out AttributedString (a 45 KB release body inserted run by run into a TextEditor took
+// seconds on Windows: each insert re-lays the whole text out). Laid out again only when the width changes.
+class NotesText final : public juce::Component
 {
 public:
-    explicit NotesPanel (const update::Release& r)
+    explicit NotesText (const std::vector<update::NoteLine>& lines)
     {
-        title.setText (r.name.empty() ? "LYNX SHARE " + versionText (r) : fromUtf8 (r.name), juce::dontSendNotification);
-        title.setFont (theme::font (theme::type::title + 3.0f, true));
-        title.setColour (juce::Label::textColourId, theme::colour::textPrimary);
-        addAndMakeVisible (title);
-
-        notes.setMultiLine (true, true);
-        notes.setReadOnly (true);
-        notes.setScrollbarsShown (true);
-        notes.setCaretVisible (false);
-        notes.setColour (juce::TextEditor::backgroundColourId, theme::colour::bg1);
-        notes.setColour (juce::TextEditor::outlineColourId, theme::colour::border);
-        notes.setColour (juce::TextEditor::focusedOutlineColourId, theme::colour::border);
-        notes.setBorder (juce::BorderSize<int> (10, 12, 10, 12));
-        const auto lines = update::releaseNotes (r.body);
+        using K = update::NoteLine::Kind;
+        text.setWordWrap (juce::AttributedString::byWord);
+        text.setLineSpacing (2.0f);
+        auto add = [this] (const juce::String& s, juce::FontOptions font, juce::Colour colour) { text.append (s, juce::Font (font), colour); };
         if (lines.empty())
-        {
-            notes.setColour (juce::TextEditor::textColourId, theme::colour::textSecondary);
-            notes.setFont (theme::font (theme::type::body));
-            notes.insertTextAtCaret (tr ("This release has no notes."));
-        }
+            add (tr ("This release has no notes."), theme::font (theme::type::body), theme::colour::textSecondary);
         for (const auto& l : lines)
         {
-            using K = update::NoteLine::Kind;
-            const auto text = fromUtf8 (l.text);
+            const auto t = juce::String::fromUTF8 (l.text.c_str());
             switch (l.kind)
             {
                 case K::heading:
-                    notes.setColour (juce::TextEditor::textColourId, l.level <= 2 ? theme::colour::accent : theme::colour::textPrimary);
-                    notes.setFont (theme::font (l.level <= 1 ? theme::type::title + 3.0f : l.level == 2 ? theme::type::title + 1.0f : theme::type::body + 1.0f, true));
-                    notes.insertTextAtCaret (text + "\n");
+                    add (t + "\n", theme::font (l.level <= 1 ? theme::type::title + 3.0f : l.level == 2 ? theme::type::title + 1.0f : theme::type::body + 1.0f, true),
+                         l.level <= 2 ? theme::colour::accent : theme::colour::textPrimary);
                     break;
                 case K::bullet:
-                    notes.setColour (juce::TextEditor::textColourId, theme::colour::textPrimary);
-                    notes.setFont (theme::font (theme::type::body));
-                    notes.insertTextAtCaret (juce::String::repeatedString ("    ", l.level) + juce::String::fromUTF8 ("\xE2\x80\xA2  ") + text + "\n");
-                    break;
-                case K::text:
-                    notes.setColour (juce::TextEditor::textColourId, theme::colour::textSecondary);
-                    notes.setFont (theme::font (theme::type::body));
-                    notes.insertTextAtCaret (text + "\n");
-                    break;
-                case K::blank:
-                    notes.setFont (theme::font (theme::type::small));
-                    notes.insertTextAtCaret ("\n");
+                    add (juce::String::repeatedString ("      ", l.level) + juce::String::fromUTF8 ("\xE2\x80\xA2  ") + t + "\n", theme::font (theme::type::body),
+                         theme::colour::textPrimary);
                     break;
+                case K::text: add (t + "\n", theme::font (theme::type::body), theme::colour::textSecondary); break;
+                case K::blank: add ("\n", theme::font (theme::type::small), theme::colour::textSecondary); break;
             }
         }
-        notes.moveCaretToTop (false);
-        addAndMakeVisible (notes);
+    }
+
+    // lays the text out for `width` and takes the height it needs
+    void fitWidth (int width)
+    {
+        if (width == laidOutWidth)
+            return;
+        laidOutWidth = width;
+        layout.createLayout (text, (float) juce::jmax (100, width - 2 * margin));
+        setSize (width, (int) std::ceil (layout.getHeight()) + 2 * margin);
+    }
+
+    void paint (juce::Graphics& g) override { layout.draw (g, getLocalBounds().reduced (margin).toFloat()); }
+
+private:
+    static constexpr int margin = 12;
+    juce::AttributedString text;
+    juce::TextLayout layout;
+    int laidOutWidth = -1;
+};
+
+class NotesPanel final : public juce::Component
+{
+public:
+    explicit NotesPanel (const update::Release& r) : notes (update::releaseNotes (r.body))
+    {
+        title.setText (r.name.empty() ? "LYNX SHARE " + versionText (r) : fromUtf8 (r.name), juce::dontSendNotification);
+        title.setFont (theme::font (theme::type::title + 3.0f, true));
+        title.setColour (juce::Label::textColourId, theme::colour::textPrimary);
+        addAndMakeVisible (title);
+
+        viewport.setViewedComponent (&notes, false);
+        viewport.setScrollBarsShown (true, false);
+        viewport.setScrollBarThickness (10);
+        addAndMakeVisible (viewport);
 
         page = releasePage (r);
         githubButton.setButtonText (tr ("Open on GitHub"));
@@ -1165,7 +1197,14 @@ public:
         setSize (680, 540);
     }
 
-    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg2);
+        g.setColour (theme::colour::bg1);
+        g.fillRect (viewport.getBounds());
+        g.setColour (theme::colour::border);
+        g.drawRect (viewport.getBounds().expanded (1));
+    }
 
     void resized() override
     {
@@ -1174,7 +1213,8 @@ public:
         r.removeFromTop (8);
         auto buttons = r.removeFromBottom (30);
         r.removeFromBottom (12);
-        notes.setBounds (r);
+        viewport.setBounds (r.reduced (1));
+        notes.fitWidth (viewport.getMaximumVisibleWidth());
         closeButton.setBounds (buttons.removeFromRight (100));
         buttons.removeFromRight (8);
         if (updateButton.isVisible())
@@ -1187,7 +1227,8 @@ public:
 
 private:
     juce::Label title;
-    juce::TextEditor notes;
+    NotesText notes;
+    juce::Viewport viewport;
     juce::TextButton githubButton, closeButton, updateButton;
     juce::String page;
 };

+ 12 - 0
tests/Update166bTests.inc

@@ -228,5 +228,17 @@ TEST (update166b_release_notes_as_text)
     CHECK (lines.size() > 6 && lines[4].level == 2 && lines[6].level == 1);
     const auto text = releaseNotesText (lines);
     CHECK (text.find ("\xE2\x80\xA2 A bar") != std::string::npos && text.find ("    \xE2\x80\xA2 nested") != std::string::npos);
+    // single-mark emphasis goes, snake_case and a lone star stay
+    const auto em = releaseNotes ("*Update* installs it, _really_; snake_case_name, 2 * 3 = 6, **bold**");
+    CHECK (em.size() == 1 && em[0].text == "Update installs it, really; snake_case_name, 2 * 3 = 6, bold");
+    if (em.size() == 1)
+        std::printf ("  em: [%s]\n", em[0].text.c_str());
     CHECK (releaseNotes ("").empty() && releaseNotes ("\n\n\n").empty());
+    // a GitHub alert marker is dropped; the quoted text stays; a bare ">" is safe
+    const auto alert = releaseNotes ("Intro\n> [!IMPORTANT]\n> Still an alpha.\n>\n> More.");
+    CHECK (alert.size() == 3 && alert[0].text == "Intro" && alert[1].text == "Still an alpha." && alert[2].text == "More.");
+    CHECK (releaseNotes (">").empty() && releaseNotes ("> [!NOTE]").empty());
+    // a line of HTML only (the logo at the top of the release notes) leaves no empty line
+    const auto logo = releaseNotes ("<p align=\"center\"><img src=\"x.png\" width=\"96\"></p>\n\n**LYNX SHARE 0.1.20 alpha**: text");
+    CHECK (logo.size() == 1 && logo[0].text == "LYNX SHARE 0.1.20 alpha: text");
 }