From 8c766c3bc2276ba8bdf5da74c8841fb8bfcfa3b0 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 3 Nov 2026 15:38:51 +0100 Subject: [PATCH] feat: settings page --- .../arm64-v8a/libthomann_dsp_app_lib.so | 2 +- .../reports/problems/problems-report.html | 2 +- .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes src/App.tsx | 10 +- src/assets/icons/SettingsIcon.tsx | 17 ++ src/components/Topbar/Topbar.css | 25 +- src/components/Topbar/Topbar.tsx | 12 +- src/hooks/useNotifications.tsx | 130 +++++++++-- src/pages/CreditsPage/CreditsPage.css | 87 ------- src/pages/CreditsPage/CreditsPage.tsx | 45 ---- src/pages/SettingsPage/SettingsPage.css | 218 ++++++++++++++++++ src/pages/SettingsPage/SettingsPage.tsx | 137 +++++++++++ src/pages/SettingsPage/settingsStore.ts | 36 +++ src/types.ts | 2 +- 15 files changed, 548 insertions(+), 175 deletions(-) create mode 100644 src/assets/icons/SettingsIcon.tsx delete mode 100644 src/pages/CreditsPage/CreditsPage.css delete mode 100644 src/pages/CreditsPage/CreditsPage.tsx create mode 100644 src/pages/SettingsPage/SettingsPage.css create mode 100644 src/pages/SettingsPage/SettingsPage.tsx create mode 100644 src/pages/SettingsPage/settingsStore.ts diff --git a/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so b/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so index 07c4bb3..78d71e2 120000 --- a/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so +++ b/src-tauri/gen/android/app/src/main/jniLibs/arm64-v8a/libthomann_dsp_app_lib.so @@ -1 +1 @@ -C:/Users/lsdg/OneDrive - ETS ROBERT SAS 49/Bureau/Projects/dsp-thomann-interface/src-tauri/target/aarch64-linux-android/release/libthomann_dsp_app_lib.so \ No newline at end of file +C:/Users/lsdg/OneDrive - ETS ROBERT SAS 49/Bureau/Projects/dsp-thomann-interface/src-tauri/target/aarch64-linux-android/debug/libthomann_dsp_app_lib.so \ No newline at end of file diff --git a/src-tauri/gen/android/build/reports/problems/problems-report.html b/src-tauri/gen/android/build/reports/problems/problems-report.html index 0ad6cfa..5b35298 100644 --- a/src-tauri/gen/android/build/reports/problems/problems-report.html +++ b/src-tauri/gen/android/build/reports/problems/problems-report.html @@ -650,7 +650,7 @@ code + .copy-button { diff --git a/src-tauri/gen/android/buildSrc/.gradle/8.14.3/executionHistory/executionHistory.lock b/src-tauri/gen/android/buildSrc/.gradle/8.14.3/executionHistory/executionHistory.lock index 1cfefedc715d8fd78cd74467e3e2ea97ff6c05e6..e4081830f8e42825f91caaa6da729508bf291b87 100644 GIT binary patch literal 17 UcmZSXk>%+-t#JM&0|aCM04^v5QUCw| literal 17 UcmZSXk>%+-t#JM&0|X=h04^W|N&o-= diff --git a/src-tauri/gen/android/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/src-tauri/gen/android/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 64db55c752622c8e0c5cc6149c0e9abc3eb904c8..21aab41e867587a4c73c728509f8f3b902de79c6 100644 GIT binary patch literal 17 UcmZR+(|%dt$g>V^1_*cr06XplX#fBK literal 17 UcmZR+(|%dt$g>V^1_-zW06X3VSpWb4 diff --git a/src/App.tsx b/src/App.tsx index f9890a4..1cdf745 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import DSPPage from './pages/DspPage/DspPage'; import AddDSPForm from './pages/AddDspPage/AddDspPage'; import { useNotifications } from './hooks/useNotifications'; import Notifications from './components/Notifications/Notifications'; -import CreditsPage from './pages/CreditsPage/CreditsPage'; +import SettingsPage from './pages/SettingsPage/SettingsPage'; import HomePage from './pages/HomePage/HomePage'; import { addDSP, createDSPInstance, restoreDSPs } from './dsp/dspApi'; import { removeDSP } from './dsp/dspShared'; @@ -20,7 +20,7 @@ function App() { const [selected, setSelected] = useState(null); const [page, setPage] = useState('home'); const [loaded, setLoaded] = useState(false); - const { notifications, notify, removeNotification, hoverNotification } = useNotifications(); + const { notifications, notify, removeNotification, hoverNotification, setNotificationsDisabled } = useNotifications(); const connectedDspCount = dsps.filter((dsp) => isConnected(dsp)).length; const restoreStarted = useRef(false); const isMobile = useIsMobile(); @@ -96,8 +96,10 @@ function App() { />
- {page === 'credits' ? ( - + {page === 'settings' ? ( + ) : page === 'add-dsp' ? ( setPage('home')} diff --git a/src/assets/icons/SettingsIcon.tsx b/src/assets/icons/SettingsIcon.tsx new file mode 100644 index 0000000..3eeb6f6 --- /dev/null +++ b/src/assets/icons/SettingsIcon.tsx @@ -0,0 +1,17 @@ +export function SettingsIcon(props: React.SVGProps) { + return ( + + + + + ); +} \ No newline at end of file diff --git a/src/components/Topbar/Topbar.css b/src/components/Topbar/Topbar.css index 884965a..576d63c 100644 --- a/src/components/Topbar/Topbar.css +++ b/src/components/Topbar/Topbar.css @@ -88,25 +88,22 @@ aspect-ratio: 1; } -.crown-action { - height: 70%; - aspect-ratio: 1; - border-radius: 50%; - color: #facc15; - width: auto; -} - -.crown-action:hover { - color: #fde047; -} - -.icon-crown, +.icon-settings, .icon-tab-add, .icon-tab-add-empty { aspect-ratio: 1/1; height: 80%; } +.settings-action { + height: 70%; + width: auto; + aspect-ratio: 1 / 1; + border-radius: 50%; + color: var(--text-muted); + flex: 0 0 auto; +} + .tab-add-empty { height: 70%; border-radius: var(--radius-pill); @@ -364,7 +361,7 @@ /* Buttons at least ~40px wide */ .tab-add, - .crown-action { + .settings-action { height: 40px; width: 40px; } diff --git a/src/components/Topbar/Topbar.tsx b/src/components/Topbar/Topbar.tsx index f3cddb3..3c7ffff 100644 --- a/src/components/Topbar/Topbar.tsx +++ b/src/components/Topbar/Topbar.tsx @@ -2,11 +2,11 @@ import { useEffect, useRef } from 'react'; import { DSP, AppPage, isConnected } from '../../types'; import AnimatedLogo from '../../assets/icons/AnimatedLogo'; import { PlusIcon } from '../../assets/icons/PlusIcon'; -import { CrownIcon } from '../../assets/icons/CrownIcon'; import Led from '../Led/Led'; import { CloseIcon } from '../../assets/icons/CloseIcon'; import './Topbar.css'; +import { SettingsIcon } from '../../assets/icons/SettingsIcon'; function getStep(count: number) { if (count <= 4) return 4; @@ -224,15 +224,15 @@ function TopBar({ )} diff --git a/src/hooks/useNotifications.tsx b/src/hooks/useNotifications.tsx index ad29875..d90c2c3 100644 --- a/src/hooks/useNotifications.tsx +++ b/src/hooks/useNotifications.tsx @@ -1,53 +1,151 @@ -import { useState, useCallback, useRef } from 'react'; + +import { useState, useCallback, useRef, useEffect } from 'react'; import { NotificationType, Notification } from '../types'; +import { loadSettings } from '../pages/SettingsPage/settingsStore'; + +type PendingNotification = { + message: string; + type: NotificationType; + dspName?: string; +}; export function useNotifications() { const [notifications, setNotifications] = useState([]); - const hovered = useRef>(new Set()); - const nextId = useRef(0); // monotonically increasing counter - const notify = useCallback( - (message: string, type: NotificationType = 'error', dspName?: string) => { + const hovered = useRef>(new Set()); + const nextId = useRef(0); + + // null means settings haven't loaded yet + const disabled = useRef(null); + const overridden = useRef(false); + + const pending = useRef([]); + + const addNotification = useCallback( + ({ message, type, dspName }: PendingNotification) => { const id = nextId.current++; const fullMessage = dspName ? `${dspName}: ${message}` : message; - setNotifications((prev) => [...prev, { id, message: fullMessage, type }]); + setNotifications((prev) => [ + ...prev, + { id, message: fullMessage, type }, + ]); const removeLater = () => { if (hovered.current.has(id)) { setTimeout(removeLater, 1000); return; } + setNotifications((prev) => prev.filter((n) => n.id !== id)); }; setTimeout(removeLater, 5000); }, - [] + [], + ); + + // Load notification preference on startup + useEffect(() => { + let cancelled = false; + + async function initialize() { + try { + const settings = await loadSettings(); + + if (cancelled) return; + + // Don't overwrite a setting changed while loading + if (!overridden.current) { + disabled.current = settings.disableNotifications; + } + } catch (error) { + console.error('Failed to load notification settings:', error); + + if (!cancelled && !overridden.current) { + disabled.current = false; + } + } + + if (cancelled) return; + + // Process notifications queued during initialization + const queued = pending.current.splice(0); + + if (!disabled.current) { + queued.forEach(addNotification); + } + } + + initialize(); + + return () => { + cancelled = true; + }; + }, [addNotification]); + + // Called by SettingsPage when the checkbox changes + const setNotificationsDisabled = useCallback((value: boolean) => { + overridden.current = true; + disabled.current = value; + + if (value) { + setNotifications([]); + hovered.current.clear(); + pending.current = []; + } + }, []); + + const notify = useCallback( + ( + message: string, + type: NotificationType = 'error', + dspName?: string, + ) => { + const notification = { message, type, dspName }; + + // Wait until the preference has loaded + if (disabled.current === null) { + pending.current.push(notification); + return; + } + + if (disabled.current) return; + + addNotification(notification); + }, + [addNotification], ); const removeNotification = useCallback((id: number) => { - hovered.current.delete(id); // prevent leaking stale hover state - setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, removing: true } : n))); + hovered.current.delete(id); + + setNotifications((prev) => + prev.map((n) => (n.id === id ? { ...n, removing: true } : n)), + ); setTimeout(() => { setNotifications((prev) => prev.filter((n) => n.id !== id)); }, 250); }, []); - const hoverNotification = useCallback((id: number, hovering: boolean) => { - if (hovering) { - hovered.current.add(id); - } else { - hovered.current.delete(id); - } - }, []); + const hoverNotification = useCallback( + (id: number, hovering: boolean) => { + if (hovering) { + hovered.current.add(id); + } else { + hovered.current.delete(id); + } + }, + [], + ); return { notifications, notify, removeNotification, hoverNotification, + setNotificationsDisabled, }; } diff --git a/src/pages/CreditsPage/CreditsPage.css b/src/pages/CreditsPage/CreditsPage.css deleted file mode 100644 index dadd539..0000000 --- a/src/pages/CreditsPage/CreditsPage.css +++ /dev/null @@ -1,87 +0,0 @@ - -.credits-page { - width: 100%; - max-width: 520px; - margin: auto; - - user-select: none; - -webkit-user-select: none; -} - -.credits-page__header { - margin-bottom: var(--space-5); -} - -.credits-page__title { - margin: 0; - font-size: var(--font-2xl); - font-weight: var(--font-weight-semibold); - color: var(--text-primary); -} - -.credits-page__subtitle { - margin: var(--space-2) 0 0; - font-size: var(--font-sm); - color: var(--text-muted); -} - -.credits-page__actions { - display: flex; - justify-content: flex-end; - margin-top: var(--space-2); -} - -.credits-page input, -.credits-page select, -.credits-page textarea { - user-select: text; - -webkit-user-select: text; -} - -/* ---------- Phone ---------- */ - -@media (max-width: 768px) { - .credits-page { - max-width: 480px; - } -} - -/* ---------- Landscape phone: compact card ---------- */ - -@media (max-height: 500px) and (orientation: landscape) { - .credits-page { - max-width: 440px; - } - - .credits-page__header { - margin-bottom: 8px; - } - - .credits-page__title { - font-size: var(--font-lg); - } - - .credits-page__subtitle { - margin-top: 4px; - font-size: 12px; - } - - .credits-page .specs { - gap: 6px; - margin-bottom: 8px; - padding: 8px 12px; - } - - .credits-page .spec { - gap: 12px; - } - - .credits-page .spec dt, - .credits-page .spec dd { - font-size: 12px; - } - - .credits-page__actions { - margin-top: 4px; - } -} diff --git a/src/pages/CreditsPage/CreditsPage.tsx b/src/pages/CreditsPage/CreditsPage.tsx deleted file mode 100644 index 1bb732b..0000000 --- a/src/pages/CreditsPage/CreditsPage.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import Card from '../../components/Card/Card'; -import Button from '../../components/Button/Button'; - -import './CreditsPage.css'; - -function CreditsPage() { - return ( - -
-

Credits

-

- Thanks to the people, projects, and communities that made this application possible. -

-
- -
-
-
Developer
-
Lucas
-
- -
-
Framework
-
React + TypeScript
-
- -
-
Desktop Runtime
-
Tauri
-
- -
-
Special Thanks
-
-
-
- -
- -
-
- ); -} - -export default CreditsPage; diff --git a/src/pages/SettingsPage/SettingsPage.css b/src/pages/SettingsPage/SettingsPage.css new file mode 100644 index 0000000..03d3bb0 --- /dev/null +++ b/src/pages/SettingsPage/SettingsPage.css @@ -0,0 +1,218 @@ + +.settings-page { + width: 100%; + max-width: 520px; + margin: auto; + + user-select: none; + -webkit-user-select: none; +} + +/* ---------- Header ---------- */ + +.settings-page__header { + margin-bottom: var(--space-5); +} + +.settings-page__title { + margin: 0; + font-size: var(--font-2xl); + font-weight: var(--font-weight-semibold); + color: var(--text-primary); +} + +.settings-page__hint { + margin: var(--space-2) 0 0; + font-size: var(--font-sm); + color: var(--text-muted); +} + +/* ---------- Sections ---------- */ + +.settings-page__section { + display: flex; + flex-direction: column; + gap: var(--space-3); +} + +.settings-page__section-title { + margin: 0; + font-size: var(--font-sm); + font-weight: var(--font-weight-semibold); + color: var(--text-primary); +} + +.settings-page__divider { + height: 1px; + background: var(--border-hairline); + margin: var(--space-5) 0; +} + +/* ---------- Checkbox ---------- */ + +.settings-page__checkbox-label { + display: flex; + align-items: center; + gap: var(--space-3); + min-height: 36px; + cursor: pointer; +} + +.settings-page__checkbox-content { + display: flex; + flex-direction: column; + gap: 3px; + min-width: 0; + + font-size: var(--font-sm); + color: var(--text-primary); +} + +.settings-page__description { + font-size: var(--font-xs); + color: var(--text-muted); +} + +.settings-page__checkbox-label input[type='checkbox'] { + appearance: none; + -webkit-appearance: none; + box-sizing: border-box; + + flex: 0 0 auto; + display: block; + + width: 18px; + height: 18px; + aspect-ratio: 1 / 1; + padding: 0; + margin: 0; + + background: var(--bg-panel); + border: var(--border-width) solid var(--border-hairline); + border-radius: var(--radius-sm); + + position: relative; + cursor: pointer; + + transition: + border-color var(--dur-base) var(--ease-standard), + background var(--dur-base) var(--ease-standard); +} + +.settings-page__checkbox-label input[type='checkbox']:checked { + background: var(--accent-brand); + border-color: var(--accent-brand); +} + +.settings-page__checkbox-label input[type='checkbox']:checked::after { + content: ''; + + position: absolute; + left: 50%; + top: 50%; + + width: 5px; + height: 9px; + + border: solid var(--bg-panel); + border-width: 0 2px 2px 0; + + transform: translate(-50%, -60%) rotate(45deg); +} + +.settings-page__checkbox-label input[type='checkbox']:focus-visible { + outline: 2px solid var(--accent-brand); + outline-offset: 2px; +} + +/* ---------- Credits ---------- */ + +.settings-page__credits { + display: flex; + flex-direction: column; + gap: var(--space-3); + margin: 0; +} + +.settings-page__credit { + display: flex; + align-items: center; + justify-content: space-between; + gap: var(--space-3); + + font-size: var(--font-sm); +} + +.settings-page__credit dt { + color: var(--text-muted); +} + +.settings-page__credit dd { + margin: 0; + color: var(--text-primary); + text-align: right; +} + +/* ---------- Text selection ---------- */ + +.settings-page input { + user-select: text; + -webkit-user-select: text; +} + +/* ---------- Phone / touch ---------- */ + +@media (pointer: coarse) { + .settings-page__checkbox-label { + min-height: 44px; + } + + .settings-page__checkbox-label input[type='checkbox'] { + min-height: 0; + } +} + +@media (max-width: 768px) { + .settings-page { + width: 100%; + max-width: 520px; + } +} + +/* ---------- Landscape phone ---------- */ + +@media (max-height: 500px) and (orientation: landscape) { + .settings-page { + max-width: 440px; + } + + .settings-page__header { + margin-bottom: 8px; + } + + .settings-page__title { + font-size: var(--font-lg); + } + + .settings-page__hint { + margin-top: 4px; + font-size: 12px; + } + + .settings-page__section { + gap: 6px; + } + + .settings-page__divider { + margin: 10px 0; + } + + .settings-page__credits { + gap: 6px; + } + + .settings-page__credit, + .settings-page__checkbox-content { + font-size: 12px; + } +} diff --git a/src/pages/SettingsPage/SettingsPage.tsx b/src/pages/SettingsPage/SettingsPage.tsx new file mode 100644 index 0000000..e705cc7 --- /dev/null +++ b/src/pages/SettingsPage/SettingsPage.tsx @@ -0,0 +1,137 @@ + +import { useEffect, useState } from 'react'; +import Card from '../../components/Card/Card'; +import { + AppSettings, + DEFAULT_SETTINGS, + loadSettings, + saveSettings, +} from './settingsStore'; + +import './SettingsPage.css'; + +function SettingsPage({ + onNotificationsDisabledChange, +}: { + onNotificationsDisabledChange: (disabled: boolean) => void; +}) { + const [settings, setSettings] = useState(DEFAULT_SETTINGS); + const [loaded, setLoaded] = useState(false); + + useEffect(() => { + let cancelled = false; + + async function initialize() { + try { + const saved = await loadSettings(); + + if (!cancelled) { + setSettings(saved); + onNotificationsDisabledChange(saved.disableNotifications); + } + } catch (error) { + console.error('Failed to load settings:', error); + } finally { + if (!cancelled) { + setLoaded(true); + } + } + } + + initialize(); + + return () => { + cancelled = true; + }; + }, []); + + async function updateSetting( + key: K, + value: AppSettings[K], + ) { + const updated = { + ...settings, + [key]: value, + }; + + setSettings(updated); + + try { + await saveSettings(updated); + } catch (error) { + console.error('Failed to save settings:', error); + } + } + + return ( + +
+

Settings

+

+ Customize how the application behaves. +

+
+ + {/* General */} +
+

General

+ + +
+ +
+ + {/* About */} +
+

About

+ +
+
+
Developer
+
Lucas
+
+ +
+
Framework
+
React + TypeScript
+
+ +
+
Desktop Runtime
+
Tauri
+
+ +
+
Special Thanks
+
Open-source community
+
+
+
+ + ); +} + +export default SettingsPage; diff --git a/src/pages/SettingsPage/settingsStore.ts b/src/pages/SettingsPage/settingsStore.ts new file mode 100644 index 0000000..3d33b7a --- /dev/null +++ b/src/pages/SettingsPage/settingsStore.ts @@ -0,0 +1,36 @@ + +import { load, Store } from '@tauri-apps/plugin-store'; + +export type AppSettings = { + disableNotifications: boolean; +}; + +export const DEFAULT_SETTINGS: AppSettings = { + disableNotifications: false, +}; + +const STORE_FILE = 'settings.json'; +const STORE_KEY = 'settings'; + +let storePromise: Promise | null = null; + +const getStore = () => + (storePromise ??= load(STORE_FILE, { autoSave: false })); + +export async function loadSettings(): Promise { + const store = await getStore(); + + return { + ...DEFAULT_SETTINGS, + ...(await store.get>(STORE_KEY)), + }; +} + +export async function saveSettings( + settings: AppSettings, +): Promise { + const store = await getStore(); + + await store.set(STORE_KEY, settings); + await store.save(); +} diff --git a/src/types.ts b/src/types.ts index 3d5a8f6..da07555 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,7 @@ export type Notification = { removing?: boolean; }; -export type AppPage = 'home' | 'add-dsp' | 'view-dsp' | 'credits'; +export type AppPage = 'home' | 'add-dsp' | 'view-dsp' | 'settings'; type DSPDefaultParameters = { ip: string;