From a75905d584f74c31ccf92d076958028a98e8e4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rik=20Levente?= Date: Sat, 23 Dec 2023 19:21:03 +0100 Subject: [PATCH] Store connection code --- packages/ui/pages/settings.svelte | 33 +++++++++++++++++++++++++++++++ packages/ui/stores/settings.ts | 14 +++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/ui/pages/settings.svelte b/packages/ui/pages/settings.svelte index 757737a..e39a221 100644 --- a/packages/ui/pages/settings.svelte +++ b/packages/ui/pages/settings.svelte @@ -34,6 +34,38 @@ +
+

Remote connections

+ +
+
+
+

Connection code

+

Use this code on the website (https://cores.levminer.com/settings).

+
+
+
+ + +
+
+
+
+
+

About

@@ -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 diff --git a/packages/ui/stores/settings.ts b/packages/ui/stores/settings.ts index 62bb27d..c4bb461 100644 --- a/packages/ui/stores/settings.ts +++ b/packages/ui/stores/settings.ts @@ -4,10 +4,11 @@ const defaultSettings: LibSettings = { interval: 2, minimizeToTray: true, launchOnStartup: false, + connectionCode: `crs_${crypto.randomUUID().replaceAll("-", "")}`, } // Create store -export const settings = writable(sessionStorage.settings ? JSON.parse(sessionStorage.settings) : defaultSettings) +export const settings = writable(localStorage.settings ? JSON.parse(localStorage.settings) : defaultSettings) settings.update((settings) => { return { ...settings, @@ -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 => {