Browse Source

Merge branch 'master' into feature/node-quick-options

pull/307/head
Tilen Komel 1 year ago
parent
commit
3f88373dd8
  1. 2
      .dockerignore
  2. 8
      .github/workflows/ci.yml
  3. 2
      .github/workflows/pr.yml
  4. 7
      Containerfile
  5. 6
      README.md
  6. 19
      package.json
  7. 944
      pnpm-lock.yaml
  8. 30
      rsbuild.config.ts
  9. 26
      src/App.tsx
  10. 4
      src/DeviceWrapper.tsx
  11. 12
      src/PageRouter.tsx
  12. 6
      src/components/CommandPalette.tsx
  13. 10
      src/components/DeviceSelector.tsx
  14. 10
      src/components/Dialog/DeviceNameDialog.tsx
  15. 21
      src/components/Dialog/DialogManager.tsx
  16. 14
      src/components/Dialog/ImportDialog.tsx
  17. 173
      src/components/Dialog/NewDeviceDialog.tsx
  18. 134
      src/components/Dialog/PKIBackupDialog.tsx
  19. 4
      src/components/Dialog/PkiRegenerateDialog.tsx
  20. 8
      src/components/Dialog/QRDialog.tsx
  21. 8
      src/components/Dialog/RebootDialog.tsx
  22. 8
      src/components/Dialog/RemoveNodeDialog.tsx
  23. 8
      src/components/Dialog/ShutdownDialog.tsx
  24. 10
      src/components/Form/DynamicForm.tsx
  25. 8
      src/components/Form/DynamicFormField.tsx
  26. 23
      src/components/Form/FormInput.tsx
  27. 32
      src/components/Form/FormPasswordGenerator.tsx
  28. 4
      src/components/Form/FormSelect.tsx
  29. 4
      src/components/Form/FormToggle.tsx
  30. 2
      src/components/Form/FormWrapper.tsx
  31. 19
      src/components/KeyBackupReminder.tsx
  32. 223
      src/components/PageComponents/Channel.tsx
  33. 23
      src/components/PageComponents/Config/Bluetooth.tsx
  34. 29
      src/components/PageComponents/Config/Device.tsx
  35. 6
      src/components/PageComponents/Config/Display.tsx
  36. 6
      src/components/PageComponents/Config/LoRa.tsx
  37. 8
      src/components/PageComponents/Config/Network.tsx
  38. 12
      src/components/PageComponents/Config/Position.tsx
  39. 6
      src/components/PageComponents/Config/Power.tsx
  40. 37
      src/components/PageComponents/Config/Security.tsx
  41. 12
      src/components/PageComponents/Connect/BLE.tsx
  42. 16
      src/components/PageComponents/Connect/HTTP.tsx
  43. 23
      src/components/PageComponents/Connect/Serial.tsx
  44. 171
      src/components/PageComponents/Map/NodeDetail.tsx
  45. 10
      src/components/PageComponents/Messages/ChannelChat.tsx
  46. 5
      src/components/PageComponents/Messages/Message.tsx
  47. 6
      src/components/PageComponents/Messages/MessageInput.tsx
  48. 2
      src/components/PageComponents/Messages/TraceRoute.tsx
  49. 6
      src/components/PageComponents/ModuleConfig/AmbientLighting.tsx
  50. 6
      src/components/PageComponents/ModuleConfig/Audio.tsx
  51. 6
      src/components/PageComponents/ModuleConfig/CannedMessage.tsx
  52. 6
      src/components/PageComponents/ModuleConfig/DetectionSensor.tsx
  53. 6
      src/components/PageComponents/ModuleConfig/ExternalNotification.tsx
  54. 6
      src/components/PageComponents/ModuleConfig/MQTT.tsx
  55. 6
      src/components/PageComponents/ModuleConfig/NeighborInfo.tsx
  56. 6
      src/components/PageComponents/ModuleConfig/Paxcounter.tsx
  57. 6
      src/components/PageComponents/ModuleConfig/RangeTest.tsx
  58. 6
      src/components/PageComponents/ModuleConfig/Serial.tsx
  59. 6
      src/components/PageComponents/ModuleConfig/StoreForward.tsx
  60. 6
      src/components/PageComponents/ModuleConfig/Telemetry.tsx
  61. 2
      src/components/PageLayout.tsx
  62. 33
      src/components/Sidebar.tsx
  63. 27
      src/components/Toaster.tsx
  64. 6
      src/components/UI/Button.tsx
  65. 2
      src/components/UI/Checkbox.tsx
  66. 4
      src/components/UI/Command.tsx
  67. 2
      src/components/UI/Dialog.tsx
  68. 2
      src/components/UI/DropdownMenu.tsx
  69. 48
      src/components/UI/Generator.tsx
  70. 2
      src/components/UI/Input.tsx
  71. 2
      src/components/UI/Label.tsx
  72. 2
      src/components/UI/Menubar.tsx
  73. 2
      src/components/UI/Popover.tsx
  74. 2
      src/components/UI/ScrollArea.tsx
  75. 2
      src/components/UI/Select.tsx
  76. 2
      src/components/UI/Seperator.tsx
  77. 2
      src/components/UI/Sidebar/SidebarSection.tsx
  78. 2
      src/components/UI/Sidebar/sidebarButton.tsx
  79. 2
      src/components/UI/Switch.tsx
  80. 2
      src/components/UI/Tabs.tsx
  81. 70
      src/components/UI/Toast.tsx
  82. 2
      src/components/UI/Tooltip.tsx
  83. 2
      src/components/UI/Typography/H4.tsx
  84. 14
      src/components/UI/Typography/H5.tsx
  85. 7
      src/components/UI/Typography/Link.tsx
  86. 2
      src/components/UI/Typography/Subtle.tsx
  87. 2
      src/components/generic/ThemeController.tsx
  88. 29
      src/core/hooks/useBrowserFeatureDetection.ts
  89. 52
      src/core/hooks/useCookie.ts
  90. 120
      src/core/hooks/useKeyBackupReminder.tsx
  91. 63
      src/core/hooks/useToast.ts
  92. 5
      src/core/stores/deviceStore.ts
  93. 2
      src/core/subscriptions.ts
  94. 2
      src/core/utils/x25519.ts
  95. 2
      src/index.css
  96. 2
      src/index.tsx
  97. 10
      src/pages/Channels.tsx
  98. 20
      src/pages/Config/DeviceConfig.tsx
  99. 26
      src/pages/Config/ModuleConfig.tsx
  100. 16
      src/pages/Config/index.tsx

2
.dockerignore

@ -0,0 +1,2 @@
dist/build.tar
dist/output

8
.github/workflows/ci.yml

@ -13,11 +13,11 @@ jobs:
build-and-package: build-and-package:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with: - name: Setup pnpm
version: latest uses: pnpm/action-setup@v4
- name: Install Dependencies - name: Install Dependencies
run: pnpm install run: pnpm install

2
.github/workflows/pr.yml

@ -11,8 +11,6 @@ jobs:
- name: Setup pnpm - name: Setup pnpm
uses: pnpm/action-setup@v4 uses: pnpm/action-setup@v4
with:
version: latest
- name: Install Dependencies - name: Install Dependencies
run: pnpm install run: pnpm install

7
Containerfile

@ -1,4 +1,9 @@
FROM registry.access.redhat.com/ubi9/nginx-122:1-45 FROM nginx:1.27.2-alpine
RUN rm -r /usr/share/nginx/html \
&& mkdir /usr/share/nginx/html
WORKDIR /usr/share/nginx/html
ADD dist . ADD dist .

6
README.md

@ -20,14 +20,14 @@ Official [Meshtastic](https://meshtastic.org) web interface, that can be hosted
## Self-host ## Self-host
The client can be self hosted using the precompiled container images with an OCI compatible runtime such as [Docker](https://www.docker.com/) or [Podman](https://podman.io/). The client can be self hosted using the precompiled container images with an OCI compatible runtime such as [Docker](https://www.docker.com/) or [Podman](https://podman.io/).
The base image used is [UBI9 Nginx 1.22](https://catalog.redhat.com/software/containers/ubi9/nginx-122/63f7653b9b0ca19f84f7e9a1) The base image used is [Nginx 1.27](https://hub.docker.com/_/nginx)
```bash ```bash
# With Docker # With Docker
docker run -d -p 8080:8080 -p 8443:8443 --restart always --name Meshtastic-Web ghcr.io/meshtastic/web docker run -d -p 8080:80 --restart always --name Meshtastic-Web ghcr.io/meshtastic/web
#With Podman #With Podman
podman run -d -p 8080:8080 -p 8443:8443 --restart always --name Meshtastic-Web ghcr.io/meshtastic/web podman run -d -p 8080:80 --restart always --name Meshtastic-Web ghcr.io/meshtastic/web
``` ```
## Development & Building ## Development & Building

19
package.json

@ -5,11 +5,12 @@
"description": "Meshtastic web client", "description": "Meshtastic web client",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"scripts": { "scripts": {
"dev": "vite --host", "build": "rsbuild build",
"build": "tsc && pnpm check && vite build ",
"check": "biome check .", "check": "biome check .",
"check:fix": "pnpm check --write", "check:fix": "pnpm check --write",
"preview": "vite preview", "dev": "rsbuild dev --open",
"format": "biome format --write",
"preview": "rsbuild preview",
"package": "gzipper c -i html,js,css,png,ico,svg,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ $(ls ./dist/output/)" "package": "gzipper c -i html,js,css,png,ico,svg,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ $(ls ./dist/output/)"
}, },
"repository": { "repository": {
@ -48,6 +49,7 @@
"cmdk": "^1.0.0", "cmdk": "^1.0.0",
"crypto-random-string": "^5.0.0", "crypto-random-string": "^5.0.0",
"immer": "^10.1.1", "immer": "^10.1.1",
"js-cookie": "^3.0.5",
"lucide-react": "^0.363.0", "lucide-react": "^0.363.0",
"mapbox-gl": "^3.6.0", "mapbox-gl": "^3.6.0",
"maplibre-gl": "4.1.2", "maplibre-gl": "4.1.2",
@ -66,13 +68,15 @@
"devDependencies": { "devDependencies": {
"@biomejs/biome": "^1.8.2", "@biomejs/biome": "^1.8.2",
"@buf/meshtastic_protobufs.bufbuild_es": "1.10.0-20240906232734-3da561588c55.1", "@buf/meshtastic_protobufs.bufbuild_es": "1.10.0-20240906232734-3da561588c55.1",
"@rsbuild/core": "^1.0.10",
"@rsbuild/plugin-react": "^1.0.3",
"@types/chrome": "^0.0.263", "@types/chrome": "^0.0.263",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.14.9", "@types/node": "^20.14.9",
"@types/react": "^18.3.3", "@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"@types/w3c-web-serial": "^1.0.6", "@types/w3c-web-serial": "^1.0.6",
"@types/web-bluetooth": "^0.0.20", "@types/web-bluetooth": "^0.0.20",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"gzipper": "^7.2.0", "gzipper": "^7.2.0",
"postcss": "^8.4.38", "postcss": "^8.4.38",
@ -80,8 +84,7 @@
"tailwindcss": "^3.4.4", "tailwindcss": "^3.4.4",
"tar": "^6.2.1", "tar": "^6.2.1",
"tslib": "^2.6.3", "tslib": "^2.6.3",
"typescript": "^5.5.2", "typescript": "^5.5.2"
"vite": "^5.3.1", },
"vite-plugin-environment": "^1.1.3" "packageManager": "[email protected]"
}
} }

944
pnpm-lock.yaml

File diff suppressed because it is too large

30
rsbuild.config.ts

@ -0,0 +1,30 @@
import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
import { execSync } from "node:child_process";
let hash = "";
try {
hash = execSync("git rev-parse --short HEAD").toString().trim();
} catch (error) {
hash = "DEV";
}
export default defineConfig({
plugins: [pluginReact()],
source: {
define: {
"process.env.COMMIT_HASH": JSON.stringify(hash),
},
alias: {
"@app": "./src",
"@pages": "./src/pages",
"@components": "./src/components",
"@core": "./src/core",
"@layouts": "./src/layouts",
},
},
html: {
title: "Meshtastic Web",
},
});

26
src/App.tsx

@ -1,16 +1,17 @@
import { DeviceWrapper } from "@app/DeviceWrapper.js"; import { DeviceWrapper } from "@app/DeviceWrapper.tsx";
import { PageRouter } from "@app/PageRouter.js"; import { PageRouter } from "@app/PageRouter.tsx";
import { CommandPalette } from "@components/CommandPalette.js"; import { CommandPalette } from "@components/CommandPalette.tsx";
import { DeviceSelector } from "@components/DeviceSelector.js"; import { DeviceSelector } from "@components/DeviceSelector.tsx";
import { DialogManager } from "@components/Dialog/DialogManager.js"; import { DialogManager } from "@components/Dialog/DialogManager";
import { NewDeviceDialog } from "@components/Dialog/NewDeviceDialog.js"; import { NewDeviceDialog } from "@components/Dialog/NewDeviceDialog.tsx";
import { Toaster } from "@components/Toaster.js"; import { Toaster } from "@components/Toaster.tsx";
import Footer from "@components/UI/Footer.js"; import Footer from "@components/UI/Footer.tsx";
import { ThemeController } from "@components/generic/ThemeController.js"; import { ThemeController } from "@components/generic/ThemeController.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDeviceStore } from "@core/stores/deviceStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.ts";
import { Dashboard } from "@pages/Dashboard/index.js"; import { Dashboard } from "@pages/Dashboard/index.tsx";
import { MapProvider } from "react-map-gl"; import { MapProvider } from "react-map-gl";
import { KeyBackupReminder } from "@components/KeyBackupReminder";
export const App = (): JSX.Element => { export const App = (): JSX.Element => {
const { getDevice } = useDeviceStore(); const { getDevice } = useDeviceStore();
@ -37,6 +38,7 @@ export const App = (): JSX.Element => {
{device ? ( {device ? (
<div className="flex h-screen"> <div className="flex h-screen">
<DialogManager /> <DialogManager />
<KeyBackupReminder />
<CommandPalette /> <CommandPalette />
<PageRouter /> <PageRouter />
</div> </div>

4
src/DeviceWrapper.tsx

@ -1,5 +1,5 @@
import { DeviceContext } from "@core/stores/deviceStore.js"; import { DeviceContext } from "@core/stores/deviceStore.ts";
import type { Device } from "@core/stores/deviceStore.js"; import type { Device } from "@core/stores/deviceStore.ts";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
export interface DeviceWrapperProps { export interface DeviceWrapperProps {

12
src/PageRouter.tsx

@ -1,9 +1,9 @@
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { ChannelsPage } from "@pages/Channels.js"; import { ChannelsPage } from "@pages/Channels.tsx";
import { ConfigPage } from "@pages/Config/index.js"; import { ConfigPage } from "@pages/Config/index.tsx";
import { MapPage } from "@pages/Map.js"; import { MapPage } from "@pages/Map.tsx";
import { MessagesPage } from "@pages/Messages.js"; import { MessagesPage } from "@pages/Messages.tsx";
import { NodesPage } from "@pages/Nodes.js"; import { NodesPage } from "@pages/Nodes.tsx";
export const PageRouter = (): JSX.Element => { export const PageRouter = (): JSX.Element => {
const { activePage } = useDevice(); const { activePage } = useDevice();

6
src/components/CommandPalette.tsx

@ -5,9 +5,9 @@ import {
CommandInput, CommandInput,
CommandItem, CommandItem,
CommandList, CommandList,
} from "@components/UI/Command.js"; } from "@components/UI/Command.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDevice, useDeviceStore } from "@core/stores/deviceStore.js"; import { useDevice, useDeviceStore } from "@core/stores/deviceStore.ts";
import { Hashicon } from "@emeraldpay/hashicon-react"; import { Hashicon } from "@emeraldpay/hashicon-react";
import { useCommandState } from "cmdk"; import { useCommandState } from "cmdk";
import { import {

10
src/components/DeviceSelector.tsx

@ -1,8 +1,8 @@
import { DeviceSelectorButton } from "@components/DeviceSelectorButton.js"; import { DeviceSelectorButton } from "@components/DeviceSelectorButton.tsx";
import { Separator } from "@components/UI/Seperator.js"; import { Separator } from "@components/UI/Seperator.tsx";
import { Code } from "@components/UI/Typography/Code.js"; import { Code } from "@components/UI/Typography/Code.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDeviceStore } from "@core/stores/deviceStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.ts";
import { Hashicon } from "@emeraldpay/hashicon-react"; import { Hashicon } from "@emeraldpay/hashicon-react";
import { import {
HomeIcon, HomeIcon,

10
src/components/Dialog/DeviceNameDialog.tsx

@ -1,5 +1,5 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@ -7,9 +7,9 @@ import {
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";

21
src/components/Dialog/DialogManager.tsx

@ -1,10 +1,11 @@
import { RemoveNodeDialog } from "@app/components/Dialog/RemoveNodeDialog.js"; import { RemoveNodeDialog } from "@app/components/Dialog/RemoveNodeDialog.tsx";
import { DeviceNameDialog } from "@components/Dialog/DeviceNameDialog.js"; import { DeviceNameDialog } from "@components/Dialog/DeviceNameDialog.tsx";
import { ImportDialog } from "@components/Dialog/ImportDialog.js"; import { ImportDialog } from "@components/Dialog/ImportDialog.tsx";
import { QRDialog } from "@components/Dialog/QRDialog.js"; import { QRDialog } from "@components/Dialog/QRDialog.tsx";
import { RebootDialog } from "@components/Dialog/RebootDialog.js"; import { RebootDialog } from "@components/Dialog/RebootDialog.tsx";
import { ShutdownDialog } from "@components/Dialog/ShutdownDialog.js"; import { ShutdownDialog } from "@components/Dialog/ShutdownDialog.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { PkiBackupDialog } from "@components/Dialog/PKIBackupDialog";
export const DialogManager = (): JSX.Element => { export const DialogManager = (): JSX.Element => {
const { channels, config, dialog, setDialogOpen } = useDevice(); const { channels, config, dialog, setDialogOpen } = useDevice();
@ -49,6 +50,12 @@ export const DialogManager = (): JSX.Element => {
setDialogOpen("nodeRemoval", open); setDialogOpen("nodeRemoval", open);
}} }}
/> />
<PkiBackupDialog
open={dialog.pkiBackup}
onOpenChange={(open) => {
setDialogOpen("pkiBackup", open);
}}
/>
</> </>
); );
}; };

14
src/components/Dialog/ImportDialog.tsx

@ -1,5 +1,5 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { Checkbox } from "@components/UI/Checkbox.js"; import { Checkbox } from "@components/UI/Checkbox.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@ -7,11 +7,11 @@ import {
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
import { Switch } from "@components/UI/Switch.js"; import { Switch } from "@components/UI/Switch.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
import { toByteArray } from "base64-js"; import { toByteArray } from "base64-js";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";

173
src/components/Dialog/NewDeviceDialog.tsx

@ -1,20 +1,26 @@
import { BLE } from "@components/PageComponents/Connect/BLE.js"; import {
import { HTTP } from "@components/PageComponents/Connect/HTTP.js"; type BrowserFeature,
import { Serial } from "@components/PageComponents/Connect/Serial.js"; useBrowserFeatureDetection,
} from "@app/core/hooks/useBrowserFeatureDetection";
import { BLE } from "@components/PageComponents/Connect/BLE.tsx";
import { HTTP } from "@components/PageComponents/Connect/HTTP.tsx";
import { Serial } from "@components/PageComponents/Connect/Serial.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { AlertCircle, InfoIcon, } from "lucide-react";
import { import {
Tabs, Tabs,
TabsContent, TabsContent,
TabsList, TabsList,
TabsTrigger, TabsTrigger,
} from "@components/UI/Tabs.js"; } from "@components/UI/Tabs.tsx";
import { Link } from "@components/UI/Typography/Link.js"; import { Subtle } from "@components/UI/Typography/Subtle.tsx";
import { Subtle } from "@components/UI/Typography/Subtle.js"; import { Link } from "../UI/Typography/Link";
import { Fragment } from "react/jsx-runtime";
export interface TabElementProps { export interface TabElementProps {
closeDialog: () => void; closeDialog: () => void;
@ -23,44 +29,114 @@ export interface TabElementProps {
export interface TabManifest { export interface TabManifest {
label: string; label: string;
element: React.FC<TabElementProps>; element: React.FC<TabElementProps>;
disabled: boolean; isDisabled: boolean;
disabledMessage: string;
disabledLink?: string;
} }
const tabs: TabManifest[] = [
{
label: "HTTP",
element: HTTP,
disabled: false,
disabledMessage: "Unsuported connection method",
},
{
label: "Bluetooth",
element: BLE,
disabled: !navigator.bluetooth,
disabledMessage:
"Web Bluetooth is currently only supported by Chromium-based browsers",
disabledLink:
"https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API#browser_compatibility",
},
{
label: "Serial",
element: Serial,
disabled: !navigator.serial,
disabledMessage:
"WebSerial is currently only supported by Chromium based browsers: https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API#browser_compatibility",
},
];
export interface NewDeviceProps { export interface NewDeviceProps {
open: boolean; open: boolean;
onOpenChange: (open: boolean) => void; onOpenChange: (open: boolean) => void;
} }
interface FeatureErrorProps {
missingFeatures: BrowserFeature[];
}
const links: { [key: string]: string } = {
"Web Bluetooth":
"https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API#browser_compatibility",
"Web Serial":
"https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API#browser_compatibility",
"Secure Context":
"https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts",
};
const listFormatter = new Intl.ListFormat('en', {
style: 'long',
type: 'conjunction'
});
const ErrorMessage = ({ missingFeatures }: FeatureErrorProps) => {
if (missingFeatures.length === 0) return null;
const browserFeatures = missingFeatures.filter(feature => feature !== "Secure Context");
const needsSecureContext = missingFeatures.includes("Secure Context");
const formatFeatureList = (features: string[]) => {
const parts = listFormatter.formatToParts(features);
return parts.map((part) => {
if (part.type === 'element') {
return (
<Link
key={part.value}
href={links[part.value]}
>
{part.value}
</Link>
);
}
return <Fragment key={part.value}>{part.value}</Fragment>;
});
};
return (
<Subtle className="flex flex-col items-start gap-2 text-black bg-red-200/80 p-4 rounded-md">
<div className="flex items-center gap-2 w-full">
<AlertCircle size={40} className="mr-2 flex-shrink-0" />
<div className="flex flex-col gap-3">
<p className="text-sm">
{browserFeatures.length > 0 && (
<>
This application requires {formatFeatureList(browserFeatures)}.
Please use a Chromium-based browser like Chrome or Edge.
</>
)}
{needsSecureContext && (
<>
{browserFeatures.length > 0 && " Additionally, it"}
{browserFeatures.length === 0 && "This application"} requires a{" "}
<Link
href={links["Secure Context"]}
>
secure context
</Link>
. Please connect using HTTPS or localhost.
</>
)}
</p>
</div>
</div>
</Subtle>
);
};
export const NewDeviceDialog = ({ export const NewDeviceDialog = ({
open, open,
onOpenChange, onOpenChange,
}: NewDeviceProps): JSX.Element => { }: NewDeviceProps): JSX.Element => {
const { unsupported } = useBrowserFeatureDetection();
const tabs: TabManifest[] = [
{
label: "HTTP",
element: HTTP,
isDisabled: false,
},
{
label: "Bluetooth",
element: BLE,
isDisabled:
unsupported.includes("Web Bluetooth") ||
unsupported.includes("Secure Context"),
},
{
label: "Serial",
element: Serial,
isDisabled:
unsupported.includes("Web Serial") ||
unsupported.includes("Secure Context"),
},
];
return ( return (
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent> <DialogContent>
@ -73,7 +149,6 @@ export const NewDeviceDialog = ({
<TabsTrigger <TabsTrigger
key={tab.label} key={tab.label}
value={tab.label} value={tab.label}
disabled={tab.disabled}
> >
{tab.label} {tab.label}
</TabsTrigger> </TabsTrigger>
@ -81,35 +156,13 @@ export const NewDeviceDialog = ({
</TabsList> </TabsList>
{tabs.map((tab) => ( {tabs.map((tab) => (
<TabsContent key={tab.label} value={tab.label}> <TabsContent key={tab.label} value={tab.label}>
{tab.disabled ? ( <fieldset disabled={tab.isDisabled}>
<p className="text-sm text-slate-500 dark:text-slate-400"> {tab.isDisabled ? <ErrorMessage missingFeatures={unsupported} /> : null}
{tab.disabledMessage}
</p>
) : (
<tab.element closeDialog={() => onOpenChange(false)} /> <tab.element closeDialog={() => onOpenChange(false)} />
)} </fieldset>
</TabsContent> </TabsContent>
))} ))}
</Tabs> </Tabs>
{(!navigator.bluetooth || !navigator.serial) && (
<>
<Subtle>
Web Bluetooth and Web Serial are currently only supported by
Chromium-based browsers.
</Subtle>
<Subtle>
Read more:&nbsp;
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API#browser_compatibility">
Web Bluetooth
</Link>
&nbsp;
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API#browser_compatibility">
Web Serial
</Link>
</Subtle>
</>
)}
</DialogContent> </DialogContent>
</Dialog> </Dialog>
); );

134
src/components/Dialog/PKIBackupDialog.tsx

@ -0,0 +1,134 @@
import { useDevice } from "@app/core/stores/deviceStore";
import { Button } from "@components/UI/Button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@components/UI/Dialog.tsx";
import { fromByteArray } from "base64-js";
import { DownloadIcon, PrinterIcon } from "lucide-react";
import React from "react";
export interface PkiBackupDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}
export const PkiBackupDialog = ({
open,
onOpenChange,
}: PkiBackupDialogProps) => {
const { config, setDialogOpen } = useDevice();
const privateKey = config.security?.privateKey;
const publicKey = config.security?.publicKey;
const decodeKeyData = React.useCallback(
(key: Uint8Array<ArrayBufferLike>) => {
if (!key) return "";
return fromByteArray(key ?? new Uint8Array(0));
},
[],
);
const closeDialog = React.useCallback(() => {
setDialogOpen("pkiBackup", false);
}, [setDialogOpen]);
const renderPrintWindow = React.useCallback(() => {
if (!privateKey || !publicKey) return;
const printWindow = window.open("", "_blank");
if (printWindow) {
printWindow.document.write(`
<html>
<head>
<title>=== MESHTASTIC KEYS ===</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
h1 { font-size: 18px; }
p { font-size: 14px; word-break: break-all; }
</style>
</head>
<body>
<h1>=== MESHTASTIC KEYS ===</h1>
<br>
<h2>Public Key:</h2>
<p>${decodeKeyData(publicKey)}</p>
<h2>Private Key:</h2>
<p>${decodeKeyData(privateKey)}</p>
<br>
<p>=== END OF KEYS ===</p>
</body>
</html>
`);
printWindow.document.close();
printWindow.print();
closeDialog();
}
}, [decodeKeyData, privateKey, publicKey, closeDialog]);
const createDownloadKeyFile = React.useCallback(() => {
if (!privateKey || !publicKey) return;
const decodedPrivateKey = decodeKeyData(privateKey);
const decodedPublicKey = decodeKeyData(publicKey);
const formattedContent = [
"=== MESHTASTIC KEYS ===\n\n",
"Private Key:\n",
decodedPrivateKey,
"\n\nPublic Key:\n",
decodedPublicKey,
"\n\n=== END OF KEYS ===",
].join("");
const blob = new Blob([formattedContent], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "meshtastic_keys.txt";
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
closeDialog();
URL.revokeObjectURL(url);
}, [decodeKeyData, privateKey, publicKey, closeDialog]);
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Backup Keys</DialogTitle>
<DialogDescription>
Its important to backup your public and private keys and store your
backup securely!
</DialogDescription>
<DialogDescription>
<span className="font-bold break-before-auto">
If you lose your keys, you will need to reset your device.
</span>
</DialogDescription>
</DialogHeader>
<DialogFooter className="mt-6">
<Button
variant={"default"}
onClick={() => createDownloadKeyFile()}
className=""
>
<DownloadIcon size={20} className="mr-2" />
Download
</Button>
<Button variant={"default"} onClick={() => renderPrintWindow()}>
<PrinterIcon size={20} className="mr-2" />
Print
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};

4
src/components/Dialog/PkiRegenerateDialog.tsx

@ -1,4 +1,4 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@ -6,7 +6,7 @@ import {
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
export interface PkiRegenerateDialogProps { export interface PkiRegenerateDialogProps {
open: boolean; open: boolean;

8
src/components/Dialog/QRDialog.tsx

@ -1,4 +1,4 @@
import { Checkbox } from "@components/UI/Checkbox.js"; import { Checkbox } from "@components/UI/Checkbox.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@ -6,9 +6,9 @@ import {
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
import { Protobuf, type Types } from "@meshtastic/js"; import { Protobuf, type Types } from "@meshtastic/js";
import { fromByteArray } from "base64-js"; import { fromByteArray } from "base64-js";
import { ClipboardIcon } from "lucide-react"; import { ClipboardIcon } from "lucide-react";

8
src/components/Dialog/RebootDialog.tsx

@ -1,13 +1,13 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription, DialogDescription,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { ClockIcon, RefreshCwIcon } from "lucide-react"; import { ClockIcon, RefreshCwIcon } from "lucide-react";
import { useState } from "react"; import { useState } from "react";

8
src/components/Dialog/RemoveNodeDialog.tsx

@ -1,6 +1,6 @@
import { useAppStore } from "@app/core/stores/appStore"; import { useAppStore } from "@app/core/stores/appStore";
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@ -8,8 +8,8 @@ import {
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
export interface RemoveNodeDialogProps { export interface RemoveNodeDialogProps {
open: boolean; open: boolean;

8
src/components/Dialog/ShutdownDialog.tsx

@ -1,13 +1,13 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription, DialogDescription,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@components/UI/Dialog.js"; } from "@components/UI/Dialog.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { ClockIcon, PowerIcon } from "lucide-react"; import { ClockIcon, PowerIcon } from "lucide-react";
import { useState } from "react"; import { useState } from "react";

10
src/components/Form/DynamicForm.tsx

@ -1,11 +1,11 @@
import { import {
DynamicFormField, DynamicFormField,
type FieldProps, type FieldProps,
} from "@components/Form/DynamicFormField.js"; } from "@components/Form/DynamicFormField.tsx";
import { FieldWrapper } from "@components/Form/FormWrapper.js"; import { FieldWrapper } from "@components/Form/FormWrapper.tsx";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { H4 } from "@components/UI/Typography/H4.js"; import { H4 } from "@components/UI/Typography/H4.tsx";
import { Subtle } from "@components/UI/Typography/Subtle.js"; import { Subtle } from "@components/UI/Typography/Subtle.tsx";
import { import {
type Control, type Control,
type DefaultValues, type DefaultValues,

8
src/components/Form/DynamicFormField.tsx

@ -1,19 +1,19 @@
import { import {
GenericInput, GenericInput,
type InputFieldProps, type InputFieldProps,
} from "@components/Form/FormInput.js"; } from "@components/Form/FormInput.tsx";
import { import {
PasswordGenerator, PasswordGenerator,
type PasswordGeneratorProps, type PasswordGeneratorProps,
} from "@components/Form/FormPasswordGenerator.js"; } from "@components/Form/FormPasswordGenerator.tsx";
import { import {
type SelectFieldProps, type SelectFieldProps,
SelectInput, SelectInput,
} from "@components/Form/FormSelect.js"; } from "@components/Form/FormSelect.tsx";
import { import {
type ToggleFieldProps, type ToggleFieldProps,
ToggleInput, ToggleInput,
} from "@components/Form/FormToggle.js"; } from "@components/Form/FormToggle.tsx";
import type { Control, FieldValues } from "react-hook-form"; import type { Control, FieldValues } from "react-hook-form";
export type FieldProps<T> = export type FieldProps<T> =

23
src/components/Form/FormInput.tsx

@ -1,10 +1,12 @@
import type { import type {
BaseFormBuilderProps, BaseFormBuilderProps,
GenericFormElementProps, GenericFormElementProps,
} from "@components/Form/DynamicForm.js"; } from "@components/Form/DynamicForm.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import type { LucideIcon } from "lucide-react"; import type { LucideIcon } from "lucide-react";
import { Eye, EyeOff } from "lucide-react";
import type { ChangeEventHandler } from "react"; import type { ChangeEventHandler } from "react";
import { useState } from "react";
import { Controller, type FieldValues } from "react-hook-form"; import { Controller, type FieldValues } from "react-hook-form";
export interface InputFieldProps<T> extends BaseFormBuilderProps<T> { export interface InputFieldProps<T> extends BaseFormBuilderProps<T> {
@ -27,13 +29,28 @@ export function GenericInput<T extends FieldValues>({
disabled, disabled,
field, field,
}: GenericFormElementProps<T, InputFieldProps<T>>) { }: GenericFormElementProps<T, InputFieldProps<T>>) {
const [passwordShown, setPasswordShown] = useState(false);
const togglePasswordVisiblity = () => {
setPasswordShown(!passwordShown);
};
return ( return (
<Controller <Controller
name={field.name} name={field.name}
control={control} control={control}
render={({ field: { value, onChange, ...rest } }) => ( render={({ field: { value, onChange, ...rest } }) => (
<Input <Input
type={field.type} type={
field.type === "password" && passwordShown ? "text" : field.type
}
action={
field.type === "password"
? {
icon: passwordShown ? EyeOff : Eye,
onClick: togglePasswordVisiblity,
}
: undefined
}
step={field.properties?.step} step={field.properties?.step}
value={field.type === "number" ? Number.parseFloat(value) : value} value={field.type === "number" ? Number.parseFloat(value) : value}
onChange={(e) => { onChange={(e) => {

32
src/components/Form/FormPasswordGenerator.tsx

@ -1,10 +1,13 @@
import type { import type {
BaseFormBuilderProps, BaseFormBuilderProps,
GenericFormElementProps, GenericFormElementProps,
} from "@components/Form/DynamicForm.js"; } from "@components/Form/DynamicForm.tsx";
import { Generator } from "@components/UI/Generator.js"; import { Generator } from "@components/UI/Generator.tsx";
import { Eye, EyeOff } from "lucide-react";
import type { ChangeEventHandler, MouseEventHandler } from "react"; import type { ChangeEventHandler, MouseEventHandler } from "react";
import { useState } from "react";
import { Controller, type FieldValues } from "react-hook-form"; import { Controller, type FieldValues } from "react-hook-form";
import type { ButtonVariant } from "@components/UI/Button";
export interface PasswordGeneratorProps<T> extends BaseFormBuilderProps<T> { export interface PasswordGeneratorProps<T> extends BaseFormBuilderProps<T> {
type: "passwordGenerator"; type: "passwordGenerator";
@ -13,7 +16,12 @@ export interface PasswordGeneratorProps<T> extends BaseFormBuilderProps<T> {
devicePSKBitCount: number; devicePSKBitCount: number;
inputChange: ChangeEventHandler; inputChange: ChangeEventHandler;
selectChange: (event: string) => void; selectChange: (event: string) => void;
buttonClick: MouseEventHandler; actionButtons: {
text: string;
onClick: React.MouseEventHandler<HTMLButtonElement>;
variant: ButtonVariant;
className?: string;
}[];
} }
export function PasswordGenerator<T extends FieldValues>({ export function PasswordGenerator<T extends FieldValues>({
@ -21,21 +29,33 @@ export function PasswordGenerator<T extends FieldValues>({
field, field,
disabled, disabled,
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) { }: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
const [passwordShown, setPasswordShown] = useState(false);
const togglePasswordVisiblity = () => {
setPasswordShown(!passwordShown);
};
return ( return (
<Controller <Controller
name={field.name} name={field.name}
control={control} control={control}
render={({ field: { value, ...rest } }) => ( render={({ field: { value, ...rest } }) => (
<Generator <Generator
hide={field.hide} type={field.hide && !passwordShown ? "password" : "text"}
action={
field.hide
? {
icon: passwordShown ? EyeOff : Eye,
onClick: togglePasswordVisiblity,
}
: undefined
}
devicePSKBitCount={field.devicePSKBitCount} devicePSKBitCount={field.devicePSKBitCount}
bits={field.bits} bits={field.bits}
inputChange={field.inputChange} inputChange={field.inputChange}
selectChange={field.selectChange} selectChange={field.selectChange}
buttonClick={field.buttonClick}
value={value} value={value}
variant={field.validationText ? "invalid" : "default"} variant={field.validationText ? "invalid" : "default"}
buttonText="Generate" actionButtons={field.actionButtons}
{...field.properties} {...field.properties}
{...rest} {...rest}
disabled={disabled} disabled={disabled}

4
src/components/Form/FormSelect.tsx

@ -1,14 +1,14 @@
import type { import type {
BaseFormBuilderProps, BaseFormBuilderProps,
GenericFormElementProps, GenericFormElementProps,
} from "@components/Form/DynamicForm.js"; } from "@components/Form/DynamicForm.tsx";
import { import {
Select, Select,
SelectContent, SelectContent,
SelectItem, SelectItem,
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@components/UI/Select.js"; } from "@components/UI/Select.tsx";
import { Controller, type FieldValues } from "react-hook-form"; import { Controller, type FieldValues } from "react-hook-form";
export interface SelectFieldProps<T> extends BaseFormBuilderProps<T> { export interface SelectFieldProps<T> extends BaseFormBuilderProps<T> {

4
src/components/Form/FormToggle.tsx

@ -1,8 +1,8 @@
import type { import type {
BaseFormBuilderProps, BaseFormBuilderProps,
GenericFormElementProps, GenericFormElementProps,
} from "@components/Form/DynamicForm.js"; } from "@components/Form/DynamicForm.tsx";
import { Switch } from "@components/UI/Switch.js"; import { Switch } from "@components/UI/Switch.tsx";
import type { ChangeEvent } from "react"; import type { ChangeEvent } from "react";
import { Controller, type FieldValues } from "react-hook-form"; import { Controller, type FieldValues } from "react-hook-form";

2
src/components/Form/FormWrapper.tsx

@ -1,4 +1,4 @@
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
export interface FieldWrapperProps { export interface FieldWrapperProps {
label: string; label: string;

19
src/components/KeyBackupReminder.tsx

@ -0,0 +1,19 @@
import { useBackupReminder } from "@app/core/hooks/useKeyBackupReminder";
import { useDevice } from "@app/core/stores/deviceStore";
export const KeyBackupReminder = (): JSX.Element => {
const { setDialogOpen } = useDevice();
useBackupReminder({
reminderInDays: 7,
message:
"We recommend backing up your key data regularly. Would you like to back up now?",
onAccept: () => setDialogOpen("pkiBackup", true),
enabled: true,
cookieOptions: {
secure: true,
sameSite: "strict",
},
});
return <></>;
};

223
src/components/PageComponents/Channel.tsx

@ -1,11 +1,12 @@
import type { ChannelValidation } from "@app/validation/channel.js"; import type { ChannelValidation } from "@app/validation/channel.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useToast } from "@core/hooks/useToast.js"; import { useToast } from "@core/hooks/useToast.ts";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
import { fromByteArray, toByteArray } from "base64-js"; import { fromByteArray, toByteArray } from "base64-js";
import cryptoRandomString from "crypto-random-string"; import cryptoRandomString from "crypto-random-string";
import { useState } from "react"; import { useState } from "react";
import { PkiRegenerateDialog } from "../Dialog/PkiRegenerateDialog";
export interface SettingsPanelProps { export interface SettingsPanelProps {
channel: Protobuf.Channel.Channel; channel: Protobuf.Channel.Channel;
@ -22,6 +23,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
channel?.settings?.psk.length ?? 16, channel?.settings?.psk.length ?? 16,
); );
const [validationText, setValidationText] = useState<string>(); const [validationText, setValidationText] = useState<string>();
const [preSharedDialogOpen, setPreSharedDialogOpen] = useState<boolean>(false);
const onSubmit = (data: ChannelValidation) => { const onSubmit = (data: ChannelValidation) => {
const channel = new Protobuf.Channel.Channel({ const channel = new Protobuf.Channel.Channel({
@ -46,7 +48,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}); });
}; };
const clickEvent = () => { const preSharedKeyRegenerate = () => {
setPass( setPass(
btoa( btoa(
cryptoRandomString({ cryptoRandomString({
@ -56,6 +58,11 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
), ),
); );
setValidationText(undefined); setValidationText(undefined);
setPreSharedDialogOpen(false);
};
const preSharedClickEvent = () => {
setPreSharedDialogOpen(true);
}; };
const validatePass = (input: string, count: number) => { const validatePass = (input: string, count: number) => {
@ -79,103 +86,105 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}; };
return ( return (
<DynamicForm<ChannelValidation> <>
onSubmit={onSubmit} <DynamicForm<ChannelValidation>
submitType="onSubmit" onSubmit={onSubmit}
hasSubmitButton={true} submitType="onSubmit"
defaultValues={{ hasSubmitButton={true}
...channel, defaultValues={{
...{ ...channel,
settings: { ...{
...channel?.settings, settings: {
psk: pass, ...channel?.settings,
positionEnabled: psk: pass,
channel?.settings?.moduleSettings?.positionPrecision !== positionEnabled:
channel?.settings?.moduleSettings?.positionPrecision !==
undefined && undefined &&
channel?.settings?.moduleSettings?.positionPrecision > 0, channel?.settings?.moduleSettings?.positionPrecision > 0,
preciseLocation: preciseLocation:
channel?.settings?.moduleSettings?.positionPrecision === 32, channel?.settings?.moduleSettings?.positionPrecision === 32,
positionPrecision: positionPrecision:
channel?.settings?.moduleSettings?.positionPrecision === undefined channel?.settings?.moduleSettings?.positionPrecision === undefined
? 10 ? 10
: channel?.settings?.moduleSettings?.positionPrecision, : channel?.settings?.moduleSettings?.positionPrecision,
},
}, },
}, }}
}} fieldGroups={[
fieldGroups={[ {
{ label: "Channel Settings",
label: "Channel Settings", description: "Crypto, MQTT & misc settings",
description: "Crypto, MQTT & misc settings", fields: [
fields: [ {
{ type: "select",
type: "select", name: "role",
name: "role", label: "Role",
label: "Role", disabled: channel.index === 0,
disabled: channel.index === 0, description:
description: "Device telemetry is sent over PRIMARY. Only one PRIMARY allowed",
"Device telemetry is sent over PRIMARY. Only one PRIMARY allowed", properties: {
properties: { enumValue:
enumValue: channel.index === 0
channel.index === 0 ? { PRIMARY: 1 }
? { PRIMARY: 1 } : { DISABLED: 0, SECONDARY: 2 },
: { DISABLED: 0, SECONDARY: 2 }, },
}, },
}, {
{ type: "passwordGenerator",
type: "passwordGenerator", name: "settings.psk",
name: "settings.psk", label: "Pre-Shared Key",
label: "pre-Shared Key", description: "Supported PSK lengths: 256-bit, 128-bit, 8-bit, Empty (0-bit)",
description: "256, 128, or 8 bit PSKs allowed", validationText: validationText,
validationText: validationText, devicePSKBitCount: bitCount ?? 0,
devicePSKBitCount: bitCount ?? 0, inputChange: inputChangeEvent,
inputChange: inputChangeEvent, selectChange: selectChangeEvent,
selectChange: selectChangeEvent, actionButtons: [{ text: 'Generate', variant: 'success', onClick: preSharedClickEvent }],
buttonClick: clickEvent, hide: true,
properties: { properties: {
value: pass, value: pass,
},
}, },
}, {
{ type: "text",
type: "text", name: "settings.name",
name: "settings.name", label: "Name",
label: "Name", description:
description: "A unique name for the channel <12 bytes, leave blank for default",
"A unique name for the channel <12 bytes, leave blank for default", },
}, {
{ type: "toggle",
type: "toggle", name: "settings.uplinkEnabled",
name: "settings.uplinkEnabled", label: "Uplink Enabled",
label: "Uplink Enabled", description: "Send messages from the local mesh to MQTT",
description: "Send messages from the local mesh to MQTT", },
}, {
{ type: "toggle",
type: "toggle", name: "settings.downlinkEnabled",
name: "settings.downlinkEnabled", label: "Downlink Enabled",
label: "Downlink Enabled", description: "Send messages from MQTT to the local mesh",
description: "Send messages from MQTT to the local mesh", },
}, {
{ type: "toggle",
type: "toggle", name: "settings.positionEnabled",
name: "settings.positionEnabled", label: "Allow Position Requests",
label: "Allow Position Requests", description: "Send position to channel",
description: "Send position to channel", },
}, {
{ type: "toggle",
type: "toggle", name: "settings.preciseLocation",
name: "settings.preciseLocation", label: "Precise Location",
label: "Precise Location", description: "Send precise location to channel",
description: "Send precise location to channel", },
}, {
{ type: "select",
type: "select", name: "settings.positionPrecision",
name: "settings.positionPrecision", label: "Approximate Location",
label: "Approximate Location", description:
description: "If not sharing precise location, position shared on channel will be accurate within this distance",
"If not sharing precise location, position shared on channel will be accurate within this distance", properties: {
properties: { enumValue:
enumValue: config.display?.units === 0
config.display?.units === 0 ? {
? {
"Within 23 km": 10, "Within 23 km": 10,
"Within 12 km": 11, "Within 12 km": 11,
"Within 5.8 km": 12, "Within 5.8 km": 12,
@ -187,7 +196,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
"Within 90 m": 18, "Within 90 m": 18,
"Within 50 m": 19, "Within 50 m": 19,
} }
: { : {
"Within 15 miles": 10, "Within 15 miles": 10,
"Within 7.3 miles": 11, "Within 7.3 miles": 11,
"Within 3.6 miles": 12, "Within 3.6 miles": 12,
@ -199,11 +208,17 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
"Within 300 feet": 18, "Within 300 feet": 18,
"Within 150 feet": 19, "Within 150 feet": 19,
}, },
},
}, },
}, ],
], },
}, ]}
]} />
/> <PkiRegenerateDialog
open={preSharedDialogOpen}
onOpenChange={() => setPreSharedDialogOpen(false)}
onSubmit={() => preSharedKeyRegenerate()}
/>
</>
); );
}; };

23
src/components/PageComponents/Config/Bluetooth.tsx

@ -1,10 +1,25 @@
import type { BluetoothValidation } from "@app/validation/config/bluetooth.js"; import type { BluetoothValidation } from "@app/validation/config/bluetooth.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
import { useState } from "react";
export const Bluetooth = (): JSX.Element => { export const Bluetooth = (): JSX.Element => {
const { config, setWorkingConfig } = useDevice(); const { config, setWorkingConfig } = useDevice();
const [bluetoothValidationText, setBluetoothValidationText] = useState<string>();
const bluetoothPinChangeEvent = (
e: React.ChangeEvent<HTMLInputElement>,
) => {
if (e.target.value[0] == "0")
{
setBluetoothValidationText("Bluetooth Pin cannot start with 0.");
}
else
{
setBluetoothValidationText("");
}
}
const onSubmit = (data: BluetoothValidation) => { const onSubmit = (data: BluetoothValidation) => {
setWorkingConfig( setWorkingConfig(
@ -52,6 +67,8 @@ export const Bluetooth = (): JSX.Element => {
name: "fixedPin", name: "fixedPin",
label: "Pin", label: "Pin",
description: "Pin to use when pairing", description: "Pin to use when pairing",
validationText: bluetoothValidationText,
inputChange: bluetoothPinChangeEvent,
disabledBy: [ disabledBy: [
{ {
fieldName: "mode", fieldName: "mode",

29
src/components/PageComponents/Config/Device.tsx

@ -1,6 +1,6 @@
import type { DeviceValidation } from "@app/validation/config/device.js"; import type { DeviceValidation } from "@app/validation/config/device.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Device = (): JSX.Element => { export const Device = (): JSX.Element => {
@ -32,7 +32,22 @@ export const Device = (): JSX.Element => {
label: "Role", label: "Role",
description: "What role the device performs on the mesh", description: "What role the device performs on the mesh",
properties: { properties: {
enumValue: Protobuf.Config.Config_DeviceConfig_Role, enumValue: {
Client: Protobuf.Config.Config_DeviceConfig_Role.CLIENT,
"Client Mute":
Protobuf.Config.Config_DeviceConfig_Role.CLIENT_MUTE,
Router: Protobuf.Config.Config_DeviceConfig_Role.ROUTER,
Repeater: Protobuf.Config.Config_DeviceConfig_Role.REPEATER,
Tracker: Protobuf.Config.Config_DeviceConfig_Role.TRACKER,
Sensor: Protobuf.Config.Config_DeviceConfig_Role.SENSOR,
TAK: Protobuf.Config.Config_DeviceConfig_Role.TAK,
"Client Hidden":
Protobuf.Config.Config_DeviceConfig_Role.CLIENT_HIDDEN,
"Lost and Found":
Protobuf.Config.Config_DeviceConfig_Role.LOST_AND_FOUND,
"TAK Tracker":
Protobuf.Config.Config_DeviceConfig_Role.SENSOR,
},
formatEnumName: true, formatEnumName: true,
}, },
}, },
@ -79,6 +94,12 @@ export const Device = (): JSX.Element => {
label: "Disable Triple Click", label: "Disable Triple Click",
description: "Disable triple click", description: "Disable triple click",
}, },
{
type: "toggle",
name: "ledHeartbeatDisabled",
label: "LED Heartbeat Disabled",
description: "Disable default blinking LED",
},
], ],
}, },
]} ]}

6
src/components/PageComponents/Config/Display.tsx

@ -1,6 +1,6 @@
import type { DisplayValidation } from "@app/validation/config/display.js"; import type { DisplayValidation } from "@app/validation/config/display.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Display = (): JSX.Element => { export const Display = (): JSX.Element => {

6
src/components/PageComponents/Config/LoRa.tsx

@ -1,6 +1,6 @@
import type { LoRaValidation } from "@app/validation/config/lora.js"; import type { LoRaValidation } from "@app/validation/config/lora.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const LoRa = (): JSX.Element => { export const LoRa = (): JSX.Element => {

8
src/components/PageComponents/Config/Network.tsx

@ -1,10 +1,10 @@
import type { NetworkValidation } from "@app/validation/config/network.js"; import type { NetworkValidation } from "@app/validation/config/network.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { import {
convertIntToIpAddress, convertIntToIpAddress,
convertIpAddressToInt, convertIpAddressToInt,
} from "@core/utils/ip.js"; } from "@core/utils/ip.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Network = (): JSX.Element => { export const Network = (): JSX.Element => {

12
src/components/PageComponents/Config/Position.tsx

@ -1,6 +1,6 @@
import type { PositionValidation } from "@app/validation/config/position.js"; import type { PositionValidation } from "@app/validation/config/position.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Position = (): JSX.Element => { export const Position = (): JSX.Element => {
@ -77,12 +77,6 @@ export const Position = (): JSX.Element => {
label: "Enable Pin", label: "Enable Pin",
description: "GPS module enable pin override", description: "GPS module enable pin override",
}, },
{
type: "number",
name: "channelPrecision",
label: "Channel Precision",
description: "GPS channel precision",
},
], ],
}, },
{ {

6
src/components/PageComponents/Config/Power.tsx

@ -1,6 +1,6 @@
import type { PowerValidation } from "@app/validation/config/power.js"; import type { PowerValidation } from "@app/validation/config/power.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Power = (): JSX.Element => { export const Power = (): JSX.Element => {

37
src/components/PageComponents/Config/Security.tsx

@ -1,18 +1,18 @@
import { PkiRegenerateDialog } from "@app/components/Dialog/PkiRegenerateDialog"; import { PkiRegenerateDialog } from "@app/components/Dialog/PkiRegenerateDialog";
import { DynamicForm } from "@app/components/Form/DynamicForm.js"; import { DynamicForm } from "@app/components/Form/DynamicForm.tsx";
import { import {
getX25519PrivateKey, getX25519PrivateKey,
getX25519PublicKey, getX25519PublicKey,
} from "@app/core/utils/x25519"; } from "@app/core/utils/x25519";
import type { SecurityValidation } from "@app/validation/config/security.js"; import type { SecurityValidation } from "@app/validation/config/security.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
import { fromByteArray, toByteArray } from "base64-js"; import { fromByteArray, toByteArray } from "base64-js";
import { Eye, EyeOff } from "lucide-react"; import { Eye, EyeOff } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
export const Security = (): JSX.Element => { export const Security = (): JSX.Element => {
const { config, nodes, hardware, setWorkingConfig } = useDevice(); const { config, nodes, hardware, setWorkingConfig, setDialogOpen } = useDevice();
const [privateKey, setPrivateKey] = useState<string>( const [privateKey, setPrivateKey] = useState<string>(
fromByteArray(config.security?.privateKey ?? new Uint8Array(0)), fromByteArray(config.security?.privateKey ?? new Uint8Array(0)),
@ -31,7 +31,7 @@ export const Security = (): JSX.Element => {
); );
const [adminKeyValidationText, setAdminKeyValidationText] = const [adminKeyValidationText, setAdminKeyValidationText] =
useState<string>(); useState<string>();
const [dialogOpen, setDialogOpen] = useState<boolean>(false); const [privateKeyDialogOpen, setPrivateKeyDialogOpen] = useState<boolean>(false);
const onSubmit = (data: SecurityValidation) => { const onSubmit = (data: SecurityValidation) => {
if (privateKeyValidationText || adminKeyValidationText) return; if (privateKeyValidationText || adminKeyValidationText) return;
@ -71,9 +71,13 @@ export const Security = (): JSX.Element => {
}; };
const privateKeyClickEvent = () => { const privateKeyClickEvent = () => {
setDialogOpen(true); setPrivateKeyDialogOpen(true);
}; };
const pkiBackupClickEvent = () => {
setDialogOpen("pkiBackup", true);
}
const pkiRegenerate = () => { const pkiRegenerate = () => {
const privateKey = getX25519PrivateKey(); const privateKey = getX25519PrivateKey();
const publicKey = getX25519PublicKey(privateKey); const publicKey = getX25519PublicKey(privateKey);
@ -86,7 +90,7 @@ export const Security = (): JSX.Element => {
setPrivateKeyValidationText, setPrivateKeyValidationText,
); );
setDialogOpen(false); setPrivateKeyDialogOpen(false);
}; };
const privateKeyInputChangeEvent = ( const privateKeyInputChangeEvent = (
@ -149,7 +153,18 @@ export const Security = (): JSX.Element => {
inputChange: privateKeyInputChangeEvent, inputChange: privateKeyInputChangeEvent,
selectChange: privateKeySelectChangeEvent, selectChange: privateKeySelectChangeEvent,
hide: !privateKeyVisible, hide: !privateKeyVisible,
buttonClick: privateKeyClickEvent, actionButtons: [
{
text: "Generate",
onClick: privateKeyClickEvent,
variant: "success",
},
{
text: "Backup Key",
onClick: pkiBackupClickEvent,
variant: "subtle",
},
],
properties: { properties: {
value: privateKey, value: privateKey,
action: { action: {
@ -187,7 +202,7 @@ export const Security = (): JSX.Element => {
name: "isManaged", name: "isManaged",
label: "Managed", label: "Managed",
description: description:
'If true, device is considered to be "managed" by a mesh administrator via admin messages', 'If true, device configuration options are only able to be changed remotely by a Remote Admin node via admin messages. Do not enable this option unless a suitable Remote Admin node has been setup, and the public key stored in the field below.',
}, },
{ {
type: "text", type: "text",
@ -228,8 +243,8 @@ export const Security = (): JSX.Element => {
]} ]}
/> />
<PkiRegenerateDialog <PkiRegenerateDialog
open={dialogOpen} open={privateKeyDialogOpen}
onOpenChange={() => setDialogOpen(false)} onOpenChange={() => setPrivateKeyDialogOpen(false)}
onSubmit={() => pkiRegenerate()} onSubmit={() => pkiRegenerate()}
/> />
</> </>

12
src/components/PageComponents/Connect/BLE.tsx

@ -1,10 +1,10 @@
import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog"; import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { Mono } from "@components/generic/Mono.js"; import { Mono } from "@components/generic/Mono.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDeviceStore } from "@core/stores/deviceStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.ts";
import { subscribeAll } from "@core/subscriptions.js"; import { subscribeAll } from "@core/subscriptions.ts";
import { randId } from "@core/utils/randId.js"; import { randId } from "@core/utils/randId.ts";
import { BleConnection, Constants } from "@meshtastic/js"; import { BleConnection, Constants } from "@meshtastic/js";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";

16
src/components/PageComponents/Connect/HTTP.tsx

@ -1,12 +1,12 @@
import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog"; import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { Label } from "@components/UI/Label.js"; import { Label } from "@components/UI/Label.tsx";
import { Switch } from "@components/UI/Switch.js"; import { Switch } from "@components/UI/Switch.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDeviceStore } from "@core/stores/deviceStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.ts";
import { subscribeAll } from "@core/subscriptions.js"; import { subscribeAll } from "@core/subscriptions.ts";
import { randId } from "@core/utils/randId.js"; import { randId } from "@core/utils/randId.ts";
import { HttpConnection } from "@meshtastic/js"; import { HttpConnection } from "@meshtastic/js";
import { useState } from "react"; import { useState } from "react";
import { Controller, useForm, useWatch } from "react-hook-form"; import { Controller, useForm, useWatch } from "react-hook-form";

23
src/components/PageComponents/Connect/Serial.tsx

@ -1,10 +1,10 @@
import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog"; import type { TabElementProps } from "@app/components/Dialog/NewDeviceDialog";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { Mono } from "@components/generic/Mono.js"; import { Mono } from "@components/generic/Mono.tsx";
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import { useDeviceStore } from "@core/stores/deviceStore.js"; import { useDeviceStore } from "@core/stores/deviceStore.ts";
import { subscribeAll } from "@core/subscriptions.js"; import { subscribeAll } from "@core/subscriptions.ts";
import { randId } from "@core/utils/randId.js"; import { randId } from "@core/utils/randId.ts";
import { SerialConnection } from "@meshtastic/js"; import { SerialConnection } from "@meshtastic/js";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
@ -14,13 +14,13 @@ export const Serial = ({ closeDialog }: TabElementProps): JSX.Element => {
const { setSelectedDevice } = useAppStore(); const { setSelectedDevice } = useAppStore();
const updateSerialPortList = useCallback(async () => { const updateSerialPortList = useCallback(async () => {
setSerialPorts(await navigator.serial.getPorts()); setSerialPorts(await navigator?.serial.getPorts());
}, []); }, []);
navigator.serial.addEventListener("connect", () => { navigator?.serial?.addEventListener("connect", () => {
updateSerialPortList(); updateSerialPortList();
}); });
navigator.serial.addEventListener("disconnect", () => { navigator?.serial?.addEventListener("disconnect", () => {
updateSerialPortList(); updateSerialPortList();
}); });
useEffect(() => { useEffect(() => {
@ -58,9 +58,8 @@ export const Serial = ({ closeDialog }: TabElementProps): JSX.Element => {
await onConnect(port); await onConnect(port);
}} }}
> >
{`# ${index} - ${usbVendorId ?? "UNK"} - ${ {`# ${index} - ${usbVendorId ?? "UNK"} - ${usbProductId ?? "UNK"
usbProductId ?? "UNK" }`}
}`}
</Button> </Button>
); );
})} })}

171
src/components/PageComponents/Map/NodeDetail.tsx

@ -0,0 +1,171 @@
import { Mono } from "@components/generic/Mono.tsx";
import { H5 } from "@app/components/UI/Typography/H5.tsx";
import { Subtle } from "@app/components/UI/Typography/Subtle.tsx";
import { Separator } from "@app/components/UI/Seperator";
import { TimeAgo } from "@components/generic/Table/tmp/TimeAgo.tsx";
import { Hashicon } from "@emeraldpay/hashicon-react";
import { Protobuf } from "@meshtastic/js";
import type { Protobuf as ProtobufType } from "@meshtastic/js";
import {
BatteryChargingIcon,
BatteryFullIcon,
BatteryLowIcon,
BatteryMediumIcon,
Dot,
LockIcon,
LockOpenIcon,
MountainSnow,
Star,
} from "lucide-react";
import { numberToHexUnpadded } from "@noble/curves/abstract/utils";
export interface NodeDetailProps {
node: ProtobufType.Mesh.NodeInfo;
}
export const NodeDetail = ({ node }: NodeDetailProps): JSX.Element => {
const name = node.user?.longName || `!${numberToHexUnpadded(node.num)}`;
const hardwareType = Protobuf.Mesh.HardwareModel[
node.user?.hwModel ?? 0
].replaceAll("_", " ");
return (
<div className="dark:text-black">
<div className="flex gap-2">
<div className="flex flex-col items-center gap-2 min-w-6 pt-1">
<Hashicon value={node.num.toString()} size={22} />
<div>
{node.user?.publicKey && node.user?.publicKey.length > 0 ? (
<LockIcon
className="text-green-600"
size={12}
strokeWidth={3}
aria-label="Public Key Enabled"
/>
) : (
<LockOpenIcon
className="text-yellow-500"
size={12}
strokeWidth={3}
aria-label="No Public Key"
/>
)}
</div>
<Star
fill={node.isFavorite ? "black" : "none"}
size={15}
aria-label={node.isFavorite ? "Favorite" : "Not a Favorite"}
/>
</div>
<div>
<H5>{name}</H5>
{hardwareType !== "UNSET" && <Subtle>{hardwareType}</Subtle>}
{!!node.deviceMetrics?.batteryLevel && (
<div
className="flex items-center gap-1"
title={`${
node.deviceMetrics?.voltage?.toPrecision(3) ?? "Unknown"
} volts`}
>
{node.deviceMetrics?.batteryLevel > 100 ? (
<BatteryChargingIcon size={22} />
) : node.deviceMetrics?.batteryLevel > 80 ? (
<BatteryFullIcon size={22} />
) : node.deviceMetrics?.batteryLevel > 20 ? (
<BatteryMediumIcon size={22} />
) : (
<BatteryLowIcon size={22} />
)}
<Subtle aria-label="Battery">
{node.deviceMetrics?.batteryLevel > 100
? "Charging"
: node.deviceMetrics?.batteryLevel + "%"}
</Subtle>
</div>
)}
<div className="flex gap-2 items-center">
{node.user?.shortName && <div>"{node.user?.shortName}"</div>}
{node.user?.id && <div>{node.user?.id}</div>}
</div>
<div
className="flex gap-1"
title={new Date(node.lastHeard * 1000).toLocaleString(
navigator.language,
)}
>
<div>
{node.lastHeard > 0 && (
<div>
Heard <TimeAgo timestamp={node.lastHeard * 1000} />
</div>
)}
</div>
{node.viaMqtt && (
<div style={{ color: "#660066" }} className="font-medium">
MQTT
</div>
)}
</div>
</div>
</div>
<Separator className="my-1" />
<div className="flex mt-2 text-sm">
<div className="flex items-center flex-grow">
<div className="border-2 border-black rounded px-0.5 mr-1">
{isNaN(node.hopsAway) ? "?" : node.hopsAway}
</div>
<div>{node.hopsAway === 1 ? "Hop" : "Hops"}</div>
</div>
{node.position?.altitude && (
<div className="flex items-center flex-grow">
<MountainSnow
size={15}
className="ml-2 mr-1"
aria-label="Elevation"
/>
<div>{node.position?.altitude} ft</div>
</div>
)}
</div>
<div className="flex mt-2">
{!!node.deviceMetrics?.channelUtilization && (
<div className="flex-grow">
<div>Channel Util</div>
<Mono>
{node.deviceMetrics?.channelUtilization.toPrecision(3)}%
</Mono>
</div>
)}
{!!node.deviceMetrics?.airUtilTx && (
<div className="flex-grow">
<div>Airtime Util</div>
<Mono>{node.deviceMetrics?.airUtilTx.toPrecision(3)}%</Mono>
</div>
)}
</div>
{node.snr !== 0 && (
<div className="mt-2">
<div>SNR</div>
<Mono className="flex items-center text-xs">
{node.snr}db
<Dot />
{Math.min(Math.max((node.snr + 10) * 5, 0), 100)}%
<Dot />
{(node.snr + 10) * 5}raw
</Mono>
</div>
)}
</div>
);
};

10
src/components/PageComponents/Messages/ChannelChat.tsx

@ -1,11 +1,11 @@
import { Subtle } from "@app/components/UI/Typography/Subtle.js"; import { Subtle } from "@app/components/UI/Typography/Subtle.tsx";
import { import {
type MessageWithState, type MessageWithState,
useDevice, useDevice,
} from "@app/core/stores/deviceStore.js"; } from "@app/core/stores/deviceStore.ts";
import { Message } from "@components/PageComponents/Messages/Message.js"; import { Message } from "@components/PageComponents/Messages/Message.tsx";
import { MessageInput } from "@components/PageComponents/Messages/MessageInput.js"; import { MessageInput } from "@components/PageComponents/Messages/MessageInput.tsx";
import { TraceRoute } from "@components/PageComponents/Messages/TraceRoute.js"; import { TraceRoute } from "@components/PageComponents/Messages/TraceRoute.tsx";
import type { Protobuf, Types } from "@meshtastic/js"; import type { Protobuf, Types } from "@meshtastic/js";
import { InboxIcon } from "lucide-react"; import { InboxIcon } from "lucide-react";

5
src/components/PageComponents/Messages/Message.tsx

@ -1,4 +1,4 @@
import type { MessageWithState } from "@app/core/stores/deviceStore.js"; import type { MessageWithState } from "@app/core/stores/deviceStore.ts";
import { Hashicon } from "@emeraldpay/hashicon-react"; import { Hashicon } from "@emeraldpay/hashicon-react";
import type { Protobuf } from "@meshtastic/js"; import type { Protobuf } from "@meshtastic/js";
import { import {
@ -44,6 +44,9 @@ export const Message = ({
<span className="cursor-pointer font-medium text-textPrimary"> <span className="cursor-pointer font-medium text-textPrimary">
{sender?.user?.longName ?? "UNK"} {sender?.user?.longName ?? "UNK"}
</span> </span>
<span className="mt-1 font-mono text-xs text-textSecondary">
{message.rxTime.toLocaleDateString()}
</span>
<span className="mt-1 font-mono text-xs text-textSecondary"> <span className="mt-1 font-mono text-xs text-textSecondary">
{message.rxTime.toLocaleTimeString(undefined, { {message.rxTime.toLocaleTimeString(undefined, {
hour: "2-digit", hour: "2-digit",

6
src/components/PageComponents/Messages/MessageInput.tsx

@ -1,6 +1,6 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import type { Types } from "@meshtastic/js"; import type { Types } from "@meshtastic/js";
import { SendIcon } from "lucide-react"; import { SendIcon } from "lucide-react";

2
src/components/PageComponents/Messages/TraceRoute.tsx

@ -1,4 +1,4 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import type { Protobuf } from "@meshtastic/js"; import type { Protobuf } from "@meshtastic/js";
import { numberToHexUnpadded } from "@noble/curves/abstract/utils"; import { numberToHexUnpadded } from "@noble/curves/abstract/utils";

6
src/components/PageComponents/ModuleConfig/AmbientLighting.tsx

@ -1,6 +1,6 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import type { AmbientLightingValidation } from "@app/validation/moduleConfig/ambientLighting.js"; import type { AmbientLightingValidation } from "@app/validation/moduleConfig/ambientLighting.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const AmbientLighting = (): JSX.Element => { export const AmbientLighting = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/Audio.tsx

@ -1,6 +1,6 @@
import type { AudioValidation } from "@app/validation/moduleConfig/audio.js"; import type { AudioValidation } from "@app/validation/moduleConfig/audio.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Audio = (): JSX.Element => { export const Audio = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/CannedMessage.tsx

@ -1,6 +1,6 @@
import type { CannedMessageValidation } from "@app/validation/moduleConfig/cannedMessage.js"; import type { CannedMessageValidation } from "@app/validation/moduleConfig/cannedMessage.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const CannedMessage = (): JSX.Element => { export const CannedMessage = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/DetectionSensor.tsx

@ -1,6 +1,6 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import type { DetectionSensorValidation } from "@app/validation/moduleConfig/detectionSensor.js"; import type { DetectionSensorValidation } from "@app/validation/moduleConfig/detectionSensor.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const DetectionSensor = (): JSX.Element => { export const DetectionSensor = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/ExternalNotification.tsx

@ -1,6 +1,6 @@
import type { ExternalNotificationValidation } from "@app/validation/moduleConfig/externalNotification.js"; import type { ExternalNotificationValidation } from "@app/validation/moduleConfig/externalNotification.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const ExternalNotification = (): JSX.Element => { export const ExternalNotification = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/MQTT.tsx

@ -1,6 +1,6 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import type { MqttValidation } from "@app/validation/moduleConfig/mqtt.js"; import type { MqttValidation } from "@app/validation/moduleConfig/mqtt.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const MQTT = (): JSX.Element => { export const MQTT = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/NeighborInfo.tsx

@ -1,6 +1,6 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import type { NeighborInfoValidation } from "@app/validation/moduleConfig/neighborInfo.js"; import type { NeighborInfoValidation } from "@app/validation/moduleConfig/neighborInfo.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const NeighborInfo = (): JSX.Element => { export const NeighborInfo = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/Paxcounter.tsx

@ -1,6 +1,6 @@
import type { PaxcounterValidation } from "@app/validation/moduleConfig/paxcounter.js"; import type { PaxcounterValidation } from "@app/validation/moduleConfig/paxcounter.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Paxcounter = (): JSX.Element => { export const Paxcounter = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/RangeTest.tsx

@ -1,6 +1,6 @@
import type { RangeTestValidation } from "@app/validation/moduleConfig/rangeTest.js"; import type { RangeTestValidation } from "@app/validation/moduleConfig/rangeTest.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const RangeTest = (): JSX.Element => { export const RangeTest = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/Serial.tsx

@ -1,6 +1,6 @@
import type { SerialValidation } from "@app/validation/moduleConfig/serial.js"; import type { SerialValidation } from "@app/validation/moduleConfig/serial.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Serial = (): JSX.Element => { export const Serial = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/StoreForward.tsx

@ -1,6 +1,6 @@
import type { StoreForwardValidation } from "@app/validation/moduleConfig/storeForward.js"; import type { StoreForwardValidation } from "@app/validation/moduleConfig/storeForward.ts";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const StoreForward = (): JSX.Element => { export const StoreForward = (): JSX.Element => {

6
src/components/PageComponents/ModuleConfig/Telemetry.tsx

@ -1,6 +1,6 @@
import type { TelemetryValidation } from "@app/validation/moduleConfig/telemetry.js"; import type { TelemetryValidation } from "@app/validation/moduleConfig/telemetry.tsx";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Protobuf } from "@meshtastic/js"; import { Protobuf } from "@meshtastic/js";
export const Telemetry = (): JSX.Element => { export const Telemetry = (): JSX.Element => {

2
src/components/PageLayout.tsx

@ -1,4 +1,4 @@
import { cn } from "@app/core/utils/cn.js"; import { cn } from "@app/core/utils/cn.ts";
import { AlignLeftIcon, type LucideIcon } from "lucide-react"; import { AlignLeftIcon, type LucideIcon } from "lucide-react";
import Footer from "./UI/Footer"; import Footer from "./UI/Footer";

33
src/components/Sidebar.tsx

@ -1,8 +1,8 @@
import { SidebarSection } from "@components/UI/Sidebar/SidebarSection.js"; import { SidebarSection } from "@components/UI/Sidebar/SidebarSection.tsx";
import { SidebarButton } from "@components/UI/Sidebar/sidebarButton.js"; import { SidebarButton } from "@components/UI/Sidebar/sidebarButton.tsx";
import { Subtle } from "@components/UI/Typography/Subtle.js"; import { Subtle } from "@components/UI/Typography/Subtle.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import type { Page } from "@core/stores/deviceStore.js"; import type { Page } from "@core/stores/deviceStore.ts";
import { import {
BatteryMediumIcon, BatteryMediumIcon,
CpuIcon, CpuIcon,
@ -12,9 +12,12 @@ import {
MapIcon, MapIcon,
MessageSquareIcon, MessageSquareIcon,
SettingsIcon, SettingsIcon,
SidebarCloseIcon,
SidebarOpenIcon,
UsersIcon, UsersIcon,
ZapIcon, ZapIcon,
} from "lucide-react"; } from "lucide-react";
import { useState } from "react";
export interface SidebarProps { export interface SidebarProps {
children?: React.ReactNode; children?: React.ReactNode;
@ -25,6 +28,7 @@ export const Sidebar = ({ children }: SidebarProps): JSX.Element => {
const myNode = nodes.get(hardware.myNodeNum); const myNode = nodes.get(hardware.myNodeNum);
const myMetadata = metadata.get(0); const myMetadata = metadata.get(0);
const { activePage, setActivePage, setDialogOpen } = useDevice(); const { activePage, setActivePage, setDialogOpen } = useDevice();
const [showSidebar, setShowSidebar] = useState<boolean>(true);
interface NavLink { interface NavLink {
name: string; name: string;
@ -60,7 +64,7 @@ export const Sidebar = ({ children }: SidebarProps): JSX.Element => {
}, },
]; ];
return ( return showSidebar ? (
<div className="min-w-[280px] max-w-min flex-col overflow-y-auto border-r-[0.5px] border-slate-300 bg-transparent dark:border-slate-700"> <div className="min-w-[280px] max-w-min flex-col overflow-y-auto border-r-[0.5px] border-slate-300 bg-transparent dark:border-slate-700">
<div className="flex justify-between px-8 pt-6"> <div className="flex justify-between px-8 pt-6">
<div> <div>
@ -76,11 +80,20 @@ export const Sidebar = ({ children }: SidebarProps): JSX.Element => {
> >
<EditIcon size={16} /> <EditIcon size={16} />
</button> </button>
<button type="button" onClick={() => setShowSidebar(false)}>
<SidebarCloseIcon size={24} />
</button>
</div> </div>
<div className="px-8 pb-6"> <div className="px-8 pb-6">
<div className="flex items-center"> <div className="flex items-center">
<BatteryMediumIcon size={24} viewBox={"0 0 28 24"} /> <BatteryMediumIcon size={24} viewBox={"0 0 28 24"} />
<Subtle>{myNode?.deviceMetrics?.batteryLevel ?? "UNK"}%</Subtle> <Subtle>
{myNode?.deviceMetrics?.batteryLevel
? myNode?.deviceMetrics?.batteryLevel > 100
? "Charging"
: myNode?.deviceMetrics?.batteryLevel + "%"
: "UNK"}
</Subtle>
</div> </div>
<div className="flex items-center"> <div className="flex items-center">
<ZapIcon size={24} viewBox={"0 0 36 24"} /> <ZapIcon size={24} viewBox={"0 0 36 24"} />
@ -109,5 +122,11 @@ export const Sidebar = ({ children }: SidebarProps): JSX.Element => {
</SidebarSection> </SidebarSection>
{children} {children}
</div> </div>
) : (
<div className="px-1 pt-8 border-r-[0.5px] border-slate-700">
<button type="button" onClick={() => setShowSidebar(true)}>
<SidebarOpenIcon size={24} />
</button>
</div>
); );
}; };

27
src/components/Toaster.tsx

@ -1,5 +1,3 @@
import { useToast } from "@core/hooks/useToast.js";
import { import {
Toast, Toast,
ToastClose, ToastClose,
@ -7,24 +5,25 @@ import {
ToastProvider, ToastProvider,
ToastTitle, ToastTitle,
ToastViewport, ToastViewport,
} from "@components/UI/Toast.js"; } from "@components/UI/Toast";
import { useToast } from "@core/hooks/useToast";
export function Toaster() { export function Toaster() {
const { toasts } = useToast(); const { toasts } = useToast();
return ( return (
<ToastProvider> <ToastProvider>
{toasts.map(({ id, title, description, action, ...props }) => ( {toasts.map(({ id, title, description, action, duration, ...props }) => (
<Toast key={id} {...props}> <Toast
key={id}
{...props}
duration={duration}
className="flex flex-col gap-4"
>
<div className="grid gap-1"> <div className="grid gap-1">
{title && ( {title && <ToastTitle>{title}</ToastTitle>}
<ToastTitle className="dark:text-white">{title}</ToastTitle> {description && <ToastDescription>{description}</ToastDescription>}
)}
{description && (
<ToastDescription className="dark:text-white-400">
{description}
</ToastDescription>
)}
</div> </div>
{action} {action}
<ToastClose /> <ToastClose />
@ -33,4 +32,4 @@ export function Toaster() {
<ToastViewport /> <ToastViewport />
</ToastProvider> </ToastProvider>
); );
} }

6
src/components/UI/Button.tsx

@ -1,7 +1,7 @@
import { type VariantProps, cva } from "class-variance-authority"; import { type VariantProps, cva } from "class-variance-authority";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const buttonVariants = cva( const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 dark:hover:bg-slate-800 dark:hover:text-slate-100 disabled:opacity-50 dark:focus:ring-slate-400 disabled:pointer-events-none dark:focus:ring-offset-slate-900 data-[state=open]:bg-slate-100 dark:data-[state=open]:bg-slate-800", "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 dark:hover:bg-slate-800 dark:hover:text-slate-100 disabled:opacity-50 dark:focus:ring-slate-400 disabled:pointer-events-none dark:focus:ring-offset-slate-900 data-[state=open]:bg-slate-100 dark:data-[state=open]:bg-slate-800",
@ -35,9 +35,11 @@ const buttonVariants = cva(
}, },
); );
export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
export interface ButtonProps export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>, extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {} VariantProps<typeof buttonVariants> { }
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, ...props }, ref) => { ({ className, variant, size, ...props }, ref) => {

2
src/components/UI/Checkbox.tsx

@ -2,7 +2,7 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react"; import { Check } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Checkbox = React.forwardRef< const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>, React.ElementRef<typeof CheckboxPrimitive.Root>,

4
src/components/UI/Command.tsx

@ -3,8 +3,8 @@ import { Command as CommandPrimitive } from "cmdk";
import { Search } from "lucide-react"; import { Search } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { Dialog, DialogContent } from "@components/UI/Dialog.js"; import { Dialog, DialogContent } from "@components/UI/Dialog.tsx";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Command = React.forwardRef< const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>, React.ElementRef<typeof CommandPrimitive>,

2
src/components/UI/Dialog.tsx

@ -2,7 +2,7 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react"; import { X } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Dialog = DialogPrimitive.Root; const Dialog = DialogPrimitive.Root;

2
src/components/UI/DropdownMenu.tsx

@ -2,7 +2,7 @@ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import { Check, ChevronRight, Circle } from "lucide-react"; import { Check, ChevronRight, Circle } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const DropdownMenu = DropdownMenuPrimitive.Root; const DropdownMenu = DropdownMenuPrimitive.Root;

48
src/components/UI/Generator.tsx

@ -1,26 +1,30 @@
import * as React from "react"; import * as React from "react";
import { Button } from "@components/UI/Button.js"; import { Button, type ButtonVariant } from "@components/UI/Button.tsx";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.tsx";
import { import {
Select, Select,
SelectContent, SelectContent,
SelectItem, SelectItem,
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@components/UI/Select.js"; } from "@components/UI/Select.tsx";
import type { LucideIcon } from "lucide-react"; import type { LucideIcon } from "lucide-react";
export interface GeneratorProps extends React.BaseHTMLAttributes<HTMLElement> { export interface GeneratorProps extends React.BaseHTMLAttributes<HTMLElement> {
hide?: boolean; type: "text" | "password";
devicePSKBitCount?: number; devicePSKBitCount?: number;
value: string; value: string;
variant: "default" | "invalid"; variant: "default" | "invalid";
buttonText?: string; actionButtons: {
text: string;
onClick: React.MouseEventHandler<HTMLButtonElement>;
variant: ButtonVariant;
className?: string;
}[];
bits?: { text: string; value: string; key: string }[]; bits?: { text: string; value: string; key: string }[];
selectChange: (event: string) => void; selectChange: (event: string) => void;
inputChange: (event: React.ChangeEvent<HTMLInputElement>) => void; inputChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
buttonClick: React.MouseEventHandler<HTMLButtonElement>;
action?: { action?: {
icon: LucideIcon; icon: LucideIcon;
onClick: () => void; onClick: () => void;
@ -31,19 +35,19 @@ export interface GeneratorProps extends React.BaseHTMLAttributes<HTMLElement> {
const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>( const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>(
( (
{ {
hide = true, type,
devicePSKBitCount, devicePSKBitCount,
variant, variant,
value, value,
buttonText, actionButtons,
bits = [ bits = [
{ text: "256 bit", value: "32", key: "bit256" }, { text: "256 bit", value: "32", key: "bit256" },
{ text: "128 bit", value: "16", key: "bit128" }, { text: "128 bit", value: "16", key: "bit128" },
{ text: "8 bit", value: "1", key: "bit8" }, { text: "8 bit", value: "1", key: "bit8" },
{ text: "Empty", value: "0", key: "empty" },
], ],
selectChange, selectChange,
inputChange, inputChange,
buttonClick,
action, action,
disabled, disabled,
...props ...props
@ -68,7 +72,7 @@ const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>(
return ( return (
<> <>
<Input <Input
type={hide ? "password" : "text"} type={type}
id="pskInput" id="pskInput"
variant={variant} variant={variant}
value={value} value={value}
@ -93,15 +97,21 @@ const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>(
))} ))}
</SelectContent> </SelectContent>
</Select> </Select>
<Button <div className="flex ml-4 space-x-4">
type="button" {actionButtons?.map(({ text, onClick, variant, className }) => (
variant="success" <Button
onClick={buttonClick} key={text}
disabled={disabled} type="button"
{...props} onClick={onClick}
> disabled={disabled}
{buttonText} variant={variant}
</Button> className={className}
{...props}
>
{text}
</Button>
))}
</div>
</> </>
); );
}, },

2
src/components/UI/Input.tsx

@ -1,6 +1,6 @@
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
import { type VariantProps, cva } from "class-variance-authority"; import { type VariantProps, cva } from "class-variance-authority";
import type { LucideIcon } from "lucide-react"; import type { LucideIcon } from "lucide-react";

2
src/components/UI/Label.tsx

@ -1,7 +1,7 @@
import * as LabelPrimitive from "@radix-ui/react-label"; import * as LabelPrimitive from "@radix-ui/react-label";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Label = React.forwardRef< const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>, React.ElementRef<typeof LabelPrimitive.Root>,

2
src/components/UI/Menubar.tsx

@ -2,7 +2,7 @@ import * as MenubarPrimitive from "@radix-ui/react-menubar";
import { Check, ChevronRight, Circle } from "lucide-react"; import { Check, ChevronRight, Circle } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const MenubarMenu = MenubarPrimitive.Menu; const MenubarMenu = MenubarPrimitive.Menu;

2
src/components/UI/Popover.tsx

@ -1,7 +1,7 @@
import * as PopoverPrimitive from "@radix-ui/react-popover"; import * as PopoverPrimitive from "@radix-ui/react-popover";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Popover = PopoverPrimitive.Root; const Popover = PopoverPrimitive.Root;

2
src/components/UI/ScrollArea.tsx

@ -1,7 +1,7 @@
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"; import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const ScrollArea = React.forwardRef< const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>, React.ElementRef<typeof ScrollAreaPrimitive.Root>,

2
src/components/UI/Select.tsx

@ -2,7 +2,7 @@ import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown } from "lucide-react"; import { Check, ChevronDown } from "lucide-react";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Select = SelectPrimitive.Root; const Select = SelectPrimitive.Root;

2
src/components/UI/Seperator.tsx

@ -1,7 +1,7 @@
import * as SeparatorPrimitive from "@radix-ui/react-separator"; import * as SeparatorPrimitive from "@radix-ui/react-separator";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Separator = React.forwardRef< const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>, React.ElementRef<typeof SeparatorPrimitive.Root>,

2
src/components/UI/Sidebar/SidebarSection.tsx

@ -1,4 +1,4 @@
import { H4 } from "@components/UI/Typography/H4.js"; import { H4 } from "@components/UI/Typography/H4.tsx";
export interface SidebarSectionProps { export interface SidebarSectionProps {
label: string; label: string;

2
src/components/UI/Sidebar/sidebarButton.tsx

@ -1,4 +1,4 @@
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.tsx";
import type { LucideIcon } from "lucide-react"; import type { LucideIcon } from "lucide-react";
export interface SidebarButtonProps { export interface SidebarButtonProps {

2
src/components/UI/Switch.tsx

@ -1,7 +1,7 @@
import * as SwitchPrimitives from "@radix-ui/react-switch"; import * as SwitchPrimitives from "@radix-ui/react-switch";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Switch = React.forwardRef< const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>, React.ElementRef<typeof SwitchPrimitives.Root>,

2
src/components/UI/Tabs.tsx

@ -1,7 +1,7 @@
import * as TabsPrimitive from "@radix-ui/react-tabs"; import * as TabsPrimitive from "@radix-ui/react-tabs";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const Tabs = TabsPrimitive.Root; const Tabs = TabsPrimitive.Root;

70
src/components/UI/Toast.tsx

@ -1,11 +1,11 @@
import * as ToastPrimitives from "@radix-ui/react-toast"; import * as React from "react"
import { type VariantProps, cva } from "class-variance-authority"; import * as ToastPrimitives from "@radix-ui/react-toast"
import { X } from "lucide-react"; import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"; import { X } from 'lucide-react'
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn"
const ToastProvider = ToastPrimitives.Provider; const ToastProvider = ToastPrimitives.Provider
const ToastViewport = React.forwardRef< const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>, React.ElementRef<typeof ToastPrimitives.Viewport>,
@ -14,35 +14,34 @@ const ToastViewport = React.forwardRef<
<ToastPrimitives.Viewport <ToastPrimitives.Viewport
ref={ref} ref={ref}
className={cn( className={cn(
"fixed top-0 z-50 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]", "fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-24 sm:right-6 sm:top-auto sm:flex-col md:max-w-[420px]",
className, className
)} )}
{...props} {...props}
/> />
)); ))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName; ToastViewport.displayName = ToastPrimitives.Viewport.displayName
const toastVariants = cva( const toastVariants = cva(
"data-[swipe=move]:transition-none grow-1 group relative pointer-events-auto flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full mt-4 data-[state=closed]:slide-out-to-right-full dark:border-slate-700 last:mt-0 sm:last:mt-4", "group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
{ {
variants: { variants: {
variant: { variant: {
default: default: "border bg-background text-foreground dark:bg-slate-700 dark:border-slate-600 dark:text-slate-50",
"bg-white border-slate-200 dark:bg-slate-800 dark:border-slate-700",
destructive: destructive:
"group destructive bg-red-600 text-white border-red-600 dark:border-red-600", "group destructive bg-red-600 text-white dark:border-red-900 dark:bg-red-900 dark:text-red-50"
}, },
}, },
defaultVariants: { defaultVariants: {
variant: "default", variant: "default",
}, },
}, }
); )
const Toast = React.forwardRef< const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>, React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants> VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => { >(({ className, variant, ...props }, ref) => {
return ( return (
<ToastPrimitives.Root <ToastPrimitives.Root
@ -50,9 +49,9 @@ const Toast = React.forwardRef<
className={cn(toastVariants({ variant }), className)} className={cn(toastVariants({ variant }), className)}
{...props} {...props}
/> />
); )
}); })
Toast.displayName = ToastPrimitives.Root.displayName; Toast.displayName = ToastPrimitives.Root.displayName
const ToastAction = React.forwardRef< const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>, React.ElementRef<typeof ToastPrimitives.Action>,
@ -61,13 +60,13 @@ const ToastAction = React.forwardRef<
<ToastPrimitives.Action <ToastPrimitives.Action
ref={ref} ref={ref}
className={cn( className={cn(
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border border-slate-200 bg-transparent px-3 text-sm font-medium transition-colors hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-red-100 group-[.destructive]:hover:border-slate-50 group-[.destructive]:hover:bg-red-100 group-[.destructive]:hover:text-red-600 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600 dark:border-slate-700 dark:text-slate-100 dark:hover:bg-slate-700 dark:hover:text-slate-100 dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900 dark:data-[state=open]:bg-slate-800", "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
className, className
)} )}
{...props} {...props}
/> />
)); ))
ToastAction.displayName = ToastPrimitives.Action.displayName; ToastAction.displayName = ToastPrimitives.Action.displayName
const ToastClose = React.forwardRef< const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>, React.ElementRef<typeof ToastPrimitives.Close>,
@ -76,16 +75,16 @@ const ToastClose = React.forwardRef<
<ToastPrimitives.Close <ToastPrimitives.Close
ref={ref} ref={ref}
className={cn( className={cn(
"absolute right-2 top-2 rounded-md p-1 text-slate-500 opacity-0 transition-opacity hover:text-slate-900 focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600 dark:hover:text-slate-50", "absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600 dark:text-slate-400 dark:hover:text-slate-50",
className, className
)} )}
toast-close="" toast-close=""
{...props} {...props}
> >
<X className="h-4 w-4" /> <X className="h-4 w-4" />
</ToastPrimitives.Close> </ToastPrimitives.Close>
)); ))
ToastClose.displayName = ToastPrimitives.Close.displayName; ToastClose.displayName = ToastPrimitives.Close.displayName
const ToastTitle = React.forwardRef< const ToastTitle = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Title>, React.ElementRef<typeof ToastPrimitives.Title>,
@ -96,8 +95,8 @@ const ToastTitle = React.forwardRef<
className={cn("text-sm font-semibold", className)} className={cn("text-sm font-semibold", className)}
{...props} {...props}
/> />
)); ))
ToastTitle.displayName = ToastPrimitives.Title.displayName; ToastTitle.displayName = ToastPrimitives.Title.displayName
const ToastDescription = React.forwardRef< const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>, React.ElementRef<typeof ToastPrimitives.Description>,
@ -108,12 +107,12 @@ const ToastDescription = React.forwardRef<
className={cn("text-sm opacity-90", className)} className={cn("text-sm opacity-90", className)}
{...props} {...props}
/> />
)); ))
ToastDescription.displayName = ToastPrimitives.Description.displayName; ToastDescription.displayName = ToastPrimitives.Description.displayName
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>; type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
type ToastActionElement = React.ReactElement<typeof ToastAction>; type ToastActionElement = React.ReactElement<typeof ToastAction>
export { export {
type ToastProps, type ToastProps,
@ -125,4 +124,5 @@ export {
ToastDescription, ToastDescription,
ToastClose, ToastClose,
ToastAction, ToastAction,
}; }

2
src/components/UI/Tooltip.tsx

@ -1,7 +1,7 @@
import * as TooltipPrimitive from "@radix-ui/react-tooltip"; import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import * as React from "react"; import * as React from "react";
import { cn } from "@core/utils/cn.js"; import { cn } from "@core/utils/cn.ts";
const TooltipProvider = TooltipPrimitive.Provider; const TooltipProvider = TooltipPrimitive.Provider;

2
src/components/UI/Typography/H4.tsx

@ -1,4 +1,4 @@
import { cn } from "@app/core/utils/cn.js"; import { cn } from "@app/core/utils/cn.ts";
export interface H4Props { export interface H4Props {
className?: string; className?: string;

14
src/components/UI/Typography/H5.tsx

@ -0,0 +1,14 @@
import { cn } from "@app/core/utils/cn.ts";
export interface H5Props {
className?: string;
children: React.ReactNode;
}
export const H5 = ({ className, children }: H5Props): JSX.Element => (
<h5
className={cn("scroll-m-20 text-lg font-medium tracking-tight", className)}
>
{children}
</h5>
);

7
src/components/UI/Typography/Link.tsx

@ -1,14 +1,17 @@
import { cn } from "@app/core/utils/cn";
export interface LinkProps { export interface LinkProps {
href: string; href: string;
children: React.ReactNode; children: React.ReactNode;
className?: string;
} }
export const Link = ({ href, children }: LinkProps): JSX.Element => ( export const Link = ({ href, children, className }: LinkProps): JSX.Element => (
<a <a
href={href} href={href}
target={"_blank"} target={"_blank"}
rel="noopener noreferrer" rel="noopener noreferrer"
className="font-medium text-slate-900 underline underline-offset-4 dark:text-slate-50" className={cn("font-medium text-slate-900 underline underline-offset-4 dark:text-slate-50", className)}
> >
{children} {children}
</a> </a>

2
src/components/UI/Typography/Subtle.tsx

@ -1,4 +1,4 @@
import { cn } from "@app/core/utils/cn.js"; import { cn } from "@app/core/utils/cn.ts";
export interface SubtleProps { export interface SubtleProps {
className?: string; className?: string;

2
src/components/generic/ThemeController.tsx

@ -1,4 +1,4 @@
import { useAppStore } from "@core/stores/appStore.js"; import { useAppStore } from "@core/stores/appStore.ts";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
export interface ThemeControllerProps { export interface ThemeControllerProps {

29
src/core/hooks/useBrowserFeatureDetection.ts

@ -0,0 +1,29 @@
import { useMemo } from 'react';
export type BrowserFeature = 'Web Bluetooth' | 'Web Serial' | 'Secure Context';
interface BrowserSupport {
supported: BrowserFeature[];
unsupported: BrowserFeature[];
}
export function useBrowserFeatureDetection(): BrowserSupport {
const support = useMemo(() => {
const features: [BrowserFeature, boolean][] = [
['Web Bluetooth', !!navigator?.bluetooth],
['Web Serial', !!navigator?.serial],
['Secure Context', window.location.protocol === 'https:' || window.location.hostname === 'localhost']
];
return features.reduce<BrowserSupport>(
(acc, [feature, isSupported]) => {
const list = isSupported ? acc.supported : acc.unsupported;
list.push(feature);
return acc;
},
{ supported: [], unsupported: [] }
);
}, []);
return support;
}

52
src/core/hooks/useCookie.ts

@ -0,0 +1,52 @@
import Cookies, { type CookieAttributes } from "js-cookie";
import { useCallback, useState } from "react";
interface CookieHookResult<T> {
value: T | undefined;
setCookie: (value: T, options?: CookieAttributes) => void;
removeCookie: () => void;
}
function useCookie<T extends object>(
cookieName: string,
initialValue?: T,
): CookieHookResult<T> {
const [cookieValue, setCookieValue] = useState<T | undefined>(() => {
try {
const cookie = Cookies.get(cookieName);
return cookie ? (JSON.parse(cookie) as T) : initialValue;
} catch (error) {
console.error(`Error parsing cookie ${cookieName}:`, error);
return initialValue;
}
});
const setCookie = useCallback(
(value: T, options?: CookieAttributes) => {
try {
Cookies.set(cookieName, JSON.stringify(value), options);
setCookieValue(value);
} catch (error) {
console.error(`Error setting cookie ${cookieName}:`, error);
}
},
[cookieName],
);
const removeCookie = useCallback(() => {
try {
Cookies.remove(cookieName);
setCookieValue(undefined);
} catch (error) {
console.error(`Error removing cookie ${cookieName}:`, error);
}
}, [cookieName]);
return {
value: cookieValue,
setCookie,
removeCookie,
};
}
export default useCookie;

120
src/core/hooks/useKeyBackupReminder.tsx

@ -0,0 +1,120 @@
import { Button } from "@app/components/UI/Button";
import type { CookieAttributes } from "js-cookie";
import { useCallback, useEffect, useRef } from "react";
import useCookie from "./useCookie";
import { useToast } from "./useToast";
interface UseBackupReminderOptions {
reminderInDays?: number;
message: string;
onAccept?: () => void | Promise<void>;
enabled: boolean;
cookieOptions?: CookieAttributes;
}
interface ReminderState {
suppressed: boolean;
lastShown: string;
}
const TOAST_APPEAR_DELAY = 10_000 // 10 seconds;
const TOAST_DURATION = 30_000 // 30 seconds;:
// remind user in 1 year to backup keys again, if they accept the reminder;
const ON_ACCEPT_REMINDER_DAYS = 365
function isReminderExpired(lastShown: string): boolean {
const lastShownDate = new Date(lastShown);
const now = new Date();
const daysSinceLastShown =
(now.getTime() - lastShownDate.getTime()) / (1000 * 60 * 60 * 24);
return daysSinceLastShown >= 7;
}
export function useBackupReminder({
reminderInDays = 7,
enabled,
message,
onAccept = () => { },
cookieOptions,
}: UseBackupReminderOptions) {
const { toast } = useToast();
const toastShownRef = useRef(false);
const { value: reminderCookie, setCookie } =
useCookie<ReminderState>("key_backup_reminder");
const suppressReminder = useCallback(
(days: number) => {
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + days);
setCookie(
{
suppressed: true,
lastShown: new Date().toISOString(),
},
{ ...cookieOptions, expires: expiryDate },
);
},
[setCookie, cookieOptions],
);
useEffect(() => {
if (!enabled || toastShownRef.current) return;
const shouldShowReminder =
!reminderCookie?.suppressed ||
isReminderExpired(reminderCookie.lastShown);
if (!shouldShowReminder) return;
toastShownRef.current = true;
const { dismiss } = toast(
{
title: "Backup Reminder",
duration: TOAST_DURATION,
delay: TOAST_APPEAR_DELAY,
description: message,
action: (
<div className="flex gap-2">
<Button
type="button"
variant="default"
onClick={() => {
onAccept();
dismiss();
suppressReminder(ON_ACCEPT_REMINDER_DAYS);
}}
>
Back up now
</Button>
<Button
type="button"
variant="outline"
onClick={() => {
dismiss();
suppressReminder(reminderInDays);
}}
>
Remind me in {reminderInDays} days
</Button>
</div>
),
},
);
return () => {
if (!toastShownRef.current) {
dismiss();
}
};
}, [
enabled,
message,
onAccept,
reminderInDays,
suppressReminder,
toast,
reminderCookie,
]);
}

63
src/core/hooks/useToast.ts

@ -1,6 +1,6 @@
import { type ReactNode, useSyncExternalStore } from "react"; import { type ReactNode, useSyncExternalStore } from "react";
import type { ToastActionElement, ToastProps } from "@components/UI/Toast.js"; import type { ToastActionElement, ToastProps } from "@components/UI/Toast.tsx";
const TOAST_LIMIT = 1; const TOAST_LIMIT = 1;
const TOAST_REMOVE_DELAY = 1000000; const TOAST_REMOVE_DELAY = 1000000;
@ -10,6 +10,7 @@ type ToasterToast = ToastProps & {
title?: ReactNode; title?: ReactNode;
description?: ReactNode; description?: ReactNode;
action?: ToastActionElement; action?: ToastActionElement;
delay?: number;
}; };
const actionTypes = { const actionTypes = {
@ -30,21 +31,21 @@ type ActionType = typeof actionTypes;
type Action = type Action =
| { | {
type: ActionType["ADD_TOAST"]; type: ActionType["ADD_TOAST"];
toast: ToasterToast; toast: ToasterToast;
} }
| { | {
type: ActionType["UPDATE_TOAST"]; type: ActionType["UPDATE_TOAST"];
toast: Partial<ToasterToast>; toast: Partial<ToasterToast>;
} }
| { | {
type: ActionType["DISMISS_TOAST"]; type: ActionType["DISMISS_TOAST"];
toastId?: ToasterToast["id"]; toastId?: ToasterToast["id"];
} }
| { | {
type: ActionType["REMOVE_TOAST"]; type: ActionType["REMOVE_TOAST"];
toastId?: ToasterToast["id"]; toastId?: ToasterToast["id"];
}; };
interface State { interface State {
toasts: ToasterToast[]; toasts: ToasterToast[];
@ -80,7 +81,7 @@ export const reducer = (state: State, action: Action): State => {
return { return {
...state, ...state,
toasts: state.toasts.map((t) => toasts: state.toasts.map((t) =>
t.id === action.toast.id ? { ...t, ...action.toast } : t, t.id === action.toast.id ? { ...t, ...action.toast } : t
), ),
}; };
@ -102,10 +103,10 @@ export const reducer = (state: State, action: Action): State => {
toasts: state.toasts.map((t) => toasts: state.toasts.map((t) =>
t.id === toastId || toastId === undefined t.id === toastId || toastId === undefined
? { ? {
...t, ...t,
open: false, open: false,
} }
: t, : t
), ),
}; };
} }
@ -137,7 +138,7 @@ function dispatch(action: Action) {
type Toast = Omit<ToasterToast, "id">; type Toast = Omit<ToasterToast, "id">;
function toast({ ...props }: Toast) { function toast({ delay = 0, ...props }: Toast) {
const id = genId(); const id = genId();
const update = (props: ToasterToast) => const update = (props: ToasterToast) =>
@ -147,17 +148,19 @@ function toast({ ...props }: Toast) {
}); });
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id }); const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
dispatch({ setTimeout(() => {
type: "ADD_TOAST", dispatch({
toast: { type: "ADD_TOAST",
...props, toast: {
id, ...props,
open: true, id,
onOpenChange: (open) => { open: true,
if (!open) dismiss(); onOpenChange: (open) => {
if (!open) dismiss();
},
}, },
}, });
}); }, delay);
return { return {
id: id, id: id,
@ -190,4 +193,4 @@ function useToast() {
}; };
} }
export { useToast, toast }; export { toast, useToast };

5
src/core/stores/deviceStore.ts

@ -25,7 +25,8 @@ export type DialogVariant =
| "shutdown" | "shutdown"
| "reboot" | "reboot"
| "deviceName" | "deviceName"
| "nodeRemoval"; | "nodeRemoval"
| "pkiBackup";
export interface Device { export interface Device {
id: number; id: number;
@ -60,6 +61,7 @@ export interface Device {
reboot: boolean; reboot: boolean;
deviceName: boolean; deviceName: boolean;
nodeRemoval: boolean; nodeRemoval: boolean;
pkiBackup: boolean;
}; };
setStatus: (status: Types.DeviceStatusEnum) => void; setStatus: (status: Types.DeviceStatusEnum) => void;
@ -142,6 +144,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
reboot: false, reboot: false,
deviceName: false, deviceName: false,
nodeRemoval: false, nodeRemoval: false,
pkiBackup: false,
}, },
pendingSettingsChanges: false, pendingSettingsChanges: false,
messageDraft: "", messageDraft: "",

2
src/core/subscriptions.ts

@ -1,4 +1,4 @@
import type { Device } from "@core/stores/deviceStore.js"; import type { Device } from "@core/stores/deviceStore.ts";
import { Protobuf, type Types } from "@meshtastic/js"; import { Protobuf, type Types } from "@meshtastic/js";
export const subscribeAll = ( export const subscribeAll = (

2
src/core/utils/x25519.ts

@ -3,6 +3,8 @@ import { x25519 } from "@noble/curves/ed25519";
export function getX25519PrivateKey(): Uint8Array { export function getX25519PrivateKey(): Uint8Array {
const key = x25519.utils.randomPrivateKey(); const key = x25519.utils.randomPrivateKey();
// scalar clamping for curve25519, according to
// https://www.rfc-editor.org/rfc/rfc7748#section-5
key[0] &= 248; key[0] &= 248;
key[31] &= 127; key[31] &= 127;
key[31] |= 64; key[31] |= 64;

2
src/index.css

@ -99,4 +99,4 @@
img { img {
-drag: none; -drag: none;
-webkit-user-drag: none; -webkit-user-drag: none;
} }

2
src/index.tsx

@ -4,7 +4,7 @@ import "maplibre-gl/dist/maplibre-gl.css";
import { StrictMode } from "react"; import { StrictMode } from "react";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import { App } from "@app/App.js"; import { App } from "@app/App.tsx";
const container = document.getElementById("root") as HTMLElement; const container = document.getElementById("root") as HTMLElement;
const root = createRoot(container); const root = createRoot(container);

10
src/pages/Channels.tsx

@ -3,11 +3,11 @@ import {
TabsContent, TabsContent,
TabsList, TabsList,
TabsTrigger, TabsTrigger,
} from "@app/components/UI/Tabs.js"; } from "@app/components/UI/Tabs.tsx";
import { Channel } from "@components/PageComponents/Channel.js"; import { Channel } from "@components/PageComponents/Channel.tsx";
import { PageLayout } from "@components/PageLayout.js"; import { PageLayout } from "@components/PageLayout.tsx";
import { Sidebar } from "@components/Sidebar.js"; import { Sidebar } from "@components/Sidebar.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
import { Types } from "@meshtastic/js"; import { Types } from "@meshtastic/js";
import type { Protobuf } from "@meshtastic/js"; import type { Protobuf } from "@meshtastic/js";
import { ImportIcon, QrCodeIcon } from "lucide-react"; import { ImportIcon, QrCodeIcon } from "lucide-react";

20
src/pages/Config/DeviceConfig.tsx

@ -1,18 +1,18 @@
import { Bluetooth } from "@components/PageComponents/Config/Bluetooth.js"; import { Bluetooth } from "@components/PageComponents/Config/Bluetooth.tsx";
import { Device } from "@components/PageComponents/Config/Device.js"; import { Device } from "@components/PageComponents/Config/Device.tsx";
import { Display } from "@components/PageComponents/Config/Display.js"; import { Display } from "@components/PageComponents/Config/Display.tsx";
import { LoRa } from "@components/PageComponents/Config/LoRa.js"; import { LoRa } from "@components/PageComponents/Config/LoRa.tsx";
import { Network } from "@components/PageComponents/Config/Network.js"; import { Network } from "@components/PageComponents/Config/Network.tsx";
import { Position } from "@components/PageComponents/Config/Position.js"; import { Position } from "@components/PageComponents/Config/Position.tsx";
import { Power } from "@components/PageComponents/Config/Power.js"; import { Power } from "@components/PageComponents/Config/Power.tsx";
import { Security } from "@components/PageComponents/Config/Security.js"; import { Security } from "@components/PageComponents/Config/Security.tsx";
import { import {
Tabs, Tabs,
TabsContent, TabsContent,
TabsList, TabsList,
TabsTrigger, TabsTrigger,
} from "@components/UI/Tabs.js"; } from "@components/UI/Tabs.tsx";
import { useDevice } from "@core/stores/deviceStore.js"; import { useDevice } from "@core/stores/deviceStore.ts";
export const DeviceConfig = (): JSX.Element => { export const DeviceConfig = (): JSX.Element => {
const { metadata } = useDevice(); const { metadata } = useDevice();

26
src/pages/Config/ModuleConfig.tsx

@ -1,21 +1,21 @@
import { AmbientLighting } from "@app/components/PageComponents/ModuleConfig/AmbientLighting.js"; import { AmbientLighting } from "@app/components/PageComponents/ModuleConfig/AmbientLighting.tsx";
import { DetectionSensor } from "@app/components/PageComponents/ModuleConfig/DetectionSensor.js"; import { DetectionSensor } from "@app/components/PageComponents/ModuleConfig/DetectionSensor.tsx";
import { NeighborInfo } from "@app/components/PageComponents/ModuleConfig/NeighborInfo.js"; import { NeighborInfo } from "@app/components/PageComponents/ModuleConfig/NeighborInfo.tsx";
import { Audio } from "@components/PageComponents/ModuleConfig/Audio.js"; import { Audio } from "@components/PageComponents/ModuleConfig/Audio.tsx";
import { CannedMessage } from "@components/PageComponents/ModuleConfig/CannedMessage.js"; import { CannedMessage } from "@components/PageComponents/ModuleConfig/CannedMessage.tsx";
import { ExternalNotification } from "@components/PageComponents/ModuleConfig/ExternalNotification.js"; import { ExternalNotification } from "@components/PageComponents/ModuleConfig/ExternalNotification.tsx";
import { MQTT } from "@components/PageComponents/ModuleConfig/MQTT.js"; import { MQTT } from "@components/PageComponents/ModuleConfig/MQTT.tsx";
import { Paxcounter } from "@components/PageComponents/ModuleConfig/Paxcounter.js"; import { Paxcounter } from "@components/PageComponents/ModuleConfig/Paxcounter.tsx";
import { RangeTest } from "@components/PageComponents/ModuleConfig/RangeTest.js"; import { RangeTest } from "@components/PageComponents/ModuleConfig/RangeTest.tsx";
import { Serial } from "@components/PageComponents/ModuleConfig/Serial.js"; import { Serial } from "@components/PageComponents/ModuleConfig/Serial.tsx";
import { StoreForward } from "@components/PageComponents/ModuleConfig/StoreForward.js"; import { StoreForward } from "@components/PageComponents/ModuleConfig/StoreForward.tsx";
import { Telemetry } from "@components/PageComponents/ModuleConfig/Telemetry.js"; import { Telemetry } from "@components/PageComponents/ModuleConfig/Telemetry.tsx";
import { import {
Tabs, Tabs,
TabsContent, TabsContent,
TabsList, TabsList,
TabsTrigger, TabsTrigger,
} from "@components/UI/Tabs.js"; } from "@components/UI/Tabs.tsx";
export const ModuleConfig = (): JSX.Element => { export const ModuleConfig = (): JSX.Element => {
const tabs = [ const tabs = [

16
src/pages/Config/index.tsx

@ -1,11 +1,11 @@
import { useDevice } from "@app/core/stores/deviceStore.js"; import { useDevice } from "@app/core/stores/deviceStore.ts";
import { PageLayout } from "@components/PageLayout.js"; import { PageLayout } from "@components/PageLayout.tsx";
import { Sidebar } from "@components/Sidebar.js"; import { Sidebar } from "@components/Sidebar.tsx";
import { SidebarSection } from "@components/UI/Sidebar/SidebarSection.js"; import { SidebarSection } from "@components/UI/Sidebar/SidebarSection.tsx";
import { SidebarButton } from "@components/UI/Sidebar/sidebarButton.js"; import { SidebarButton } from "@components/UI/Sidebar/sidebarButton.tsx";
import { useToast } from "@core/hooks/useToast.js"; import { useToast } from "@core/hooks/useToast.ts";
import { DeviceConfig } from "@pages/Config/DeviceConfig.js"; import { DeviceConfig } from "@pages/Config/DeviceConfig.tsx";
import { ModuleConfig } from "@pages/Config/ModuleConfig.js"; import { ModuleConfig } from "@pages/Config/ModuleConfig.tsx";
import { BoxesIcon, SaveIcon, SettingsIcon } from "lucide-react"; import { BoxesIcon, SaveIcon, SettingsIcon } from "lucide-react";
import { useState } from "react"; import { useState } from "react";

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save