Skip to content

Commit

Permalink
CI: Prepare release 'v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterDiscord CI authored and BetterDiscord CI committed May 15, 2023
2 parents 3cd90da + cd4e601 commit 8b0877f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "BetterDiscord Installer",
"description": "A simple standalone program which automates the installation, removal and maintenance of BetterDiscord.",
"author": "BetterDiscord",
"version": "1.2.1",
"version": "1.3.0",
"license": "MIT",
"scripts": {
"dev": "electron-webpack dev",
Expand Down
76 changes: 59 additions & 17 deletions src/renderer/actions/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,77 @@ async function makeDirectories(...folders) {

const getJSON = phin.defaults({method: "GET", parse: "json", followRedirects: true, headers: {"User-Agent": "BetterDiscord/Installer"}});
const downloadFile = phin.defaults({method: "GET", followRedirects: true, headers: {"User-Agent": "BetterDiscord/Installer", "Accept": "application/octet-stream"}});
const asarPath = path.join(bdDataFolder, "betterdiscord.asar");
async function downloadAsar() {
try {
const response = await downloadFile("https://betterdiscord.app/Download/betterdiscord.asar")
const bdVersion = response.headers["x-bd-version"];
if (200 <= response.statusCode && response.statusCode < 300) {
log(`✅ Downloaded BetterDiscord version ${bdVersion} from the official website`);
return response.body;
}
throw new Error(`Status code did not indicate success: ${response.statusCode}`);
}
catch (error) {
log(`❌ Failed to download package from the official website`);
log(`❌ ${error.message}`);
log(`Falling back to GitHub...`);
}
let assetUrl;
let bdVersion;
try {
const response = await getJSON(RELEASE_API);
const releases = response.body;
const asset = releases && releases.length && releases[0].assets && releases[0].assets.find(a => a.name.toLowerCase() === "betterdiscord.asar");
const assetUrl = asset && asset.url;
assetUrl = asset && asset.url;
bdVersion = asset && releases[0].tag_name;
if (!assetUrl) {
let errMessage = "Could not get the asset url";
if (!asset) errMessage = "Could not get asset object";
if (!releases) errMessage = "Could not get response body";
if (!response) errMessage = "Could not get any response";
throw new Error(errMessage);
}
try {
const resp = await downloadFile(assetUrl);
const originalFs = require("original-fs").promises; // because electron doesn't like when I write asar files
await originalFs.writeFile(asarPath, resp.body);
}
catch (error) {
log(`❌ Failed to download package from ${assetUrl}`);
log(`❌ ${error.message}`);
return error;
}
}
catch (err) {
catch (error) {
log(`❌ Failed to get asset url from ${RELEASE_API}`);
log(`❌ ${err.message}`);
return err;
log(`❌ ${error.message}`);
throw error;
}
try {
const response = await downloadFile(assetUrl);
if (200 <= response.statusCode && response.statusCode < 300) {
log(`✅ Downloaded BetterDiscord version ${bdVersion} from GitHub`);
return response.body;
}
throw new Error(`Status code did not indicate success: ${response.statusCode}`);
}
catch (error) {
log(`❌ Failed to download package from ${assetUrl}`);
log(`❌ ${error.message}`);
throw error;
}
}

const asarPath = path.join(bdDataFolder, "betterdiscord.asar");
async function installAsar(fileContent) {
try {
const originalFs = require("original-fs").promises; // because electron doesn't like writing asar files
await originalFs.writeFile(asarPath, fileContent);
}
catch (error) {
log(`❌ Failed to write package to disk: ${asarPath}`);
log(`❌ ${error.message}`);
throw error;
}
}

async function downloadAndInstallAsar() {
try {
const fileContent = await downloadAsar();
await installAsar(fileContent);
}
catch (error) {
return error;
}
}

Expand Down Expand Up @@ -117,7 +159,7 @@ export default async function(config) {


lognewline("Downloading asar file");
const downloadErr = await downloadAsar();
const downloadErr = await downloadAndInstallAsar();
if (downloadErr) return fail();
log("✅ Package downloaded");
progress.set(DOWNLOAD_PACKAGE_PROGRESS);
Expand All @@ -138,4 +180,4 @@ export default async function(config) {


succeed();
};
};
8 changes: 4 additions & 4 deletions webpack.main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
output: {
hashFunction: "xxhash64"
}
module.exports = config => {
delete config.optimization.namedModules;
config.output.hashFunction = "xxhash64";
return config;
};
20 changes: 8 additions & 12 deletions webpack.renderer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
module.exports = {
module: {
rules: [
{
test: /\.(html|svelte)$/,
use: "svelte-loader"
}
]
},
output: {
hashFunction: "xxhash64"
}
module.exports = config => {
delete config.optimization.namedModules;
config.output.hashFunction = "xxhash64";
config.module.rules.push({
test: /\.(html|svelte)$/,
use: "svelte-loader"
});
return config;
};

0 comments on commit 8b0877f

Please sign in to comment.