Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ef2959

Browse filesBrowse files
committed
feat: add proper saving of settings
- save on window lost focus - save every 30 seconds only if there is a change to the settings file - add lodash to compare settings objects
1 parent f69d04a commit 2ef2959
Copy full SHA for 2ef2959

3 files changed

+130-106Lines changed: 130 additions & 106 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎GUI/ETVR/package.json‎

Copy file name to clipboard
+83-82Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,84 @@
11
{
2-
"name": "etvr",
3-
"version": "1.0.0",
4-
"private": true,
5-
"description": "A SolidJS project for EyeTrack VR",
6-
"author": "EyeTrack VR",
7-
"license": "MIT",
8-
"scripts": {
9-
"dev": "vite dev",
10-
"build": "vite build",
11-
"start": "vite start",
12-
"serve": "vite preview",
13-
"tauri": "tauri",
14-
"tauri:dev": "tauri dev",
15-
"tauri:dev:release": "tauri dev --release",
16-
"tauri:build": "tauri build",
17-
"tauri:build:dev": "tauri build --debug",
18-
"tauri:update": "cd src-tauri && cargo update && cargo upgrade",
19-
"tauri:clean": "cd src-tauri && cargo clean",
20-
"docs": "jsdoc -c jsdoc.conf.json",
21-
"lint": "eslint --ext .js,.ts,.jsx,.tsx src",
22-
"format": "pnpm run lint --fix & pnpm prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
23-
"update-deps": "pnpm up -Li",
24-
"typecheck": "tsc --noEmit"
25-
},
26-
"devDependencies": {
27-
"@babel/core": "^7.22.9",
28-
"@babel/preset-env": "^7.22.9",
29-
"@tailwindcss/forms": "^0.5.4",
30-
"@tauri-apps/api": "^1.4.0",
31-
"@tauri-apps/cli": "^1.4.0",
32-
"@types/node": "^20.4.2",
33-
"@typescript-eslint/eslint-plugin": "^6.1.0",
34-
"@typescript-eslint/parser": "^6.1.0",
35-
"autoprefixer": "^10.4.14",
36-
"babel-loader": "^9.1.3",
37-
"better-docs": "^2.7.2",
38-
"eslint": "^8.41.0",
39-
"eslint-config-google": "^0.14.0",
40-
"eslint-config-prettier": "^8.8.0",
41-
"eslint-import-resolver-typescript": "^3.5.5",
42-
"eslint-plugin-autofix": "^1.1.0",
43-
"eslint-plugin-import": "^2.27.5",
44-
"eslint-plugin-solid": "^0.12.1",
45-
"https-localhost": "^4.7.1",
46-
"jsdoc": "^4.0.2",
47-
"postcss": "^8.4.24",
48-
"postcss-import": "^15.1.0",
49-
"prettier": "^3.0.0",
50-
"tailwindcss": "^3.3.3",
51-
"typescript": "^5.1.6",
52-
"vite": "^4.4.4",
53-
"vite-plugin-solid": "^2.7.0"
54-
},
55-
"dependencies": {
56-
"@builder.io/partytown": "^0.8.0",
57-
"@kobalte/core": "^0.9.8",
58-
"@kobalte/tailwindcss": "^0.6.5",
59-
"@solid-primitives/i18n": "^1.4.0",
60-
"@solid-primitives/map": "^0.4.6",
61-
"@solidjs/meta": "^0.28.5",
62-
"@solidjs/router": "^0.8.2",
63-
"@stitches/core": "^1.2.8",
64-
"@tailwindcss/typography": "^0.5.9",
65-
"babel-preset-solid": "^1.7.7",
66-
"clsx": "^1.2.1",
67-
"moment": "^2.29.4",
68-
"solid-form-handler": "^1.2.0",
69-
"solid-headless": "^0.13.1",
70-
"solid-i18n": "^1.0.4",
71-
"solid-icons": "^1.0.11",
72-
"solid-js": "^1.7.8",
73-
"solid-spinner": "^0.1.9",
74-
"solid-transition-group": "^0.2.2",
75-
"solidjs-icons": "^1.0.12",
76-
"solidjs-use": "^2.2.1",
77-
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log",
78-
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
79-
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload",
80-
"undici": "^5.22.1",
81-
"yup": "^1.2.0"
82-
}
83-
}
2+
"name": "etvr",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "A SolidJS project for EyeTrack VR",
6+
"author": "EyeTrack VR",
7+
"license": "MIT",
8+
"scripts": {
9+
"dev": "vite dev",
10+
"build": "vite build",
11+
"start": "vite start",
12+
"serve": "vite preview",
13+
"tauri": "tauri",
14+
"tauri:dev": "tauri dev",
15+
"tauri:dev:release": "tauri dev --release",
16+
"tauri:build": "tauri build",
17+
"tauri:build:dev": "tauri build --debug",
18+
"tauri:update": "cd src-tauri && cargo update && cargo upgrade",
19+
"tauri:clean": "cd src-tauri && cargo clean",
20+
"docs": "jsdoc -c jsdoc.conf.json",
21+
"lint": "eslint --ext .js,.ts,.jsx,.tsx src",
22+
"format": "pnpm run lint --fix & pnpm prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
23+
"update-deps": "pnpm up -Li",
24+
"typecheck": "tsc --noEmit"
25+
},
26+
"devDependencies": {
27+
"@babel/core": "^7.22.9",
28+
"@babel/preset-env": "^7.22.9",
29+
"@tailwindcss/forms": "^0.5.4",
30+
"@tauri-apps/api": "^1.4.0",
31+
"@tauri-apps/cli": "^1.4.0",
32+
"@types/node": "^20.4.2",
33+
"@typescript-eslint/eslint-plugin": "^6.1.0",
34+
"@typescript-eslint/parser": "^6.1.0",
35+
"autoprefixer": "^10.4.14",
36+
"babel-loader": "^9.1.3",
37+
"better-docs": "^2.7.2",
38+
"eslint": "^8.41.0",
39+
"eslint-config-google": "^0.14.0",
40+
"eslint-config-prettier": "^8.8.0",
41+
"eslint-import-resolver-typescript": "^3.5.5",
42+
"eslint-plugin-autofix": "^1.1.0",
43+
"eslint-plugin-import": "^2.27.5",
44+
"eslint-plugin-solid": "^0.12.1",
45+
"https-localhost": "^4.7.1",
46+
"jsdoc": "^4.0.2",
47+
"postcss": "^8.4.24",
48+
"postcss-import": "^15.1.0",
49+
"prettier": "^3.0.0",
50+
"tailwindcss": "^3.3.3",
51+
"typescript": "^5.1.6",
52+
"vite": "^4.4.4",
53+
"vite-plugin-solid": "^2.7.0"
54+
},
55+
"dependencies": {
56+
"@builder.io/partytown": "^0.8.0",
57+
"@kobalte/core": "^0.9.8",
58+
"@kobalte/tailwindcss": "^0.6.5",
59+
"@solid-primitives/i18n": "^1.4.0",
60+
"@solid-primitives/map": "^0.4.6",
61+
"@solidjs/meta": "^0.28.5",
62+
"@solidjs/router": "^0.8.2",
63+
"@stitches/core": "^1.2.8",
64+
"@tailwindcss/typography": "^0.5.9",
65+
"babel-preset-solid": "^1.7.7",
66+
"clsx": "^1.2.1",
67+
"lodash": "^4.17.21",
68+
"moment": "^2.29.4",
69+
"solid-form-handler": "^1.2.0",
70+
"solid-headless": "^0.13.1",
71+
"solid-i18n": "^1.0.4",
72+
"solid-icons": "^1.0.11",
73+
"solid-js": "^1.7.8",
74+
"solid-spinner": "^0.1.9",
75+
"solid-transition-group": "^0.2.2",
76+
"solidjs-icons": "^1.0.12",
77+
"solidjs-use": "^2.2.1",
78+
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log",
79+
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store",
80+
"tauri-plugin-upload-api": "github:tauri-apps/tauri-plugin-upload",
81+
"undici": "^5.22.1",
82+
"yup": "^1.2.0"
83+
}
84+
}
Collapse file

‎GUI/ETVR/pnpm-lock.yaml‎

Copy file name to clipboardExpand all lines: GUI/ETVR/pnpm-lock.yaml
+12-10Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎GUI/ETVR/src/routes/Routes.tsx‎

Copy file name to clipboardExpand all lines: GUI/ETVR/src/routes/Routes.tsx
+35-14Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useLocation, useNavigate, useRoutes } from '@solidjs/router'
2+
import { isEqual } from 'lodash'
23
import { createEffect, onMount, type Component, createSignal } from 'solid-js'
3-
import { useEventListener } from 'solidjs-use'
4+
import { useEventListener, useInterval } from 'solidjs-use'
45
import { debug } from 'tauri-plugin-log-api'
56
import { routes } from '.'
67
import type { PersistentSettings } from '@src/static/types'
@@ -66,30 +67,50 @@ const AppRoutes: Component = () => {
6667
setScanForCamerasOnStartup(settings.scanForCamerasOnStartup)
6768
}
6869
})
70+
checkPermission()
6971
doGHRequest()
7072
useMDNSScanner('_openiristracker._tcp', 5).then(() => {
7173
// TODO: pass the mdns res object to the Python backend - then start the websocket clients after the backend is ready
7274
// passMdnsResToPythonBackend().then(() => {
7375
generateWebsocketClients(getCameras, addNotification, setCameraWS, setCameraStatus)
7476
//})
7577
})
76-
checkPermission()
7778
})
7879

80+
const createSettingsObject = () => {
81+
const settings: PersistentSettings = {
82+
user: connectedUserName(),
83+
enableNotifications: getEnableNotifications(),
84+
enableNotificationsSounds: getEnableNotificationsSounds(),
85+
globalNotificationsType: getGlobalNotificationsType(),
86+
enableMDNS: getEnableMDNS(),
87+
debugMode: getDebugMode(),
88+
scanForCamerasOnStartup: getScanForCamerasOnStartup(),
89+
}
90+
return settings
91+
}
92+
93+
const handleSaveSettings = async () => {
94+
// check if the settings have changed and save to the store if they have
95+
get('settings').then((storedSettings) => {
96+
if (!isEqual(storedSettings, createSettingsObject())) {
97+
debug(`[Routes]: Saving Settings - ${JSON.stringify(createSettingsObject())}`)
98+
set('settings', createSettingsObject())
99+
}
100+
})
101+
}
102+
79103
createEffect(() => {
104+
const { resume, pause } = useInterval(30000, {
105+
controls: true,
106+
callback: handleSaveSettings,
107+
})
108+
80109
useEventListener(window, 'blur', () => {
81-
// save the app settings to the persistent store
82-
const settings: PersistentSettings = {
83-
user: connectedUserName(),
84-
enableNotifications: getEnableNotifications(),
85-
enableNotificationsSounds: getEnableNotificationsSounds(),
86-
globalNotificationsType: getGlobalNotificationsType(),
87-
enableMDNS: getEnableMDNS(),
88-
debugMode: getDebugMode(),
89-
scanForCamerasOnStartup: getScanForCamerasOnStartup(),
90-
}
91-
debug(`[Routes]: Saving Settings - ${JSON.stringify(settings)}`)
92-
set('settings', settings)
110+
pause()
111+
debug(`[Routes]: Saving Settings - ${JSON.stringify(createSettingsObject())}`)
112+
set('settings', createSettingsObject())
113+
resume()
93114
})
94115
})
95116

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.