From f350e0a93963c02fda0068031d1d10ea7aeffacb Mon Sep 17 00:00:00 2001 From: Loganh4005 <60761520+Preloading@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:47:36 -0700 Subject: [PATCH 1/4] feat: implement the ability for canary to check for updates --- .../chrome/JS/Geckium_updater.uc.js | 43 ++++++++++++++++++- .../chrome/JS/modules/GeckiumUpdater.sys.mjs | 22 ++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Profile Folder/chrome/JS/Geckium_updater.uc.js b/Profile Folder/chrome/JS/Geckium_updater.uc.js index ed6f30d88..44202eb81 100644 --- a/Profile Folder/chrome/JS/Geckium_updater.uc.js +++ b/Profile Folder/chrome/JS/Geckium_updater.uc.js @@ -93,11 +93,21 @@ function updateSettings(iteration) { // PLACEHOLDER UPDATE MECHANISM FOR GECKIUM PUBLIC BETA 1 async function gkCheckForUpdates() { + // Check for updates based on the channel + if (await gkUpdater.getChannel() == "canary") { + await gkCheckForUpdatesCanary(); + } else { + await gkCheckForUpdateReleases(); + } + +} + +async function gkCheckForUpdateReleases() { const ghURL = "https://api.github.com/repos/angelbruni/Geckium/releases?page=1&per_page=1"; // Fetch remote version with timestamp to prevent caching var gkver = await gkUpdater.getVersion(); - fetch(ghURL, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json",}}) + fetch(ghURL, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) .then((response) => response.json()) .then((releases) => { if (releases[0].tag_name !== gkver) { @@ -108,4 +118,35 @@ async function gkCheckForUpdates() { console.error("Something happened when checking for newer Geckium builds:", error); }); } + +async function gkCheckForUpdatesCanary() { + // Canary is under a weird case where it is not an actual release, so we need to get it from github actions. + // Also versioning is different, using the commit hash. + const ghURL = "https://api.github.com/repos/angelbruni/Geckium/actions/workflows/127139753/runs?status=success&branch=main&check_suite_id=30704180915"; + var gkverraw = await gkUpdater.getRawVersion(); + fetch(ghURL, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) + .then((response) => response.json()) + .then((workflow_runs) => { + workflow_runs.forEach(run => { + // check if the latest successful run is newer than the current version. I am assuming they are in order of when they were run. + if (run.head_commit.id.substring(0, 7) == gkverraw) { + // We are on the newest version, abort. + return; + } + // We know that the latest run is newer than the current version, but we do not know if it actually built anything. + // We need to check the artifacts to see if there is a build. + fetch(`https://api.github.com/repos/angelbruni/Geckium/actions/runs/${run.id}/artifacts`, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) + .then((response) => response.json()) + .then((artifacts) => { + if (artifacts.total_count > 0) { + // We have a build, we can update. + document.documentElement.setAttribute("gkcanupdate", "true"); + } + }); + }); + }) + .catch(error => { + console.error("Something happened when checking for newer Geckium Canary builds:", error); + }); +} window.addEventListener("load", gkCheckForUpdates); \ No newline at end of file diff --git a/Profile Folder/chrome/JS/modules/GeckiumUpdater.sys.mjs b/Profile Folder/chrome/JS/modules/GeckiumUpdater.sys.mjs index 3668f28b4..7b5af3189 100644 --- a/Profile Folder/chrome/JS/modules/GeckiumUpdater.sys.mjs +++ b/Profile Folder/chrome/JS/modules/GeckiumUpdater.sys.mjs @@ -25,6 +25,28 @@ export class gkUpdater { throw error; // re-throw the error to propagate it further if needed } } + static async getChannel() { + try { + const response = await fetch("chrome://userchrome/content/version.json"); + const data = await response.json(); + + return data.update_channel; + } catch (error) { + console.error('Error fetching JSON:', error); + throw error; // re-throw the error to propagate it further if needed + } + } + static async getRawVersion() { + try { + const response = await fetch("chrome://userchrome/content/version.json"); + const data = await response.json(); + + return data.version; + } catch (error) { + console.error('Error fetching JSON:', error); + throw error; // re-throw the error to propagate it further if needed + } + } static checkForUpdates() { return "W.I.P." From 157c7352b467a527b3747b3eaea8269bf871d023 Mon Sep 17 00:00:00 2001 From: Loganh4005 <60761520+Preloading@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:37:31 -0700 Subject: [PATCH 2/4] fix the brokeness in last commit --- .../chrome/JS/Geckium_updater.uc.js | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Profile Folder/chrome/JS/Geckium_updater.uc.js b/Profile Folder/chrome/JS/Geckium_updater.uc.js index 44202eb81..0e879d98f 100644 --- a/Profile Folder/chrome/JS/Geckium_updater.uc.js +++ b/Profile Folder/chrome/JS/Geckium_updater.uc.js @@ -112,6 +112,8 @@ async function gkCheckForUpdateReleases() { .then((releases) => { if (releases[0].tag_name !== gkver) { document.documentElement.setAttribute("gkcanupdate", "true"); + } else { + document.documentElement.setAttribute("gkcanupdate", "false"); } }) .catch(error => { @@ -122,28 +124,39 @@ async function gkCheckForUpdateReleases() { async function gkCheckForUpdatesCanary() { // Canary is under a weird case where it is not an actual release, so we need to get it from github actions. // Also versioning is different, using the commit hash. - const ghURL = "https://api.github.com/repos/angelbruni/Geckium/actions/workflows/127139753/runs?status=success&branch=main&check_suite_id=30704180915"; + const ghURL = "https://api.github.com/repos/angelbruni/Geckium/actions/workflows/127139753/runs?status=success&branch=main"; var gkverraw = await gkUpdater.getRawVersion(); fetch(ghURL, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) .then((response) => response.json()) .then((workflow_runs) => { - workflow_runs.forEach(run => { + // JSON is beautiful, isn't it? + let hasUpdate = false; + for (let run of workflow_runs.workflow_runs) { + if (hasUpdate) break; + console.log("We found a run with the following commit hash: " + run.head_commit.id.substring(0, 7) + " current version: " + gkverraw); // check if the latest successful run is newer than the current version. I am assuming they are in order of when they were run. if (run.head_commit.id.substring(0, 7) == gkverraw) { // We are on the newest version, abort. - return; + console.log("We are on the newest version, aborting."); + document.documentElement.setAttribute("gkcanupdate", "false"); + break; } + console.log("Not using latest run, checking for artifacts."); // We know that the latest run is newer than the current version, but we do not know if it actually built anything. // We need to check the artifacts to see if there is a build. - fetch(`https://api.github.com/repos/angelbruni/Geckium/actions/runs/${run.id}/artifacts`, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) + fetch(run.artifacts_url, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) .then((response) => response.json()) .then((artifacts) => { if (artifacts.total_count > 0) { // We have a build, we can update. document.documentElement.setAttribute("gkcanupdate", "true"); + console.log("We have a build, we can update."); + hasUpdate = true; + } else { + console.log("No artifacts found, skipping."); } }); - }); + } }) .catch(error => { console.error("Something happened when checking for newer Geckium Canary builds:", error); From e14c4148a45a52a42f68d4083b111a6e58cf4e95 Mon Sep 17 00:00:00 2001 From: Loganh4005 <60761520+Preloading@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:39:36 -0700 Subject: [PATCH 3/4] ci: add name to build step --- .github/workflows/buildcanary.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/buildcanary.yml b/.github/workflows/buildcanary.yml index 9cd8628a2..d930047ff 100644 --- a/.github/workflows/buildcanary.yml +++ b/.github/workflows/buildcanary.yml @@ -34,6 +34,7 @@ jobs: echo "should_run=true" >> $GITHUB_OUTPUT fi build: + name: Build Canary needs: check_date if: ${{ needs.check_date.outputs.should_run != 'false' || github.event_name != 'schedule' }} runs-on: ubuntu-latest From facf391196d182eea9cf3c6ba8c194d01f5ed1f0 Mon Sep 17 00:00:00 2001 From: Loganh4005 <60761520+Preloading@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:44:55 -0700 Subject: [PATCH 4/4] hotfix: remove leftover debug code for canary updates --- Profile Folder/chrome/JS/Geckium_updater.uc.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Profile Folder/chrome/JS/Geckium_updater.uc.js b/Profile Folder/chrome/JS/Geckium_updater.uc.js index 0e879d98f..1e3ac51d7 100644 --- a/Profile Folder/chrome/JS/Geckium_updater.uc.js +++ b/Profile Folder/chrome/JS/Geckium_updater.uc.js @@ -133,15 +133,14 @@ async function gkCheckForUpdatesCanary() { let hasUpdate = false; for (let run of workflow_runs.workflow_runs) { if (hasUpdate) break; - console.log("We found a run with the following commit hash: " + run.head_commit.id.substring(0, 7) + " current version: " + gkverraw); + // check if the latest successful run is newer than the current version. I am assuming they are in order of when they were run. if (run.head_commit.id.substring(0, 7) == gkverraw) { // We are on the newest version, abort. - console.log("We are on the newest version, aborting."); document.documentElement.setAttribute("gkcanupdate", "false"); break; } - console.log("Not using latest run, checking for artifacts."); + // We know that the latest run is newer than the current version, but we do not know if it actually built anything. // We need to check the artifacts to see if there is a build. fetch(run.artifacts_url, {cache: "reload", headers: {"X-GitHub-Api-Version": "2022-11-28", "Accept": "application/vnd.github+json", "UserAgent": "GeckiumUpdater/1.0"}}) @@ -150,10 +149,7 @@ async function gkCheckForUpdatesCanary() { if (artifacts.total_count > 0) { // We have a build, we can update. document.documentElement.setAttribute("gkcanupdate", "true"); - console.log("We have a build, we can update."); hasUpdate = true; - } else { - console.log("No artifacts found, skipping."); } }); }