mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-04 18:53:26 +08:00
refactor: use try/catch
This commit is contained in:
parent
3f2cfca361
commit
3e8fbb7d4b
1 changed files with 16 additions and 21 deletions
|
@ -52,27 +52,22 @@ async function generateUrl(): Promise<string> {
|
|||
async function copy(): Promise<void> {
|
||||
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, {
|
||||
|
|
Loading…
Reference in a new issue