Skip to content

Commit

Permalink
2 New Settings + Updated SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Cattn committed Sep 22, 2024
1 parent 6800a2d commit 4745f63
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/internal/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 (
<div className="flex flex-col items-center w-full pt-16">
<h1 className="font-bold text-5xl">Settings </h1>
Expand All @@ -46,6 +69,14 @@ const Settings: Plugin = {
<Switch id="auto-update" checked={autoUpdate} onCheckedChange={(checked) => autoUpdateSet(checked)} />
<Label className="text-md" htmlFor="auto-update">Auto Update</Label>
</div>
<div className="flex flex-row items-center gap-4 mt-2">
<Switch id="notifications" checked={notifications} onCheckedChange={(checked) => notificationSet(checked)} />
<Label className="text-md" htmlFor="notifications">Disable All Notifications</Label>
</div>
<div className="flex flex-row items-center gap-4 mt-2">
<Switch id="pluginNotif" checked={pluginNotifs} onCheckedChange={(checked) => pluginNotifSet(checked)} />
<Label className="text-md" htmlFor="pluginNotif">Disable Notifications from Plugins</Label>
</div>
</div>
</div>
)
Expand Down
13 changes: 12 additions & 1 deletion src/lib/bunker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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


17 changes: 17 additions & 0 deletions src/lib/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { $plugins } from "./plugins"
import { toast } from "sonner"

// interface Setting {
// pluginId: string
Expand Down Expand Up @@ -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)
}
}
}
}
3 changes: 2 additions & 1 deletion src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -24,7 +25,7 @@ export default function App() {
<div className="flex bg-zinc-900">
<HashRouter>
<Navbar />
<Toaster position="top-right" />
{bunker.notifications === "false" && <Toaster position="top-right" />}
<div className="w-[calc(100vw-4rem)] absolute right-0 top-0 h-screen">
<Routes>
<Route element={<Home />} path="/" />
Expand Down

0 comments on commit 4745f63

Please sign in to comment.