diff --git a/injector/src/modules/csp.js b/injector/src/modules/csp.js index 6fc06640..e3c4b63d 100644 --- a/injector/src/modules/csp.js +++ b/injector/src/modules/csp.js @@ -7,31 +7,51 @@ const whitelist = { "https://cdnjs.cloudflare.com" // Used for Monaco ], - // Discord includes nothing we need - connect: [ - "https://api.github.com", - ], - // Discord includes unsafe-inline already style: [ "https://*.github.io", "https://cdnjs.cloudflare.com", // Used for Monaco "https://fonts.googleapis.com", + "https://fonts.cdnfonts.com", + "https://cdn.statically.io", + "https://rawgit.com", + "https://raw.githack.com", + "https://rsms.me", + "https://cdn.jsdelivr.net", ], - // Discord includes the other google font url + // Discord includes fonts.gstatic.com font: [ "data:", "https://*.github.io", "https://cdnjs.cloudflare.com", "https://fonts.googleapis.com", + "https://raw.githack.com", + "https://cdn.jsdelivr.net", ], - // Discord includes several sources already including imgur + // Discord includes several sources already including imgur and data: img: [ "https://*.github.io", "https://ik.imagekit.io", "https://source.unsplash.com", + "https://raw.githubusercontent.com", + "https://svgur.com", + "https://i.ibb.co", + "https://rawgit.com", + "https://bowmanfox.xyz", + "https://paz.pw", + "https://adx74.fr", + "https://media.tenor.com", // included by discord already + "https://upload.wikimedia.org", + "https://svgrepo.com", + "https://ch3rry.red", + "https://teamcofh.com", + "https://icon-library.net", + "https://images.pexels.com", + "https://user-images.githubusercontent.com", + "https://emoji.gg", + "https://cdn-icons-png.flaticon.com", ], // Discord does not include this normally diff --git a/renderer/src/modules/updater.js b/renderer/src/modules/updater.js index b5e3b12b..2041be68 100644 --- a/renderer/src/modules/updater.js +++ b/renderer/src/modules/updater.js @@ -76,31 +76,45 @@ export class CoreUpdater { } static async checkForUpdate(showNotice = true) { - const resp = await fetch(`https://api.github.com/repos/BetterDiscord/BetterDiscord/releases/latest`,{ - method: "GET", - headers: { - "Accept": "application/json", - "Content-Type": "application/json", - "User-Agent": "BetterDiscord Updater" - } - }); + try { + const buffer = await new Promise((resolve, reject) => { + request({ + url: "https://api.github.com/repos/BetterDiscord/BetterDiscord/releases/latest", + method: "get", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "User-Agent": "BetterDiscord Updater" + } + }, (err, resp, body) => { + if (err || resp.statusCode != 200) return reject(err || `${resp.statusCode} ${resp.statusMessage}`); + return resolve(body); + }); + }); - const data = await resp.json(); - this.apiData = data; - const remoteVersion = data.tag_name.startsWith("v") ? data.tag_name.slice(1) : data.tag_name; - this.hasUpdate = remoteVersion > Config.version; - this.remoteVersion = remoteVersion; - if (!this.hasUpdate || !showNotice) return; + const data = JSON.parse(buffer.toString()); + this.apiData = data; + const remoteVersion = data.tag_name.startsWith("v") ? data.tag_name.slice(1) : data.tag_name; + this.hasUpdate = remoteVersion > Config.version; + this.remoteVersion = remoteVersion; + if (!this.hasUpdate || !showNotice) return; - const close = Notices.info(Strings.Updater.updateAvailable.format({version: remoteVersion}), { - buttons: [{ - label: Strings.Notices.moreInfo, - onClick: () => { - close(); - UserSettingsWindow?.open?.("updates"); - } - }] - }); + const close = Notices.info(Strings.Updater.updateAvailable.format({version: remoteVersion}), { + buttons: [{ + label: Strings.Notices.moreInfo, + onClick: () => { + close(); + UserSettingsWindow?.open?.("updates"); + } + }] + }); + } + catch (err) { + Logger.stacktrace("Updater", "Failed to check update", err); + Modals.showConfirmationModal(Strings.Updater.updateFailed, Strings.Updater.updateFailedMessage, { + cancelText: null + }); + } } static async update() {