From 72574abb0e0b3e4f514fd4770c31e3451c1c6ab7 Mon Sep 17 00:00:00 2001 From: _Lighty_ Date: Wed, 8 Apr 2020 12:44:02 +0200 Subject: [PATCH] CR v0.1.6 --- Plugins/CrashRecovery/CHANGELOG.md | 3 + Plugins/CrashRecovery/CrashRecovery.plugin.js | 65 ++++++------------- Plugins/CrashRecovery/README.md | 3 +- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/Plugins/CrashRecovery/CHANGELOG.md b/Plugins/CrashRecovery/CHANGELOG.md index 97c9a12..fe6b59a 100644 --- a/Plugins/CrashRecovery/CHANGELOG.md +++ b/Plugins/CrashRecovery/CHANGELOG.md @@ -1,4 +1,7 @@ # [CrashRecovery](https://1lighty.github.io/BetterDiscordStuff/?plugin=CrashRecovery "CrashRecovery") Changelog +### 0.1.6 +- Removed usage of soon to be deprecated globals. + ### 0.1.5 - Fixed startup error in console diff --git a/Plugins/CrashRecovery/CrashRecovery.plugin.js b/Plugins/CrashRecovery/CrashRecovery.plugin.js index edd25ae..6d4d5a8 100644 --- a/Plugins/CrashRecovery/CrashRecovery.plugin.js +++ b/Plugins/CrashRecovery/CrashRecovery.plugin.js @@ -41,7 +41,7 @@ var CrashRecovery = (() => { twitter_username: '' } ], - version: '0.1.5', + version: '0.1.6', description: 'In the event that your Discord crashes, the plugin enables you to get Discord back to a working state, without needing to reload at all.', github: 'https://github.com/1Lighty', github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/CrashRecovery/CrashRecovery.plugin.js' @@ -50,7 +50,7 @@ var CrashRecovery = (() => { { title: 'misc changes', type: 'fixed', - items: ['Fixed startup error in console'] + items: ['Removed usage of soon to be deprecated globals.'] } ], defaultConfig: [ @@ -70,7 +70,7 @@ var CrashRecovery = (() => { const { React, Dispatcher, FlexChild: Flex, GuildStore } = DiscordModules; const DelayedCall = (WebpackModules.getByProps('DelayedCall') || {}).DelayedCall; - const ElectronDiscordModule = WebpackModules.getByProps('cleanupDisplaySleep'); + const ElectronDiscordModule = WebpackModules.getByProps('cleanupDisplaySleep') || { cleanupDisplaySleep: DiscordModules.DiscordConstants.NOOP }; return class CrashRecovery extends Plugin { constructor() { @@ -100,33 +100,13 @@ var CrashRecovery = (() => { this.attempts = 0; this.promises = { state: { cancelled: false } }; if (!DelayedCall) return this._startFailure('DelayedCall missing, plugin cannot function.'); + if (ElectronDiscordModule.cleanupDisplaySleep === DiscordModules.DiscordConstants.NOOP) XenoLib.Notifications.error(`[**${this.name}**] cleanupDisplaySleep is missing.`); delete this.onCrashRecoveredDelayedCall; this.onCrashRecoveredDelayedCall = new DelayedCall(1000, () => { XenoLib.Notifications.remove(this.notificationId); this.notificationId = null; if (this.disabledPlugins) XenoLib.Notifications.danger(`${this.disabledPlugins.map(e => e)} ${this.disabledPlugins.length > 1 ? 'have' : 'has'} been disabled to recover from the crash`, { timeout: 0 }); if (this.suspectedPlugin) XenoLib.Notifications.danger(`${this.suspectedPlugin} ${this.suspectedPlugin2 !== this.suspectedPlugin && this.suspectedPlugin2 ? 'or ' + this.suspectedPlugin2 : ''} is suspected of causing the crash.`, { timeout: 10000 }); - if (this.autoDisabledPlugins && this.autoDisabledPlugins.length) { - setTimeout(() => { - XenoLib.Notifications.danger(`${this.autoDisabledPlugins.length} ${this.autoDisabledPlugins.length > 1 ? 'plugins have' : 'plugin has'} been reenabled due to the crash disabling ${this.autoDisabledPlugins.length > 1 ? 'them' : 'it'}`, { timeout: 10000 }); - this.autoDisabledPlugins.forEach(({ name }) => { - try { - pluginModule.stopPlugin(name); - pluginCookie[name] = true; - pluginModule.startPlugin(name); - } catch (err) { - try { - pluginCookie[name] = false; - pluginModule.stopPlugin(name); - } catch (err) { - /* bruh idk */ - } - } - }); - pluginModule.savePluginData(); - this.autoDisabledPlugins = []; - }, 1000); - } this.disabledPlugins = null; this.suspectedPlugin = null; this.suspectedPlugin2 = null; @@ -138,13 +118,6 @@ var CrashRecovery = (() => { Logger.info('Corrected incorrectly placed containers'); }); this.patchAll(); - if (!document.querySelector(`.${XenoLib.getSingleClass('errorPage')}`)) - this.__safeClearTimeout = setTimeout(() => { - if (global.bdpluginErrors && global.bdpluginErrors.length) { - global.bdpluginErrors.splice(0, global.bdpluginErrors.length); - Logger.info('Cleared global.bdpluginErrors'); - } - }, 7500); } onStop() { this.promises.state.cancelled = true; @@ -166,8 +139,20 @@ var CrashRecovery = (() => { } if (onDispatchEventFound && /Object\.callback.*(?:\\|\/|VM\d+ )MessageLoggerV2\.plugin\.js/.test(match[i])) continue; if (pluginName === '0PluginLibrary' || pluginName === this.name) continue; - const bbdplugin = Object.values(bdplugins).find(m => m.filename.startsWith(pluginName)); + + let bbdplugin = null; + if (!BdApi.Plugins.get(pluginName)) { + /* + * go away Zack + */ + for (const path in require.cache) { + const module = require.cache[path]; + if (!module || !module.exports || !module.exports.plugin || module.exports.filename.indexOf(pluginName) !== 0) continue; + bbdplugin = module.exports; + } + } const name = (bbdplugin && bbdplugin.name) || pluginName; + bbdplugin = null; if (this.disabledPlugins && this.disabledPlugins.indexOf(name) !== -1) return { name: name }; plugins.push(name); } @@ -192,7 +177,6 @@ var CrashRecovery = (() => { handleCrash(_this, stack, isRender) { this.onCrashRecoveredDelayedCall.cancel(); - if (this.__safeClearTimeout) clearTimeout(this.__safeClearTimeout), (this.__safeClearTimeout = 0); if (!isRender) { _this.setState({ error: { stack } @@ -210,16 +194,6 @@ var CrashRecovery = (() => { this.cleanupDiscord(); if (responsiblePlugins) this.suspectedPlugin = responsiblePlugins.shift(); } - if (!this.attempts && !this.autoDisabledPlugins) { - setTimeout(() => { - this.autoDisabledPlugins = Utilities.deepclone(global.bdpluginErrors); - if (!this.autoDisabledPlugins || !this.autoDisabledPlugins.length) { - return; - } - this.suspectedPlugin2 = this.autoDisabledPlugins.shift().name; - global.bdpluginErrors.splice(0, global.bdpluginErrors.length); - }, 750); - } if (this.setStateTimeout) return; if (this.attempts >= 10 || ((this.settings.useThirdStep ? this.attempts >= 3 : this.attempts >= 2) && (!responsiblePlugins || !responsiblePlugins[0]))) { XenoLib.Notifications.update(this.notificationId, { content: 'Failed to recover from crash', loading: false }); @@ -231,7 +205,7 @@ var CrashRecovery = (() => { XenoLib.Notifications.update(this.notificationId, { content: `Failed, switching channels` }); } else if (this.attempts >= 2) { try { - pluginModule.disablePlugin(responsiblePlugins[0]); + BdApi.Plugins.disable(responsiblePlugins[0]); } catch (e) {} XenoLib.Notifications.update(this.notificationId, { content: `Failed, suspecting ${responsiblePlugins[0]} for recovery failure` }); if (!this.disabledPlugins) this.disabledPlugins = []; @@ -319,8 +293,7 @@ var CrashRecovery = (() => { this.disabledPlugins.length > 1 ? ' have' : ' has', ' been disabled in an attempt to recover' ) - : false, - global.bdpluginErrors && global.bdpluginErrors.length ? React.createElement('div', {}, global.bdpluginErrors.length, ' plugins have been disabled by BBD due to the crash') : null + : false ]; }); const ErrorBoundaryInstance = ReactTools.getOwnerInstance(document.querySelector(`.${XenoLib.getSingleClass('errorPage')}`) || document.querySelector('#app-mount > svg:first-of-type'), { include: ['ErrorBoundary'] }); diff --git a/Plugins/CrashRecovery/README.md b/Plugins/CrashRecovery/README.md index ccffa40..012a9c7 100644 --- a/Plugins/CrashRecovery/README.md +++ b/Plugins/CrashRecovery/README.md @@ -3,7 +3,6 @@ In the event that your Discord crashes, the plugin enables you to get Discord ba ### Features If your Discord crashes when you open it, it'll attempt to "uncrash" it, and disable any plugin that is preventing recovery. If it completels, it will tell you exactly what plugin may have caused the crash (if it can detect it). -If you had toasts enabled and plugins got disabled due to the crash, it will reenable them for you. If your Discord crashes out of random (maybe you clicked something?) it'll attempt to recover with the same steps as above. In the event that recovery fails, you still have some info on what plugin may have been responsible for the initial crash, and have a button alongside the reload button, to try to recover again, maybe after removing a plugin from your plugins folder. ### Preview @@ -11,7 +10,7 @@ Plugin start crash ![crash](https://i.imgur.com/Sb5BSX9.png) Unknown crash that may happen at random ![crash2](https://i.imgur.com/oICzvKB.png) -Startup crash + reenable auto disabled plugins due to crash +Startup crash ![startcrash](https://i.imgur.com/ZtkJG5N.png) ### Settings ##### Enable step 3