From 2d9988b1be556acb1fb45d6dea04d0b9f3f820bc Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:54:44 -0400 Subject: [PATCH] fix fetching build number (closes #243) --- src/startup.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/startup.cpp b/src/startup.cpp index 06d6402..89e29a5 100644 --- a/src/startup.cpp +++ b/src/startup.cpp @@ -29,10 +29,22 @@ std::optional> ParseCookie(const Glib::ustri } std::optional GetJavascriptFileFromAppPage(const Glib::ustring &contents) { - auto regex = Glib::Regex::create(R"(app-mount.*(/assets/[\w\d]*.js).*/assets/[\w\d]*.js)"); + auto regex = Glib::Regex::create(R"(/assets/\w{20}.js)"); + std::vector matches; + + // regex->match_all doesnt work for some reason + int start_position = 0; Glib::MatchInfo match; - if (regex->match(contents, match)) { - return match.fetch(1); + while (regex->match(contents, start_position, match)) { + const auto str = match.fetch(0); + matches.push_back(str); + int foo; + match.fetch_pos(0, start_position, foo); + start_position += str.size(); + } + + if (matches.size() >= 6) { + return matches[matches.size() - 6]; } return {}; @@ -52,7 +64,7 @@ std::optional GetBuildNumberFromJSURL(const Glib::ustring &url, const auto res = req.execute(); if (res.error) return {}; - auto regex = Glib::Regex::create(R"("buildNumber",null!==\(t="(\d+)\"\))"); + auto regex = Glib::Regex::create("buildNumber:\"(\\d+)\""); Glib::MatchInfo match; Glib::ustring string = res.text; if (regex->match(string, match)) {