Skip to content

Commit

Permalink
Store connection code
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 23, 2023
1 parent 5d4f771 commit a75905d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
33 changes: 33 additions & 0 deletions packages/ui/pages/settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@
</div>
</div>

<div class="transparent-900 m-10 mx-auto w-11/12 rounded-xl p-10 sm:m-3 sm:w-full">
<h1 class="mb-10">Remote connections</h1>

<div class="mx-auto flex flex-col items-center justify-center gap-5 rounded-2xl">
<div class="transparent-800 flex w-full flex-row items-center justify-between rounded-xl p-10 text-left">
<div>
<h2>Connection code</h2>
<h3>Use this code on the website (https://cores.levminer.com/settings).</h3>
</div>
<div class="ml-20 flex gap-3">
<div class="flex items-center justify-center space-x-3">
<input class="input" readonly value={$settings.connectionCode} />
<button
class="button"
on:click={() => {
navigator.clipboard.writeText($settings.connectionCode)
document.querySelector(".copy").innerHTML = "Copied"

setTimeout(() => {
document.querySelector(".copy").innerHTML = "Copy"
}, 1000)
}}
>
<Clipboard />
<span class="copy">Copy</span>
</button>
</div>
</div>
</div>
</div>
</div>

<div class="transparent-900 m-10 mx-auto w-11/12 rounded-xl p-10 sm:m-3 sm:w-full">
<h1 class="mb-10">About</h1>

Expand Down Expand Up @@ -131,6 +163,7 @@
import build from "../../../build.json"
import Select from "ui/components/select.svelte"
import Toggle from "ui/components/toggle.svelte"
import { Clipboard } from "lucide-svelte"
let message = `Cores: ${$hardwareInfo.system.os.app} \n\nRuntime: ${$hardwareInfo.system.os.runtime} \nChromium: ${
$hardwareInfo.system.os.webView
Expand Down
14 changes: 12 additions & 2 deletions packages/ui/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const defaultSettings: LibSettings = {
interval: 2,
minimizeToTray: true,
launchOnStartup: false,
connectionCode: `crs_${crypto.randomUUID().replaceAll("-", "")}`,
}

// Create store
export const settings = writable<LibSettings>(sessionStorage.settings ? JSON.parse(sessionStorage.settings) : defaultSettings)
export const settings = writable<LibSettings>(localStorage.settings ? JSON.parse(localStorage.settings) : defaultSettings)
settings.update((settings) => {
return {
...settings,
Expand All @@ -17,11 +18,20 @@ settings.update((settings) => {

// Listen for store events
settings.subscribe((data) => {
let prev: LibSettings = localStorage.settings ? JSON.parse(localStorage.settings) : defaultSettings
console.log("Settings changed: ", data)

data.mode = import.meta.env.VITE_CORES_MODE

sessionStorage.setItem("settings", JSON.stringify(data))
if (!data.connectionCode) {
if (!prev.connectionCode) {
data.connectionCode = `crs_${crypto.randomUUID().replaceAll("-", "")}`
} else {
data.connectionCode = prev.connectionCode
}
}

localStorage.setItem("settings", JSON.stringify(data))
})

export const getSettings = (): LibSettings => {
Expand Down

0 comments on commit a75905d

Please sign in to comment.