Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Reset data
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 18, 2022
1 parent 31d1ff5 commit a90dc37
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 100 deletions.
24 changes: 13 additions & 11 deletions interface/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { writable, get } from "svelte/store"

export const settings = writable(
localStorage.settings
? JSON.parse(localStorage.settings)
: {
security: {
requireAuthentication: null,
password: null,
key: null,
},
}
)
const defaultSettings: LibSettings = {
security: {
requireAuthentication: null,
password: null,
key: null,
},
}

export const settings = writable(localStorage.settings ? JSON.parse(localStorage.settings) : defaultSettings)

settings.subscribe((data) => {
console.log("Settings changed: ", data)
Expand All @@ -25,3 +23,7 @@ export const getSettings = (): LibSettings => {
export const setSettings = (newSettings: LibSettings) => {
settings.set(newSettings)
}

export const resetSettings = () => {
settings.set(defaultSettings)
}
18 changes: 10 additions & 8 deletions interface/stores/state.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { writable, get } from "svelte/store"

export const state = writable(
sessionStorage.state
? JSON.parse(sessionStorage.state)
: {
authenticated: false,
importData: null,
}
)
const defaultState = {
authenticated: false,
importData: null,
}

export const state = writable(sessionStorage.state ? JSON.parse(sessionStorage.state) : defaultState)

state.subscribe((data) => {
console.log("State changed: ", data)
Expand All @@ -22,3 +20,7 @@ export const getState = (): LibState => {
export const setState = (newState: LibState) => {
state.set(newState)
}

export const resetState = () => {
state.set(defaultState)
}
21 changes: 20 additions & 1 deletion interface/windows/settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
<h3>Clear password, 2FA codes and all other settings. Be careful.</h3>
</div>
<div class="ml-20 flex gap-3">
<button class="button">
<button class="button" on:click={clearData}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<!-- svelte-ignore component-name-lowercase -->
<path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
Clear data
Expand Down Expand Up @@ -97,10 +98,28 @@

<script>
import Dropdown from "../components/dropdown.svelte"
import { navigate } from "../libraries/navigate"
import { resetState } from "../stores/state"
import { resetSettings } from "../stores/settings"
import Toggle from "../components/toggle.svelte"
import { fs, path } from "@tauri-apps/api"
const handleMessage = (event) => {
console.log(event.detail.value)
}
const clearData = async () => {
localStorage.clear()
sessionStorage.clear()
const folderPath = await path.join(await path.configDir(), "Levminer", "Authme 4")
await fs.removeDir(folderPath, { recursive: true })
resetState()
resetSettings()
navigate("/")
location.reload()
}
</script>
158 changes: 79 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"@tauri-apps/api": "^1.0.2",
"@tauri-apps/cli": "^1.0.3",
"@tauri-apps/cli": "^1.0.4",
"@types/node": "^18.0.3",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
Expand Down

0 comments on commit a90dc37

Please sign in to comment.