Skip to content

Commit

Permalink
feat(web): add device information modal
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Oct 2, 2024
1 parent 50ae0bc commit 131ac40
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 25 deletions.
24 changes: 22 additions & 2 deletions manager-ui/src/WebApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
NavbarBrand,
NavbarContent,
NavbarItem,
Spinner
Spinner,
useDisclosure
} from '@nextui-org/react';
import { BlurredOverlay } from '@components/atoms/blurredOverlay';
import { ChevronDown, Unplug } from 'lucide-react';
import { ChevronDown, Info, Unplug } from 'lucide-react';
import { DeviceStateLayout } from './layouts/deviceState';
import { DeviceInfoModal } from '@components/DeviceInfoModal/deviceInfoModal';

enum ConnectionDialogStatus {
DIALOG_OPEN,
Expand All @@ -32,6 +34,13 @@ export const WebApp: React.FC = () => {
disconnect: state.disconnect,
setDevice: state.setDevice
}));

const {
isOpen: isDeviceInfoOpen,
onOpen: onDeviceInfoOpen,
onClose: onDeviceInfoClose
} = useDisclosure();

const [isConnecting, setIsConnecting] = useState(ConnectionDialogStatus.CLOSED);
const scan = async () => {
setIsConnecting(ConnectionDialogStatus.DIALOG_OPEN);
Expand Down Expand Up @@ -78,6 +87,14 @@ export const WebApp: React.FC = () => {
</Button>
</DropdownTrigger>
<DropdownMenu variant={'faded'} aria-label="Device Actions">
<DropdownItem
key="deviceinfo"
onClick={onDeviceInfoOpen}
startContent={
<Info className={'pointer-events-none flex-shrink-0'} size={20} />
}>
Device Information
</DropdownItem>
<DropdownItem
key="disconnect"
className="text-danger"
Expand Down Expand Up @@ -111,6 +128,9 @@ export const WebApp: React.FC = () => {
</>
)}
</div>
{state && (
<DeviceInfoModal isOpen={isDeviceInfoOpen} onClose={onDeviceInfoClose} state={state} />
)}
</>
);
};
61 changes: 61 additions & 0 deletions manager-ui/src/components/DeviceInfoModal/deviceInfoModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { SoundcoreDeviceState } from '@generated-types/soundcore-lib';
import {
Modal,
ModalBody,
ModalContent,
ModalHeader,
Table,
TableBody,
TableCell,
TableColumn,
TableHeader,
TableRow
} from '@nextui-org/react';

export interface DeviceInfoModalProps {
isOpen: boolean;
onClose: () => void;
state: SoundcoreDeviceState;
}

export const DeviceInfoModal: React.FC<DeviceInfoModalProps> = ({ isOpen, onClose, state }) => {
return (
<Modal backdrop="blur" isOpen={isOpen} onClose={onClose}>
<ModalContent>
<ModalHeader>Device Information</ModalHeader>
<ModalBody className="p-0">
<Table hideHeader removeWrapper className="p-4">
<TableHeader>
<TableColumn>Hidden</TableColumn>
<TableColumn>Hidden</TableColumn>
</TableHeader>
<TableBody>
<TableRow key="1">
<TableCell>Model</TableCell>
<TableCell>{state.serial?.model}</TableCell>
</TableRow>
<TableRow key="2">
<TableCell>Serial Number</TableCell>
<TableCell>{state.serial?.value}</TableCell>
</TableRow>
<TableRow key="3">
<TableCell>Firmware Version</TableCell>
<TableCell>
{state.fw?.primary.major}.{state.fw?.primary.minor}
</TableCell>
</TableRow>
<TableRow key="4">
<TableCell>LDAC</TableCell>
<TableCell>{state.ldac ? 'Enabled' : 'Disabled/Unknown'}</TableCell>
</TableRow>
<TableRow key="5">
<TableCell>Prompt Language</TableCell>
<TableCell>{state.promptLanguage}</TableCell>
</TableRow>
</TableBody>
</Table>
</ModalBody>
</ModalContent>
</Modal>
);
};
25 changes: 14 additions & 11 deletions manager-ui/src/stores/web/useWebManagerStore.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { BLEDevice } from '../../ble/bleDevice';
import { SoundcoreDeviceState } from '@generated-types/soundcore-lib';

Expand All @@ -10,14 +11,16 @@ export interface WebManagerStore {
disconnect: () => void;
}

export const useWebManagerStore = create<WebManagerStore>((set) => ({
device: null,
currentState: null,
setDevice: (device) => set({ device }),
setCurrentState: (currentState) => set({ currentState }),
disconnect: () =>
set((state) => {
state.device?.free();
return { device: null, currentState: null };
})
}));
export const useWebManagerStore = create<WebManagerStore>()(
devtools((set) => ({
device: null,
currentState: null,
setDevice: (device) => set({ device }),
setCurrentState: (currentState) => set({ currentState }),
disconnect: () =>
set((state) => {
state.device?.free();
return { device: null, currentState: null };
})
}))
);
9 changes: 7 additions & 2 deletions manager-ui/src/types/soundcore-lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Generated by typeshare 1.8.0
Generated by typeshare 1.9.2
*/

export type CustomANCValue = number;
Expand Down Expand Up @@ -130,6 +130,11 @@ export interface FirmwareVer {
minor: number;
}

export interface DeviceFirmware {
primary: FirmwareVer;
secondary?: FirmwareVer;
}

export type ButtonModel =
| { type: 'a3909'; value: A3909ButtonModel }
| { type: 'a3040'; value: A3040ButtonModel };
Expand Down Expand Up @@ -159,7 +164,7 @@ export interface SoundcoreDeviceState {
soundMode: SoundMode;
eqConfiguration: EQConfiguration;
serial?: SerialNumber;
fw?: FirmwareVer;
fw?: DeviceFirmware;
buttonModel?: ButtonModel;
hostDevice?: number;
sideTone?: SideTone;
Expand Down
4 changes: 2 additions & 2 deletions manager-ui/src/types/tauri-backend.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Generated by typeshare 1.8.0
Generated by typeshare 1.9.2
*/

export interface AddrWrappedPayload<T> {
Expand All @@ -26,7 +26,7 @@ export type BridgeCommand =
| { command: 'setEqualizer'; payload: AddrWrappedPayload<SetEqualizerPayload> };

export type SetEqualizerPayload =
| { command: 'setCustomEqualizer'; payload: MonoEQ }
| { command: 'setCustomEqualizer'; payload: number[] }
| { command: 'setEqualizerPreset'; payload: EQProfile };

export type BridgeResponse =
Expand Down
23 changes: 19 additions & 4 deletions soundcore-lib/src/models/fw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@ use std::fmt::Display;
use typeshare::typeshare;

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)]
pub enum DeviceFirmware {
DUAL(FirmwareVer, FirmwareVer),
SINGLE(FirmwareVer),
#[typeshare]
pub struct DeviceFirmware {
primary: FirmwareVer,
secondary: Option<FirmwareVer>,
}

impl DeviceFirmware {
pub fn new(primary: FirmwareVer, secondary: Option<FirmwareVer>) -> Self {
Self { primary, secondary }
}

pub fn primary(&self) -> FirmwareVer {
self.primary
}

pub fn secondary(&self) -> Option<FirmwareVer> {
self.secondary
}
}

#[derive(
Expand Down Expand Up @@ -40,7 +55,7 @@ impl Display for FirmwareVer {

impl From<FirmwareVer> for Option<DeviceFirmware> {
fn from(val: FirmwareVer) -> Self {
Some(DeviceFirmware::SINGLE(val))
Some(DeviceFirmware::new(val, None))
}
}

Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/packets/response/info/a3951.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn parse_a3951_device_info_packet<'a, E: ParseError<'a>>(
"parse_a3951_device_info",
all_consuming(map(pair(parse_dual_fw, parse_serial_number), |(fw, sn)| {
A3951DeviceInfoResponse {
fw: DeviceFirmware::DUAL(fw.0, fw.1),
fw: DeviceFirmware::new(fw.0, Some(fw.1)),
sn,
}
})),
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/packets/response/state/a3027.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn parse_a3027_state_response<'a, E: ParseError<'a>>(
hear_id,
sound_mode,
wear_detection,
fw: DeviceFirmware::DUAL(fw.0, fw.1),
fw: DeviceFirmware::new(fw.0, Some(fw.1)),
sn,
touch_func: touch_func.unwrap_or(false),
},
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/packets/response/state/a3028.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn parse_a3028_state_response<'a, E: ParseError<'a>>(
age_range,
hear_id,
sound_mode,
fw: DeviceFirmware::DUAL(fw.0, fw.1),
fw: DeviceFirmware::new(fw.0, Some(fw.1)),
sn,
},
},
Expand Down
2 changes: 1 addition & 1 deletion soundcore-lib/src/packets/response/state/a3029.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn parse_a3029_state_response<'a, E: ParseError<'a>>(
age_range,
hear_id,
sound_mode,
fw: DeviceFirmware::DUAL(fw.0, fw.1),
fw: DeviceFirmware::new(fw.0, Some(fw.1)),
sn,
hear_id_has_data,
},
Expand Down

0 comments on commit 131ac40

Please sign in to comment.