From b587fd422d60f0d939dbf3e7aec70eee0ced6d75 Mon Sep 17 00:00:00 2001 From: Zerebos Date: Mon, 27 Mar 2023 09:30:56 -0400 Subject: [PATCH 1/2] Fix webpack builds for modern versions (#333) --- webpack.main.js | 8 ++++---- webpack.renderer.js | 20 ++++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/webpack.main.js b/webpack.main.js index 216a7c8c..dde70b23 100644 --- a/webpack.main.js +++ b/webpack.main.js @@ -1,5 +1,5 @@ -module.exports = { - output: { - hashFunction: "xxhash64" - } +module.exports = config => { + delete config.optimization.namedModules; + config.output.hashFunction = "xxhash64"; + return config; }; \ No newline at end of file diff --git a/webpack.renderer.js b/webpack.renderer.js index b0d35619..9f6290b2 100644 --- a/webpack.renderer.js +++ b/webpack.renderer.js @@ -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; }; \ No newline at end of file From cd4e601038f5c27ea4acc64867e0e23e1eecabc1 Mon Sep 17 00:00:00 2001 From: square Date: Sun, 14 May 2023 23:33:31 +0200 Subject: [PATCH 2/2] implement download from site (#347) --- src/renderer/actions/install.js | 76 +++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/src/renderer/actions/install.js b/src/renderer/actions/install.js index a2c4096f..16187bb0 100644 --- a/src/renderer/actions/install.js +++ b/src/renderer/actions/install.js @@ -49,13 +49,29 @@ 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"; @@ -63,21 +79,47 @@ async function downloadAsar() { 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; } } @@ -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); @@ -138,4 +180,4 @@ export default async function(config) { succeed(); -}; \ No newline at end of file +};