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 diff --git a/Profile Folder/chrome/JS/Geckium_updater.uc.js b/Profile Folder/chrome/JS/Geckium_updater.uc.js index 0ce26e25e..362d75413 100644 --- a/Profile Folder/chrome/JS/Geckium_updater.uc.js +++ b/Profile Folder/chrome/JS/Geckium_updater.uc.js @@ -128,19 +128,69 @@ function updateSettings(iteration) { // PLACEHOLDER UPDATE MECHANISM FOR GECKIUM PUBLIC BETA 1 async function gkCheckForUpdates() { - const ghURL = "https://api.github.com/repos/angelbruni/Geckium/releases?page=1&per_page=1"; + // Check for updates based on the channel + if (await gkUpdater.getChannel() == "canary") { + await gkCheckForUpdatesCanary(); + } else { + await gkCheckForUpdateReleases(); + } + +} - // 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",}}) - .then((response) => response.json()) - .then((releases) => { - if (releases[0].tag_name !== gkver) { - document.documentElement.setAttribute("gkcanupdate", "true"); - } - }) - .catch(error => { - console.error("Something happened when checking for newer Geckium builds:", error); - }); +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", "UserAgent": "GeckiumUpdater/1.0"}}) + .then((response) => response.json()) + .then((releases) => { + if (releases[0].tag_name !== gkver) { + document.documentElement.setAttribute("gkcanupdate", "true"); + } else { + document.documentElement.setAttribute("gkcanupdate", "false"); + } + }) + .catch(error => { + 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"; + 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) => { + // JSON is beautiful, isn't it? + let hasUpdate = false; + for (let run of workflow_runs.workflow_runs) { + if (hasUpdate) break; + + // 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. + document.documentElement.setAttribute("gkcanupdate", "false"); + break; + } + + // 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"}}) + .then((response) => response.json()) + .then((artifacts) => { + if (artifacts.total_count > 0) { + // We have a build, we can update. + document.documentElement.setAttribute("gkcanupdate", "true"); + hasUpdate = 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."