Skip to content

Commit

Permalink
Allow release checkers to find bridge version in earlier releases
Browse files Browse the repository at this point in the history
  • Loading branch information
hensm committed Sep 13, 2020
1 parent c656d02 commit b7d741d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 57 deletions.
110 changes: 57 additions & 53 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,70 +80,74 @@ switch (navigator.platform) {
}


function populateAppListApp (element, fileUrl, fileName, fileSize) {
function populateAppListApp (element, fileUrl, fileName, fileSize, version) {
element.href = fileUrl;
element.title = `${fileName} (${fileSize})`;
element.dataset.fileSize = fileSize;
element.dataset.version = version;
element.removeAttribute("disabled");
}


const ENDPOINT_URL = "https://api.github.com/repos/hensm/fx_cast/releases/latest";
const ENDPOINT_URL = "https://api.github.com/repos/hensm/fx_cast/releases";

fetch(ENDPOINT_URL)
.then(res => res.json())
.then(onResponse)
.catch(onError);

function onResponse (res) {
for (const asset of res.assets) {
const formattedSize = formatSize(asset.size);

const REGEX_EXT = /.*\.(.*)$/;
const REGEX_ARCH = /.*(x(?:86|64))\..*$/;

switch (asset.name.match(REGEX_EXT).pop()) {
case "xpi":
downloadExtBtn.href = asset.browser_download_url;
downloadExtBtn.title = `${asset.name} (${formattedSize})`;
downloadExtBtn.dataset.version = res.tag_name;
downloadExtBtn.removeAttribute("disabled");
break;


case "exe":
switch (asset.name.match(REGEX_ARCH).pop()) {
case "x86":
populateAppListApp(
appListWin32Btn, asset.browser_download_url
, asset.name, formattedSize);
break;
case "x64":
populateAppListApp(
appListWin64Btn, asset.browser_download_url
, asset.name, formattedSize);
break;
}

break;

case "pkg":
populateAppListApp(
appListMacBtn, asset.browser_download_url
, asset.name, formattedSize);
break;

case "deb":
populateAppListApp(
appListDebBtn, asset.browser_download_url
, asset.name, formattedSize);
break;

case "rpm":
populateAppListApp(
appListRpmBtn, asset.browser_download_url
, asset.name, formattedSize);
break;
for (const release of res.reverse()) {
for (const asset of release.assets) {
const formattedSize = formatSize(asset.size);
const { tag_name } = release;

const REGEX_EXT = /.*\.(.*)$/;
const REGEX_ARCH = /.*(x(?:86|64))\..*$/;

switch (asset.name.match(REGEX_EXT).pop()) {
case "xpi":
downloadExtBtn.href = asset.browser_download_url;
downloadExtBtn.title = `${asset.name} (${formattedSize})`;
downloadExtBtn.dataset.version = tag_name;
downloadExtBtn.removeAttribute("disabled");
break;


case "exe":
switch (asset.name.match(REGEX_ARCH).pop()) {
case "x86":
populateAppListApp(
appListWin32Btn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
break;
case "x64":
populateAppListApp(
appListWin64Btn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
break;
}

break;

case "pkg":
populateAppListApp(
appListMacBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
break;

case "deb":
populateAppListApp(
appListDebBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
break;

case "rpm":
populateAppListApp(
appListRpmBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
break;
}
}
}

Expand All @@ -152,12 +156,12 @@ function onResponse (res) {
case "win":
downloadAppBtn.href = appListWin64Btn.href;
downloadAppBtn.title = appListWin64Btn.title;
downloadAppBtn.dataset.version = res.tag_name;
downloadAppBtn.dataset.version = appListWin64Btn.dataset.version;
break;
case "mac":
downloadAppBtn.href = appListMacBtn.href;
downloadAppBtn.title = appListMacBtn.title;
downloadAppBtn.dataset.version = res.tag_name;
downloadAppBtn.dataset.version = appListMacBtn.dataset.version;
break;

default: {
Expand All @@ -170,7 +174,7 @@ function onResponse (res) {
}

function onError (err) {
console.error("Failed to fetch download links");
console.error("Failed to fetch download links", err);
}


Expand Down
27 changes: 23 additions & 4 deletions ext/src/ui/options/Bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
}));
}, 500);

fetch("https://api.github.com/repos/hensm/fx_cast/releases/latest")
fetch("https://api.github.com/repos/hensm/fx_cast/releases")
.then(res => {
window.clearTimeout(timeout);
return res.json();
Expand All @@ -250,11 +250,30 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
}

private async onCheckUpdatesResponse (res: any) {
const isUpdateAvailable = !this.props.info ||
semver.lt(this.props.info.version, res.tag_name);
let latestBridgeRelease;
for (const release of res) {
if (release.assets.find((asset: any) =>
asset.content_type !== "application/x-xpinstall")) {
latestBridgeRelease = release;
break;
}
}

if (!latestBridgeRelease) {
this.setState({
isCheckingUpdates: false
, wasErrorCheckingUpdates: true
, updateStatus: _("optionsBridgeUpdateStatusError")
});

return;
}

const isUpdateAvailable = !this.props.info || semver.lt(
this.props.info.version, latestBridgeRelease.tag_name);

if (isUpdateAvailable) {
this.updateData = res;
this.updateData = latestBridgeRelease;
}

this.setState({
Expand Down

0 comments on commit b7d741d

Please sign in to comment.