summaryrefslogtreecommitdiff
path: root/src/utils/toastUtils.ts
blob: dce0a5952a5fa822230d213f4110189bca537b9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * Centralized toast notification utilities
 * Provides consistent success/error messaging patterns
 */

import { toaster } from "@decky/api";

export interface ToastOptions {
  title: string;
  body: string;
}

/**
 * Show a success toast notification
 */
export function showSuccessToast(title: string, body: string): void {
  toaster.toast({
    title,
    body
  });
}

/**
 * Show an error toast notification
 */
export function showErrorToast(title: string, body: string): void {
  toaster.toast({
    title,
    body
  });
}

/**
 * Standard success messages for common operations
 */
export const ToastMessages = {
  INSTALL_SUCCESS: {
    title: "Installation Complete",
    body: "lsfg-vk has been installed successfully"
  },
  INSTALL_ERROR: {
    title: "Installation Failed",
    body: "Unknown error occurred"
  },
  UNINSTALL_SUCCESS: {
    title: "Uninstallation Complete", 
    body: "lsfg-vk has been uninstalled successfully"
  },
  UNINSTALL_ERROR: {
    title: "Uninstallation Failed",
    body: "Unknown error occurred"
  },
  CONFIG_UPDATE_ERROR: {
    title: "Update Failed",
    body: "Failed to update configuration"
  },
  CLIPBOARD_SUCCESS: {
    title: "Copied to Clipboard!",
    body: "Launch option ready to paste"
  },
  CLIPBOARD_ERROR: {
    title: "Copy Failed",
    body: "Unable to copy to clipboard"
  }
} as const;

/**
 * Show a toast with dynamic error message
 */
export function showErrorToastWithMessage(title: string, error: unknown): void {
  const errorMessage = error instanceof Error ? error.message : String(error);
  showErrorToast(title, errorMessage);
}

/**
 * Show installation success toast
 */
export function showInstallSuccessToast(): void {
  showSuccessToast(ToastMessages.INSTALL_SUCCESS.title, ToastMessages.INSTALL_SUCCESS.body);
}

/**
 * Show installation error toast
 */
export function showInstallErrorToast(error?: string): void {
  showErrorToast(ToastMessages.INSTALL_ERROR.title, error || ToastMessages.INSTALL_ERROR.body);
}

/**
 * Show uninstallation success toast
 */
export function showUninstallSuccessToast(): void {
  showSuccessToast(ToastMessages.UNINSTALL_SUCCESS.title, ToastMessages.UNINSTALL_SUCCESS.body);
}

/**
 * Show uninstallation error toast
 */
export function showUninstallErrorToast(error?: string): void {
  showErrorToast(ToastMessages.UNINSTALL_ERROR.title, error || ToastMessages.UNINSTALL_ERROR.body);
}

/**
 * Show clipboard success toast
 */
export function showClipboardSuccessToast(): void {
  showSuccessToast(ToastMessages.CLIPBOARD_SUCCESS.title, ToastMessages.CLIPBOARD_SUCCESS.body);
}

/**
 * Show clipboard error toast
 */
export function showClipboardErrorToast(): void {
  showErrorToast(ToastMessages.CLIPBOARD_ERROR.title, ToastMessages.CLIPBOARD_ERROR.body);
}