From 3e8fbb7d4b823651aa4a0385636cfd488d784587 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 12 Mar 2024 15:37:33 +0100 Subject: [PATCH] refactor: use try/catch --- frontend/src/ts/modals/share-custom-theme.ts | 37 +++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/frontend/src/ts/modals/share-custom-theme.ts b/frontend/src/ts/modals/share-custom-theme.ts index 67f5d3482..70b162549 100644 --- a/frontend/src/ts/modals/share-custom-theme.ts +++ b/frontend/src/ts/modals/share-custom-theme.ts @@ -52,27 +52,22 @@ async function generateUrl(): Promise { async function copy(): Promise { const url = await generateUrl(); - navigator.clipboard.writeText(url).then( - function () { - Notifications.add("URL Copied to clipboard", 1); - void modal.hide(); - }, - function (e) { - Notifications.add( - createErrorMessage(e, "Failed to copy to clipboard"), - -1 - ); - Notifications.add( - "Looks like we couldn't copy the link straight to your clipboard. Please copy it manually.", - 0, - { - duration: 5, - } - ); - void modal.hide(); - CustomThemePopup.show(url); - } - ); + try { + await navigator.clipboard.writeText(url); + Notifications.add("URL Copied to clipboard", 1); + void modal.hide(); + } catch (e) { + Notifications.add(createErrorMessage(e, "Failed to copy to clipboard"), -1); + Notifications.add( + "Looks like we couldn't copy the link straight to your clipboard. Please copy it manually.", + 0, + { + duration: 5, + } + ); + void modal.hide(); + CustomThemePopup.show(url); + } } const modal = new AnimatedModal("shareCustomThemeModal", "popups", undefined, {