Skip to content

Commit

Permalink
Fix: Save, Restore and Reapply Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed Apr 10, 2023
1 parent e0fb15e commit c533cf1
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"root": true,
"extends": ["with-tsconfig"],
"rules": {
"new-cap": "off"
"new-cap": "off",
"no-sequences": "off"
},
"overrides": [
{
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none"
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
"ress": "5.0.2",
"tauri-plugin-autostart-api": "https://github.com/tauri-apps/tauri-plugin-autostart",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
"throttle-debounce": "5.0.0",
"ts-pattern": "4.2.2",
"valtio": "1.10.4"
"valtio": "1.10.4",
"zod": "^3.21.4"
},
"devDependencies": {
"@babel/core": "7.21.4",
"@tauri-apps/cli": "1.2.3",
"@types/node": "18.15.11",
"@types/react": "18.0.33",
"@types/react": "18.0.34",
"@types/react-dom": "18.0.11",
"@types/throttle-debounce": "5.0.0",
"@vitejs/plugin-react": "3.1.0",
"core-dts": "0.0.3",
"eslint": "8.38.0",
Expand Down
90 changes: 56 additions & 34 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "SensiMouse",
"version": "1.0.2"
"version": "1.0.3"
},
"tauri": {
"allowlist": {
Expand Down
25 changes: 1 addition & 24 deletions src/store.ts → src/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { invoke } from '@tauri-apps/api/tauri'
import { atom, getDefaultStore } from 'jotai'
import * as autostart from 'tauri-plugin-autostart-api'

import { DEFAULT_ACC_ENABLED, DEFAULT_SEN } from './constants'
import { getMouseCfg, setMouseCfg } from './lib/cmd'
import { on } from './lib/dom'
import { setMouseCfg } from './lib/cmd'

export const store = getDefaultStore()

Expand All @@ -26,24 +24,3 @@ export const setAutoLaunchAtom = atom(null, async (_, set, enabled: boolean) =>

set(autoLaunchAtom, enabled)
})

export const fetchState = async () => {
const ret = await getMouseCfg()
const [sen, accEnabled] = ret.match({
Ok: v => v,
Error: () => [DEFAULT_SEN, DEFAULT_ACC_ENABLED]
})

const autoStart = await autostart.isEnabled()

store.set(senAtom, sen)
store.set(accEnabledAtom, accEnabled)
store.set(autoLaunchAtom, autoStart)
}

export const resetState = () => {
store.set(senAtom, DEFAULT_SEN)
store.set(accEnabledAtom, DEFAULT_ACC_ENABLED)
}

on(window)('focus', fetchState)
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Locales } from './i18n/i18n-types'

export const DEFAULT_LANG: Locales = 'en'
export const DEFAULT_LOCALE: Locales = 'en'

export const DEFAULT_SEN = 90

Expand Down
Loading

0 comments on commit c533cf1

Please sign in to comment.