From 4745f63973f29b8e127e91bb651c5ec3952acf05 Mon Sep 17 00:00:00 2001 From: Cattn Date: Sun, 22 Sep 2024 00:06:03 -0400 Subject: [PATCH] 2 New Settings + Updated SDK --- src/internal/Settings.tsx | 31 +++++++++++++++++++++++++++++++ src/lib/bunker.ts | 13 ++++++++++++- src/lib/sdk.ts | 17 +++++++++++++++++ src/root.tsx | 3 ++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/internal/Settings.tsx b/src/internal/Settings.tsx index 309bba1..e342b79 100644 --- a/src/internal/Settings.tsx +++ b/src/internal/Settings.tsx @@ -14,6 +14,8 @@ const Settings: Plugin = { page({ sdk }) { const [pluginLocation, setPluginLocation] = useState(sdk.config.get("storageLocation")); const [autoUpdate, setAutoUpdate] = useState(sdk.config.get("autoUpdate") === "true"); + const [notifications, setNotifications] = useState(sdk.config.get("notifications") === "true"); + const [pluginNotifs, setPluginNotifs] = useState(sdk.config.get("pluginNotifs") === "true"); function setStorageLocation(checked: boolean) { if (checked) { sdk.config.set("storageLocation", "internal") @@ -34,6 +36,27 @@ const Settings: Plugin = { } } + function notificationSet(checked: boolean) { + if (checked) { + sdk.config.set("notifications", "true") + setNotifications(true); + } else { + sdk.config.set("notifications", "false") + setNotifications(false); + } + } + + function pluginNotifSet(checked: boolean) { + if (checked) { + sdk.config.set("pluginNotifs", "true") + setPluginNotifs(true); + } else { + sdk.config.set("pluginNotifs", "false") + setPluginNotifs(false); + } + } + + return (

Settings

@@ -46,6 +69,14 @@ const Settings: Plugin = { autoUpdateSet(checked)} />
+
+ notificationSet(checked)} /> + +
+
+ pluginNotifSet(checked)} /> + +
) diff --git a/src/lib/bunker.ts b/src/lib/bunker.ts index 139be9a..992a0de 100644 --- a/src/lib/bunker.ts +++ b/src/lib/bunker.ts @@ -2,7 +2,8 @@ import { SDK } from "./sdk" let version: string = "v0.2.4" let pluginLocation: string = "internal" let autoUpdate: string = "true" - +let notifications: string = "false" // True = disable all notifications, false = enable all +let pluginNotifs: string = "true" // True = enabled plugin notifications, false = disabled plugin notifications let Settings = new SDK("bunker.settings") @@ -12,9 +13,19 @@ pluginLocation = Settings.config.get("storageLocation") || pluginLocation // @ts-ignore autoUpdate = Settings.config.get("autoUpdate") || autoUpdate; +// @ts-ignore +notifications = Settings.config.get("notifications") || notifications; + +// @ts-ignore +pluginNotifs = Settings.config.get("pluginNotifs") || pluginNotifs; + const bunker = { version, pluginLocation, autoUpdate, + notifications, + pluginNotifs } export default bunker + + diff --git a/src/lib/sdk.ts b/src/lib/sdk.ts index 27a82b7..16acb64 100644 --- a/src/lib/sdk.ts +++ b/src/lib/sdk.ts @@ -1,4 +1,5 @@ import { $plugins } from "./plugins" +import { toast } from "sonner" // interface Setting { // pluginId: string @@ -40,4 +41,20 @@ export class SDK { return plugins.some((plugin) => plugin.id === pluginId) }, } + + public notification = { + push: (message: string, type: string) => { + if (this.config.get("notifications") === "false") return + console.log(`[${this.id}] Pushing notification: ${message}`) + if (type === "error") { + toast.error(message) + } else if (type === "success") { + toast.success(message) + } else if (type === "info") { + toast.info(message) + } else { + toast(message) + } + } + } } diff --git a/src/root.tsx b/src/root.tsx index d71d54d..d9980f3 100644 --- a/src/root.tsx +++ b/src/root.tsx @@ -10,6 +10,7 @@ import { useEffect } from "react" import { registerDefaultPlugins } from "./lib/plugins" import PluginRouter from "./routes/pluginrouter" import { createRoot } from "react-dom/client" +import bunker from "./lib/bunker" import "./styles.css" @@ -24,7 +25,7 @@ export default function App() {
- + {bunker.notifications === "false" && }
} path="/" />