make copyWithToast use error style on error

This commit is contained in:
sadan 2025-01-26 22:58:42 -05:00
parent 28efdef3a0
commit 1693273f8b
No known key found for this signature in database

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Clipboard, Toasts } from "@webpack/common";
import { Clipboard, ToastData, Toasts } from "@webpack/common";
import { DevsById } from "./constants";
@ -36,15 +36,19 @@ export function sleep(ms: number): Promise<void> {
}
export function copyWithToast(text: string, toastMessage = "Copied to clipboard!") {
const opts: Pick<ToastData, "type" | "message"> = {
message: toastMessage,
type: Toasts.Type.SUCCESS
};
if (Clipboard.SUPPORTS_COPY) {
Clipboard.copy(text);
} else {
toastMessage = "Your browser does not support copying to clipboard";
opts.message = "Your browser does not support copying to clipboard";
opts.type = Toasts.Type.FAILURE;
}
Toasts.show({
message: toastMessage,
id: Toasts.genId(),
type: Toasts.Type.SUCCESS
...opts
});
}