diff options
author | Nuckyz <61953774+Nuckyz@users.noreply.github.com> | 2023-03-01 01:26:13 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-01 05:26:13 +0100 |
commit | faa90eccd363b635b84be2162376645d6a83ad55 (patch) | |
tree | 01473b58f52a54c2dc08234a51a20f0069487981 /src/utils | |
parent | c91b0df6071639471cd41b481e7188259a3c1159 (diff) | |
download | Vencord-faa90eccd363b635b84be2162376645d6a83ad55.tar.gz Vencord-faa90eccd363b635b84be2162376645d6a83ad55.tar.bz2 Vencord-faa90eccd363b635b84be2162376645d6a83ad55.zip |
feat: Crash Handler (#531)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/modal.tsx | 8 | ||||
-rw-r--r-- | src/utils/types.ts | 4 | ||||
-rw-r--r-- | src/utils/updater.ts | 22 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index 3174cac..35aaaf8 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -117,6 +117,7 @@ const ModalAPI = mapMangledModuleLazy("onCloseRequest:null!=", { openModal: filters.byCode("onCloseRequest:null!="), closeModal: filters.byCode("onCloseCallback&&"), openModalLazy: m => m?.length === 1 && filters.byCode(".apply(this,arguments)")(m), + closeAllModals: filters.byCode(".value.key,") }); /** @@ -142,3 +143,10 @@ export function openModal(render: RenderFunction, options?: ModalOptions, contex export function closeModal(modalKey: string, contextKey?: string): void { return ModalAPI.closeModal(modalKey, contextKey); } + +/** + * Close all open modals + */ +export function closeAllModals(): void { + return ModalAPI.closeAllModals(); +} diff --git a/src/utils/types.ts b/src/utils/types.ts index 24915a6..96aa4ab 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -76,6 +76,10 @@ export interface PluginDef { */ required?: boolean; /** + * Whether this plugin should be enabled by default, but can be disabled + */ + enabledByDefault?: boolean; + /** * Set this if your plugin only works on Browser or Desktop, not both */ target?: "WEB" | "DESKTOP" | "BOTH"; diff --git a/src/utils/updater.ts b/src/utils/updater.ts index 9fdec47..e13f5cf 100644 --- a/src/utils/updater.ts +++ b/src/utils/updater.ts @@ -77,3 +77,25 @@ export async function rebuild() { return oldHashes["patcher.js"] !== newHashes["patcher.js"] || oldHashes["preload.js"] !== newHashes["preload.js"]; } + +export async function maybePromptToUpdate(confirmMessage: string, checkForDev = false) { + if (IS_WEB) return; + if (checkForDev && IS_DEV) return; + + try { + const isOutdated = await checkForUpdates(); + if (isOutdated) { + const wantsUpdate = confirm(confirmMessage); + if (wantsUpdate && isNewer) return alert("Your local copy has more recent commits. Please stash or reset them."); + if (wantsUpdate) { + await update(); + const needFullRestart = await rebuild(); + if (needFullRestart) DiscordNative.app.relaunch(); + else location.reload(); + } + } + } catch (err) { + UpdateLogger.error(err); + alert("That also failed :( Try updating or re-installing with the installer!"); + } +} |