Skip to content

Commit

Permalink
Storage Toggle / SDK Additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cattn committed Sep 20, 2024
1 parent 9fb435a commit 878cc06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/internal/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Plugin } from "@/lib/types"
import bunker from "@/lib/bunker"
import { Settings2 } from "lucide-react"
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"

import { useEffect, useState } from "react"
import { useState } from "react"

const Settings: Plugin = {
name: "Settings",
Expand All @@ -13,19 +12,23 @@ const Settings: Plugin = {
icon: Settings2,

page({ sdk }) {
const [pluginLocation, setPluginLocation] = useState(sdk.config.get("storageLocation"));
function setStorageLocation(checked: boolean) {
if (checked) {
sdk.config.set("pluginLocation", "internal")
sdk.config.set("storageLocation", "internal")
setPluginLocation("internal");
} else {
sdk.config.set("pluginLocation", "external")
sdk.config.set("storageLocation", "external")
setPluginLocation("external");
}
}

return (
<div className="flex flex-col items-center w-full pt-16">
<h1 className="font-bold text-5xl">Settings </h1>

<div className="flex flex-wrap justify-center gap-4 mt-8">
<Switch id="storage-location" onCheckedChange={(checked) => setStorageLocation(checked)} />
<Switch id="storage-location" checked={pluginLocation === "internal"} onCheckedChange={(checked) => setStorageLocation(checked)} />
<Label className="text-md" htmlFor="storage-location">Store Plugins Internally</Label>
</div>
</div>
Expand All @@ -34,7 +37,7 @@ const Settings: Plugin = {


onReady() {
console.log("Status")
console.log("Settings")
},
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib/bunker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const version = "v0.2.3"
const pluginLocation = "internal"
import { SDK } from "./sdk"
let version = "v0.2.3"
let pluginLocation = "internal"
let Settings = new SDK("bunker.settings")

pluginLocation = Settings.config.get("storageLocation") || pluginLocation

const bunker = {
version,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ export class SDK {

public config = {
get: (key: string) => {
console.log(`[${this.id}] Getting config value for key ${key}`)
const value = localStorage.getItem(`${this.id}.${key}`)
if (value) {
return value
}
},
set: (key: string, value: string) => {
console.log(`[${this.id}] Setting config value for key ${key} to ${value}`)
localStorage.setItem(`${this.id}.${key}`, value)
return value
},
}

public plugins = {
isInstalled: (pluginId: string) => {
console.log(`[${this.id}] Checking if plugin ${pluginId} is installed`)
const plugins = $plugins.get()
return plugins.some((plugin) => plugin.id === pluginId)
},
Expand Down

0 comments on commit 878cc06

Please sign in to comment.