Compare commits

...

17 Commits

Author SHA1 Message Date
Sevi 05a3613fc6
Merge c2219d1d15 into 63aa940f42 2025-10-01 22:43:20 +02:00
Sevi c2219d1d15
Merge branch 'dev' into feat/custom-serial-buttons 2025-10-01 22:43:16 +02:00
Severin Müller c07ae51da3 Merge extensions "Serial Console" and "Serial Buttons" 2025-10-01 22:34:25 +02:00
dependabot[bot] 63aa940f42
build(deps): bump github.com/prometheus/client_golang (#851)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:44:24 +02:00
dependabot[bot] 043ef9ddfc
build(deps): bump github.com/gin-gonic/gin from 1.10.1 to 1.11.0 (#852)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:44:08 +02:00
Marc Brooks 437f0b854a
upgrade ui packages (#861) 2025-10-01 21:43:46 +02:00
dependabot[bot] a45d55123c
build(deps): bump github.com/prometheus/common from 0.66.0 to 0.66.1 (#855)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:42:08 +02:00
dependabot[bot] 213e750e04
build(deps): bump github.com/coder/websocket from 1.8.13 to 1.8.14 (#854)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:41:48 +02:00
dependabot[bot] 6dcb0286e3
build(deps): bump golang.org/x/net from 0.43.0 to 0.44.0 (#856)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:40:57 +02:00
dependabot[bot] 74ccca0b1a
build(deps): bump golang.org/x/crypto from 0.41.0 to 0.42.0 (#849)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:39:31 +02:00
dependabot[bot] 0ad435475b
build(deps): bump github.com/go-co-op/gocron/v2 from 2.16.5 to 2.16.6 (#859)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:39:15 +02:00
dependabot[bot] 23bf3978fa
build(deps): bump actions/setup-go from 5 to 6 (#848)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-01 21:35:35 +02:00
Sevi cfd5e7cfab
Merge branch 'jetkvm:dev' into feat/custom-serial-buttons 2025-09-24 22:21:06 +02:00
Severin Müller 67e9136b03 Add order buttons and response field 2025-09-23 22:11:54 +02:00
Severin Müller d8f670fcba Add backend to send custom commands 2025-09-23 16:49:45 +02:00
Sevi b2b3ee40a7
Merge branch 'jetkvm:dev' into dev 2025-09-22 17:11:23 +02:00
Severin Müller b8d4464904 Create new extension "Serial Buttons" 2025-09-22 17:10:58 +02:00
15 changed files with 1628 additions and 498 deletions

View File

@ -43,7 +43,7 @@ jobs:
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Set up Golang
uses: actions/setup-go@v6.0.0
uses: actions/setup-go@v6
with:
go-version: "^1.25.1"
- name: Build frontend

View File

@ -24,7 +24,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v5
- name: Install Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: oldstable
- name: Create empty resource directory

View File

@ -104,7 +104,7 @@ jobs:
EOF
ssh jkci "cat /tmp/device-tests.json" > device-tests.json
- name: Set up Golang
uses: actions/setup-go@v5.5.0
uses: actions/setup-go@v6
with:
go-version: "1.24.4"
- name: Golang Test Report

48
go.mod
View File

@ -5,13 +5,14 @@ go 1.24.4
require (
github.com/Masterminds/semver/v3 v3.4.0
github.com/beevik/ntp v1.4.3
github.com/coder/websocket v1.8.13
github.com/coder/websocket v1.8.14
github.com/coreos/go-oidc/v3 v3.15.0
github.com/creack/pty v1.1.24
github.com/erikdubbelboer/gspt v0.0.0-20210805194459-ce36a5128377
github.com/fsnotify/fsnotify v1.9.0
github.com/gin-contrib/logger v1.2.6
github.com/gin-gonic/gin v1.10.1
github.com/go-co-op/gocron/v2 v2.16.5
github.com/gin-gonic/gin v1.11.0
github.com/go-co-op/gocron/v2 v2.16.6
github.com/google/uuid v1.6.0
github.com/guregu/null/v6 v6.0.0
github.com/gwatts/rootcerts v0.0.0-20250901182336-dc5ae18bd79f
@ -19,8 +20,8 @@ require (
github.com/pion/mdns/v2 v2.0.7
github.com/pion/webrtc/v4 v4.1.4
github.com/pojntfx/go-nbd v0.3.2
github.com/prometheus/client_golang v1.23.0
github.com/prometheus/common v0.66.0
github.com/prometheus/client_golang v1.23.2
github.com/prometheus/common v0.66.1
github.com/prometheus/procfs v0.17.0
github.com/psanford/httpreadat v0.1.0
github.com/rs/xid v1.6.0
@ -30,37 +31,32 @@ require (
github.com/vearutop/statigz v1.5.0
github.com/vishvananda/netlink v1.3.1
go.bug.st/serial v1.6.4
golang.org/x/crypto v0.41.0
golang.org/x/net v0.43.0
golang.org/x/sys v0.35.0
golang.org/x/crypto v0.42.0
golang.org/x/net v0.44.0
golang.org/x/sys v0.36.0
)
replace github.com/pojntfx/go-nbd v0.3.2 => github.com/chemhack/go-nbd v0.0.0-20241006125820-59e45f5b1e7b
require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.13.3 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/bytedance/sonic v1.14.0 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/creack/goselect v0.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/erikdubbelboer/gspt v0.0.0-20210805194459-ce36a5128377 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.0 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.26.0 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
github.com/jpillora/overseer v1.1.6 // indirect
github.com/jpillora/s3 v1.1.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
@ -84,16 +80,22 @@ require (
github.com/pion/turn/v4 v4.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.54.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
github.com/vishvananda/netns v0.0.5 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
golang.org/x/arch v0.18.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/arch v0.20.0 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/text v0.28.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/tools v0.36.0 // indirect
google.golang.org/protobuf v1.36.9 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

104
go.sum
View File

@ -1,7 +1,5 @@
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho=
@ -10,20 +8,18 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bool64/dev v0.2.39 h1:kP8DnMGlWXhGYJEZE/J0l/gVBdbuhoPGL+MJG4QbofE=
github.com/bool64/dev v0.2.39/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chemhack/go-nbd v0.0.0-20241006125820-59e45f5b1e7b h1:dSbDgy72Y1sjLPWLv7vs0fMFuhMBMViiT9PJZiZWZNs=
github.com/chemhack/go-nbd v0.0.0-20241006125820-59e45f5b1e7b/go.mod h1:SehHnbi2e8NiSAKby42Itm8SIoS7b+wAprsfPH3qgYk=
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/coreos/go-oidc/v3 v3.15.0 h1:R6Oz8Z4bqWR7VFQ+sPSvZPQv4x8M+sJkDO5ojgwlyAg=
github.com/coreos/go-oidc/v3 v3.15.0/go.mod h1:HaZ3szPaZ0e4r6ebqvsLWlk2Tn+aejfmrfah6hnSYEU=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
@ -44,50 +40,42 @@ github.com/gin-contrib/logger v1.2.6 h1:EPolruKUTzNXMVBD9LuAFQmRjTs7AH7yKGuXgYqr
github.com/gin-contrib/logger v1.2.6/go.mod h1:7niPrd7F0Nscw/zvgz8RiGJxSdbKM2yfQNy8xCHcm64=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-co-op/gocron/v2 v2.16.5 h1:j228Jxk7bb9CF8LKR3gS+bK3rcjRUINjlVI+ZMp26Ss=
github.com/go-co-op/gocron/v2 v2.16.5/go.mod h1:zAfC/GFQ668qHxOVl/D68Jh5Ce7sDqX6TJnSQyRkRBc=
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
github.com/go-co-op/gocron/v2 v2.16.6 h1:zI2Ya9sqvuLcgqJgV79LwoJXM8h20Z/drtB7ATbpRWo=
github.com/go-co-op/gocron/v2 v2.16.6/go.mod h1:zAfC/GFQ668qHxOVl/D68Jh5Ce7sDqX6TJnSQyRkRBc=
github.com/go-jose/go-jose/v4 v4.1.0 h1:cYSYxd3pw5zd2FSXk2vGdn9igQU2PS8MuxrCOCl0FdY=
github.com/go-jose/go-jose/v4 v4.1.0/go.mod h1:GG/vqmYm3Von2nYiB2vGTXzdoNKE5tix5tuc6iAd+sw=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=
github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248=
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
github.com/guregu/null/v6 v6.0.0 h1:N14VRS+4di81i1PXRiprbQJ9EM9gqBa0+KVMeS/QSjQ=
github.com/guregu/null/v6 v6.0.0/go.mod h1:hrMIhIfrOZeLPZhROSn149tpw2gHkidAqxoXNyeX3iQ=
github.com/gwatts/rootcerts v0.0.0-20250901182336-dc5ae18bd79f h1:08t2PbrkDgW2+mwCQ3jhKUBrCM9Bc9SeH5j2Dst3B+0=
github.com/gwatts/rootcerts v0.0.0-20250901182336-dc5ae18bd79f/go.mod h1:5Kt9XkWvkGi2OHOq0QsGxebHmhCcqJ8KCbNg/a6+n+g=
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60=
github.com/jpillora/overseer v1.1.6 h1:3ygYfNcR3FfOr22miu3vR1iQcXKMHbmULBh98rbkIyo=
github.com/jpillora/overseer v1.1.6/go.mod h1:aPXQtxuVb9PVWRWTXpo+LdnC/YXQ0IBLNXqKMJmgk88=
github.com/jpillora/s3 v1.1.4 h1:YCCKDWzb/Ye9EBNd83ATRF/8wPEy0xd43Rezb6u6fzc=
github.com/jpillora/s3 v1.1.4/go.mod h1:yedE603V+crlFi1Kl/5vZJaBu9pUzE9wvKegU/lF2zs=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@ -152,16 +140,20 @@ github.com/pion/webrtc/v4 v4.1.4/go.mod h1:Oab9npu1iZtQRMic3K3toYq5zFPvToe/QBw7d
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.66.0 h1:K/rJPHrG3+AoQs50r2+0t7zMnMzek2Vbv31OFVsMeVY=
github.com/prometheus/common v0.66.0/go.mod h1:Ux6NtV1B4LatamKE63tJBntoxD++xmtI/lK0VtEplN4=
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
github.com/psanford/httpreadat v0.1.0 h1:VleW1HS2zO7/4c7c7zNl33fO6oYACSagjJIyMIwZLUE=
github.com/psanford/httpreadat v0.1.0/go.mod h1:Zg7P+TlBm3bYbyHTKv/EdtSJZn3qwbPwpfZ/I9GKCRE=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
@ -170,15 +162,12 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/gunit v1.1.3/go.mod h1:EH5qMBab2UclzXUcpR8b93eHsIlp9u+pDQIRp5DZNzQ=
github.com/sourcegraph/tf-dag v0.2.2-0.20250131204052-3e8ff1477b4f h1:VgoRCP1efSCEZIcF2THLQ46+pIBzzgNiaUBe9wEDwYU=
github.com/sourcegraph/tf-dag v0.2.2-0.20250131204052-3e8ff1477b4f/go.mod h1:pzro7BGorij2WgrjEammtrkbo3+xldxo+KaGLGUiD+Q=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@ -200,33 +189,40 @@ go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
go.bug.st/serial v1.6.4/go.mod h1:nofMJxTeNVny/m6+KaafC6vJGj3miwQZ6vW4BZUGJPI=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

View File

@ -772,6 +772,8 @@ func rpcSetActiveExtension(extensionId string) error {
_ = unmountATXControl()
case "dc-power":
_ = unmountDCControl()
case "serial-buttons":
_ = unmountSerialButtons()
}
config.ActiveExtension = extensionId
if err := SaveConfig(); err != nil {
@ -782,6 +784,8 @@ func rpcSetActiveExtension(extensionId string) error {
_ = mountATXControl()
case "dc-power":
_ = mountDCControl()
case "serial-buttons":
_ = mountSerialButtons()
}
return nil
}
@ -816,6 +820,15 @@ func rpcGetATXState() (ATXState, error) {
return state, nil
}
func rpcSendCustomCommand(command string, terminator string) error {
logger.Debug().Str("Command", command).Msg("JSONRPC: Sending custom serial command")
err := sendCustomCommand(command, terminator)
if err != nil {
return fmt.Errorf("failed to send custom command in jsonrpc: %w", err)
}
return nil
}
type SerialSettings struct {
BaudRate string `json:"baudRate"`
DataBits string `json:"dataBits"`
@ -907,6 +920,54 @@ func rpcSetSerialSettings(settings SerialSettings) error {
return nil
}
func rpcGetSerialButtonConfig() (CustomButtonSettings, error) {
return getSerialSettings()
}
func rpcSetSerialButtonConfig(config CustomButtonSettings) error {
return setSerialSettings(config)
}
const SerialCommandHistoryPath = "/userdata/serialCommandHistory.json"
func rpcGetSerialCommandHistory() ([]string, error) {
items := []string{}
file, err := os.Open(SerialCommandHistoryPath)
if err != nil {
logger.Debug().Msg("SerialCommandHistory file doesn't exist, using default")
return items, nil
}
defer file.Close()
// load and merge the default config with the user config
var loadedItems []string
if err := json.NewDecoder(file).Decode(&loadedItems); err != nil {
logger.Warn().Err(err).Msg("SerialCommandHistory file JSON parsing failed")
return items, nil
}
return loadedItems, nil
}
func rpcSetSerialCommandHistory(commandHistory []string) error {
logger.Trace().Str("path", SerialCommandHistoryPath).Msg("Saving serial command history")
file, err := os.Create(SerialCommandHistoryPath)
if err != nil {
return fmt.Errorf("failed to create SerialCommandHistory file: %w", err)
}
defer file.Close()
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
if err := encoder.Encode(commandHistory); err != nil {
return fmt.Errorf("failed to encode SerialCommandHistory: %w", err)
}
return nil
}
func rpcGetUsbDevices() (usbgadget.Devices, error) {
return *config.UsbDevices, nil
}
@ -1182,89 +1243,94 @@ func rpcDoExecuteKeyboardMacro(ctx context.Context, macro []hidrpc.KeyboardMacro
}
var rpcHandlers = map[string]RPCHandler{
"ping": {Func: rpcPing},
"reboot": {Func: rpcReboot, Params: []string{"force"}},
"getDeviceID": {Func: rpcGetDeviceID},
"deregisterDevice": {Func: rpcDeregisterDevice},
"getCloudState": {Func: rpcGetCloudState},
"getNetworkState": {Func: rpcGetNetworkState},
"getNetworkSettings": {Func: rpcGetNetworkSettings},
"setNetworkSettings": {Func: rpcSetNetworkSettings, Params: []string{"settings"}},
"renewDHCPLease": {Func: rpcRenewDHCPLease},
"getKeyboardLedState": {Func: rpcGetKeyboardLedState},
"getKeyDownState": {Func: rpcGetKeysDownState},
"keyboardReport": {Func: rpcKeyboardReport, Params: []string{"modifier", "keys"}},
"keypressReport": {Func: rpcKeypressReport, Params: []string{"key", "press"}},
"absMouseReport": {Func: rpcAbsMouseReport, Params: []string{"x", "y", "buttons"}},
"relMouseReport": {Func: rpcRelMouseReport, Params: []string{"dx", "dy", "buttons"}},
"wheelReport": {Func: rpcWheelReport, Params: []string{"wheelY"}},
"getVideoState": {Func: rpcGetVideoState},
"getUSBState": {Func: rpcGetUSBState},
"unmountImage": {Func: rpcUnmountImage},
"rpcMountBuiltInImage": {Func: rpcMountBuiltInImage, Params: []string{"filename"}},
"setJigglerState": {Func: rpcSetJigglerState, Params: []string{"enabled"}},
"getJigglerState": {Func: rpcGetJigglerState},
"setJigglerConfig": {Func: rpcSetJigglerConfig, Params: []string{"jigglerConfig"}},
"getJigglerConfig": {Func: rpcGetJigglerConfig},
"getTimezones": {Func: rpcGetTimezones},
"sendWOLMagicPacket": {Func: rpcSendWOLMagicPacket, Params: []string{"macAddress"}},
"getStreamQualityFactor": {Func: rpcGetStreamQualityFactor},
"setStreamQualityFactor": {Func: rpcSetStreamQualityFactor, Params: []string{"factor"}},
"getAutoUpdateState": {Func: rpcGetAutoUpdateState},
"setAutoUpdateState": {Func: rpcSetAutoUpdateState, Params: []string{"enabled"}},
"getEDID": {Func: rpcGetEDID},
"setEDID": {Func: rpcSetEDID, Params: []string{"edid"}},
"getVideoLogStatus": {Func: rpcGetVideoLogStatus},
"getDevChannelState": {Func: rpcGetDevChannelState},
"setDevChannelState": {Func: rpcSetDevChannelState, Params: []string{"enabled"}},
"getLocalVersion": {Func: rpcGetLocalVersion},
"getUpdateStatus": {Func: rpcGetUpdateStatus},
"tryUpdate": {Func: rpcTryUpdate},
"getDevModeState": {Func: rpcGetDevModeState},
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
"getSSHKeyState": {Func: rpcGetSSHKeyState},
"setSSHKeyState": {Func: rpcSetSSHKeyState, Params: []string{"sshKey"}},
"getTLSState": {Func: rpcGetTLSState},
"setTLSState": {Func: rpcSetTLSState, Params: []string{"state"}},
"setMassStorageMode": {Func: rpcSetMassStorageMode, Params: []string{"mode"}},
"getMassStorageMode": {Func: rpcGetMassStorageMode},
"isUpdatePending": {Func: rpcIsUpdatePending},
"getUsbEmulationState": {Func: rpcGetUsbEmulationState},
"setUsbEmulationState": {Func: rpcSetUsbEmulationState, Params: []string{"enabled"}},
"getUsbConfig": {Func: rpcGetUsbConfig},
"setUsbConfig": {Func: rpcSetUsbConfig, Params: []string{"usbConfig"}},
"checkMountUrl": {Func: rpcCheckMountUrl, Params: []string{"url"}},
"getVirtualMediaState": {Func: rpcGetVirtualMediaState},
"getStorageSpace": {Func: rpcGetStorageSpace},
"mountWithHTTP": {Func: rpcMountWithHTTP, Params: []string{"url", "mode"}},
"mountWithStorage": {Func: rpcMountWithStorage, Params: []string{"filename", "mode"}},
"listStorageFiles": {Func: rpcListStorageFiles},
"deleteStorageFile": {Func: rpcDeleteStorageFile, Params: []string{"filename"}},
"startStorageFileUpload": {Func: rpcStartStorageFileUpload, Params: []string{"filename", "size"}},
"getWakeOnLanDevices": {Func: rpcGetWakeOnLanDevices},
"setWakeOnLanDevices": {Func: rpcSetWakeOnLanDevices, Params: []string{"params"}},
"resetConfig": {Func: rpcResetConfig},
"setDisplayRotation": {Func: rpcSetDisplayRotation, Params: []string{"params"}},
"getDisplayRotation": {Func: rpcGetDisplayRotation},
"setBacklightSettings": {Func: rpcSetBacklightSettings, Params: []string{"params"}},
"getBacklightSettings": {Func: rpcGetBacklightSettings},
"getDCPowerState": {Func: rpcGetDCPowerState},
"setDCPowerState": {Func: rpcSetDCPowerState, Params: []string{"enabled"}},
"setDCRestoreState": {Func: rpcSetDCRestoreState, Params: []string{"state"}},
"getActiveExtension": {Func: rpcGetActiveExtension},
"setActiveExtension": {Func: rpcSetActiveExtension, Params: []string{"extensionId"}},
"getATXState": {Func: rpcGetATXState},
"setATXPowerAction": {Func: rpcSetATXPowerAction, Params: []string{"action"}},
"getSerialSettings": {Func: rpcGetSerialSettings},
"setSerialSettings": {Func: rpcSetSerialSettings, Params: []string{"settings"}},
"getUsbDevices": {Func: rpcGetUsbDevices},
"setUsbDevices": {Func: rpcSetUsbDevices, Params: []string{"devices"}},
"setUsbDeviceState": {Func: rpcSetUsbDeviceState, Params: []string{"device", "enabled"}},
"setCloudUrl": {Func: rpcSetCloudUrl, Params: []string{"apiUrl", "appUrl"}},
"getKeyboardLayout": {Func: rpcGetKeyboardLayout},
"setKeyboardLayout": {Func: rpcSetKeyboardLayout, Params: []string{"layout"}},
"getKeyboardMacros": {Func: getKeyboardMacros},
"setKeyboardMacros": {Func: setKeyboardMacros, Params: []string{"params"}},
"getLocalLoopbackOnly": {Func: rpcGetLocalLoopbackOnly},
"setLocalLoopbackOnly": {Func: rpcSetLocalLoopbackOnly, Params: []string{"enabled"}},
"ping": {Func: rpcPing},
"reboot": {Func: rpcReboot, Params: []string{"force"}},
"getDeviceID": {Func: rpcGetDeviceID},
"deregisterDevice": {Func: rpcDeregisterDevice},
"getCloudState": {Func: rpcGetCloudState},
"getNetworkState": {Func: rpcGetNetworkState},
"getNetworkSettings": {Func: rpcGetNetworkSettings},
"setNetworkSettings": {Func: rpcSetNetworkSettings, Params: []string{"settings"}},
"renewDHCPLease": {Func: rpcRenewDHCPLease},
"getKeyboardLedState": {Func: rpcGetKeyboardLedState},
"getKeyDownState": {Func: rpcGetKeysDownState},
"keyboardReport": {Func: rpcKeyboardReport, Params: []string{"modifier", "keys"}},
"keypressReport": {Func: rpcKeypressReport, Params: []string{"key", "press"}},
"absMouseReport": {Func: rpcAbsMouseReport, Params: []string{"x", "y", "buttons"}},
"relMouseReport": {Func: rpcRelMouseReport, Params: []string{"dx", "dy", "buttons"}},
"wheelReport": {Func: rpcWheelReport, Params: []string{"wheelY"}},
"getVideoState": {Func: rpcGetVideoState},
"getUSBState": {Func: rpcGetUSBState},
"unmountImage": {Func: rpcUnmountImage},
"rpcMountBuiltInImage": {Func: rpcMountBuiltInImage, Params: []string{"filename"}},
"setJigglerState": {Func: rpcSetJigglerState, Params: []string{"enabled"}},
"getJigglerState": {Func: rpcGetJigglerState},
"setJigglerConfig": {Func: rpcSetJigglerConfig, Params: []string{"jigglerConfig"}},
"getJigglerConfig": {Func: rpcGetJigglerConfig},
"getTimezones": {Func: rpcGetTimezones},
"sendWOLMagicPacket": {Func: rpcSendWOLMagicPacket, Params: []string{"macAddress"}},
"getStreamQualityFactor": {Func: rpcGetStreamQualityFactor},
"setStreamQualityFactor": {Func: rpcSetStreamQualityFactor, Params: []string{"factor"}},
"getAutoUpdateState": {Func: rpcGetAutoUpdateState},
"setAutoUpdateState": {Func: rpcSetAutoUpdateState, Params: []string{"enabled"}},
"getEDID": {Func: rpcGetEDID},
"setEDID": {Func: rpcSetEDID, Params: []string{"edid"}},
"getVideoLogStatus": {Func: rpcGetVideoLogStatus},
"getDevChannelState": {Func: rpcGetDevChannelState},
"setDevChannelState": {Func: rpcSetDevChannelState, Params: []string{"enabled"}},
"getLocalVersion": {Func: rpcGetLocalVersion},
"getUpdateStatus": {Func: rpcGetUpdateStatus},
"tryUpdate": {Func: rpcTryUpdate},
"getDevModeState": {Func: rpcGetDevModeState},
"setDevModeState": {Func: rpcSetDevModeState, Params: []string{"enabled"}},
"getSSHKeyState": {Func: rpcGetSSHKeyState},
"setSSHKeyState": {Func: rpcSetSSHKeyState, Params: []string{"sshKey"}},
"getTLSState": {Func: rpcGetTLSState},
"setTLSState": {Func: rpcSetTLSState, Params: []string{"state"}},
"setMassStorageMode": {Func: rpcSetMassStorageMode, Params: []string{"mode"}},
"getMassStorageMode": {Func: rpcGetMassStorageMode},
"isUpdatePending": {Func: rpcIsUpdatePending},
"getUsbEmulationState": {Func: rpcGetUsbEmulationState},
"setUsbEmulationState": {Func: rpcSetUsbEmulationState, Params: []string{"enabled"}},
"getUsbConfig": {Func: rpcGetUsbConfig},
"setUsbConfig": {Func: rpcSetUsbConfig, Params: []string{"usbConfig"}},
"checkMountUrl": {Func: rpcCheckMountUrl, Params: []string{"url"}},
"getVirtualMediaState": {Func: rpcGetVirtualMediaState},
"getStorageSpace": {Func: rpcGetStorageSpace},
"mountWithHTTP": {Func: rpcMountWithHTTP, Params: []string{"url", "mode"}},
"mountWithStorage": {Func: rpcMountWithStorage, Params: []string{"filename", "mode"}},
"listStorageFiles": {Func: rpcListStorageFiles},
"deleteStorageFile": {Func: rpcDeleteStorageFile, Params: []string{"filename"}},
"startStorageFileUpload": {Func: rpcStartStorageFileUpload, Params: []string{"filename", "size"}},
"getWakeOnLanDevices": {Func: rpcGetWakeOnLanDevices},
"setWakeOnLanDevices": {Func: rpcSetWakeOnLanDevices, Params: []string{"params"}},
"resetConfig": {Func: rpcResetConfig},
"setDisplayRotation": {Func: rpcSetDisplayRotation, Params: []string{"params"}},
"getDisplayRotation": {Func: rpcGetDisplayRotation},
"setBacklightSettings": {Func: rpcSetBacklightSettings, Params: []string{"params"}},
"getBacklightSettings": {Func: rpcGetBacklightSettings},
"getDCPowerState": {Func: rpcGetDCPowerState},
"setDCPowerState": {Func: rpcSetDCPowerState, Params: []string{"enabled"}},
"setDCRestoreState": {Func: rpcSetDCRestoreState, Params: []string{"state"}},
"getActiveExtension": {Func: rpcGetActiveExtension},
"setActiveExtension": {Func: rpcSetActiveExtension, Params: []string{"extensionId"}},
"getATXState": {Func: rpcGetATXState},
"setATXPowerAction": {Func: rpcSetATXPowerAction, Params: []string{"action"}},
"sendCustomCommand": {Func: rpcSendCustomCommand, Params: []string{"command", "terminator"}},
"getSerialSettings": {Func: rpcGetSerialSettings},
"setSerialSettings": {Func: rpcSetSerialSettings, Params: []string{"settings"}},
"getSerialButtonConfig": {Func: rpcGetSerialButtonConfig},
"setSerialButtonConfig": {Func: rpcSetSerialButtonConfig, Params: []string{"config"}},
"getSerialCommandHistory": {Func: rpcGetSerialCommandHistory},
"setSerialCommandHistory": {Func: rpcSetSerialCommandHistory, Params: []string{"commandHistory"}},
"getUsbDevices": {Func: rpcGetUsbDevices},
"setUsbDevices": {Func: rpcSetUsbDevices, Params: []string{"devices"}},
"setUsbDeviceState": {Func: rpcSetUsbDeviceState, Params: []string{"device", "enabled"}},
"setCloudUrl": {Func: rpcSetCloudUrl, Params: []string{"apiUrl", "appUrl"}},
"getKeyboardLayout": {Func: rpcGetKeyboardLayout},
"setKeyboardLayout": {Func: rpcSetKeyboardLayout, Params: []string{"layout"}},
"getKeyboardMacros": {Func: getKeyboardMacros},
"setKeyboardMacros": {Func: setKeyboardMacros, Params: []string{"params"}},
"getLocalLoopbackOnly": {Func: rpcGetLocalLoopbackOnly},
"setLocalLoopbackOnly": {Func: rpcSetLocalLoopbackOnly, Params: []string{"enabled"}},
}

230
serial.go
View File

@ -2,7 +2,11 @@ package kvm
import (
"bufio"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
@ -251,6 +255,89 @@ func setDCRestoreState(state int) error {
return nil
}
func mountSerialButtons() error {
_ = port.SetMode(defaultMode)
startSerialButtonsRxLoop(currentSession)
return nil
}
func unmountSerialButtons() error {
stopSerialButtonsRxLoop()
_ = reopenSerialPort()
return nil
}
// ---- Serial Buttons RX fan-out (JSON-RPC events) ----
var serialButtonsRXStopCh chan struct{}
func startSerialButtonsRxLoop(session *Session) {
scopedLogger := serialLogger.With().Str("service", "custom_buttons_rx").Logger()
scopedLogger.Debug().Msg("Attempting to start RX reader.")
// Stop previous loop if running
if serialButtonsRXStopCh != nil {
stopSerialButtonsRxLoop()
}
serialButtonsRXStopCh = make(chan struct{})
go func() {
buf := make([]byte, 4096)
scopedLogger.Debug().Msg("Starting loop")
for {
select {
case <-serialButtonsRXStopCh:
return
default:
if currentSession == nil {
time.Sleep(500 * time.Millisecond)
continue
}
n, err := port.Read(buf)
if err != nil {
if err != io.EOF {
scopedLogger.Debug().Err(err).Msg("serial RX read error")
}
time.Sleep(50 * time.Millisecond)
continue
}
if n == 0 {
continue
}
// Safe for any bytes: wrap in Base64
b64 := base64.StdEncoding.EncodeToString(buf[:n])
writeJSONRPCEvent("serial.rx", map[string]any{
"base64": b64,
}, currentSession)
}
}
}()
}
func stopSerialButtonsRxLoop() {
scopedLogger := serialLogger.With().Str("service", "custom_buttons_rx").Logger()
scopedLogger.Debug().Msg("Stopping RX reader.")
if serialButtonsRXStopCh != nil {
close(serialButtonsRXStopCh)
serialButtonsRXStopCh = nil
}
}
func sendCustomCommand(command string, terminator string) error {
scopedLogger := serialLogger.With().Str("service", "custom_buttons_tx").Logger()
scopedLogger.Info().Str("Command", command).Msg("Sending custom command.")
_, err := port.Write([]byte(terminator))
if err != nil {
scopedLogger.Warn().Err(err).Msg("Failed to send terminator")
return err
}
_, err = port.Write([]byte(command))
if err != nil {
scopedLogger.Warn().Err(err).Str("Command", command).Msg("Failed to send serial command")
return err
}
return nil
}
var defaultMode = &serial.Mode{
BaudRate: 115200,
DataBits: 8,
@ -258,6 +345,149 @@ var defaultMode = &serial.Mode{
StopBits: serial.OneStopBit,
}
const serialSettingsPath = "/userdata/serialSettings.json"
type Terminator struct {
Label string `json:"label"` // Terminator label
Value string `json:"value"` // Terminator value
}
type QuickButton struct {
Id string `json:"id"` // Unique identifier
Label string `json:"label"` // Button label
Command string `json:"command"` // Command to send, raw command to send (without auto-terminator)
Terminator Terminator `json:"terminator"` // Terminator to use: None/CR/LF/CRLF/LFCR
Sort int `json:"sort"` // Sort order
}
// Mode describes a serial port configuration.
type CustomButtonSettings struct {
BaudRate string `json:"baudRate"` // The serial port bitrate (aka Baudrate)
DataBits string `json:"dataBits"` // Size of the character (must be 5, 6, 7 or 8)
Parity string `json:"parity"` // Parity (see Parity type for more info)
StopBits string `json:"stopBits"` // Stop bits (see StopBits type for more info)
Terminator Terminator `json:"terminator"` // Terminator to send after each command
LineMode bool `json:"lineMode"` // Whether to send each line when Enter is pressed, or each character immediately
HideSerialSettings bool `json:"hideSerialSettings"` // Whether to hide the serial settings in the UI
EnableEcho bool `json:"enableEcho"` // Whether to echo received characters back to the sender
Buttons []QuickButton `json:"buttons"` // Custom quick buttons
}
func getSerialSettings() (CustomButtonSettings, error) {
config := CustomButtonSettings{
BaudRate: strconv.Itoa(defaultMode.BaudRate),
DataBits: strconv.Itoa(defaultMode.DataBits),
Parity: "none",
StopBits: "1",
Terminator: Terminator{Label: "CR (\\r)", Value: "\r"},
LineMode: true,
HideSerialSettings: false,
EnableEcho: false,
Buttons: []QuickButton{},
}
switch defaultMode.StopBits {
case serial.OneStopBit:
config.StopBits = "1"
case serial.OnePointFiveStopBits:
config.StopBits = "1.5"
case serial.TwoStopBits:
config.StopBits = "2"
}
switch defaultMode.Parity {
case serial.NoParity:
config.Parity = "none"
case serial.OddParity:
config.Parity = "odd"
case serial.EvenParity:
config.Parity = "even"
case serial.MarkParity:
config.Parity = "mark"
case serial.SpaceParity:
config.Parity = "space"
}
file, err := os.Open(serialSettingsPath)
if err != nil {
logger.Debug().Msg("SerialButtons config file doesn't exist, using default")
return config, err
}
defer file.Close()
// load and merge the default config with the user config
var loadedConfig CustomButtonSettings
if err := json.NewDecoder(file).Decode(&loadedConfig); err != nil {
logger.Warn().Err(err).Msg("SerialButtons config file JSON parsing failed")
return config, nil
}
return loadedConfig, nil
}
func setSerialSettings(newSettings CustomButtonSettings) error {
logger.Trace().Str("path", serialSettingsPath).Msg("Saving config")
file, err := os.Create(serialSettingsPath)
if err != nil {
return fmt.Errorf("failed to create SerialButtons config file: %w", err)
}
defer file.Close()
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
if err := encoder.Encode(newSettings); err != nil {
return fmt.Errorf("failed to encode SerialButtons config: %w", err)
}
baudRate, err := strconv.Atoi(newSettings.BaudRate)
if err != nil {
return fmt.Errorf("invalid baud rate: %v", err)
}
dataBits, err := strconv.Atoi(newSettings.DataBits)
if err != nil {
return fmt.Errorf("invalid data bits: %v", err)
}
var stopBits serial.StopBits
switch newSettings.StopBits {
case "1":
stopBits = serial.OneStopBit
case "1.5":
stopBits = serial.OnePointFiveStopBits
case "2":
stopBits = serial.TwoStopBits
default:
return fmt.Errorf("invalid stop bits: %s", newSettings.StopBits)
}
var parity serial.Parity
switch newSettings.Parity {
case "none":
parity = serial.NoParity
case "odd":
parity = serial.OddParity
case "even":
parity = serial.EvenParity
case "mark":
parity = serial.MarkParity
case "space":
parity = serial.SpaceParity
default:
return fmt.Errorf("invalid parity: %s", newSettings.Parity)
}
serialPortMode = &serial.Mode{
BaudRate: baudRate,
DataBits: dataBits,
StopBits: stopBits,
Parity: parity,
}
_ = port.SetMode(serialPortMode)
return nil
}
func initSerialPort() {
_ = reopenSerialPort()
switch config.ActiveExtension {

640
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "kvm-ui",
"private": true,
"version": "2025.09.26.01300",
"version": "2025.10.01.1900",
"type": "module",
"engines": {
"node": "^22.15.0"
@ -42,7 +42,7 @@
"react-hot-toast": "^2.6.0",
"react-icons": "^5.5.0",
"react-router": "^7.9.3",
"react-simple-keyboard": "^3.8.122",
"react-simple-keyboard": "^3.8.125",
"react-use-websocket": "^4.13.0",
"react-xtermjs": "^1.0.10",
"recharts": "^3.2.1",
@ -56,15 +56,15 @@
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.36.0",
"@tailwindcss/forms": "^0.5.10",
"@tailwindcss/postcss": "^4.1.13",
"@tailwindcss/postcss": "^4.1.14",
"@tailwindcss/typography": "^0.5.19",
"@tailwindcss/vite": "^4.1.13",
"@types/react": "^19.1.14",
"@types/react-dom": "^19.1.9",
"@tailwindcss/vite": "^4.1.14",
"@types/react": "^19.1.17",
"@types/react-dom": "^19.1.10",
"@types/semver": "^7.7.1",
"@types/validator": "^13.15.3",
"@typescript-eslint/eslint-plugin": "^8.44.1",
"@typescript-eslint/parser": "^8.44.1",
"@typescript-eslint/eslint-plugin": "^8.45.0",
"@typescript-eslint/parser": "^8.45.0",
"@vitejs/plugin-react-swc": "^4.1.0",
"autoprefixer": "^10.4.21",
"eslint": "^9.36.0",
@ -77,8 +77,8 @@
"postcss": "^8.5.6",
"prettier": "^3.6.2",
"prettier-plugin-tailwindcss": "^0.6.14",
"tailwindcss": "^4.1.13",
"typescript": "^5.9.2",
"tailwindcss": "^4.1.14",
"typescript": "^5.9.3",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4"
}

View File

@ -0,0 +1,290 @@
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { createPortal } from "react-dom";
import clsx from "clsx";
import InputField from "@/components/InputField"; // your existing input component
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
import notifications from "@/notifications";
interface Hit { value: string; index: number }
// ---------- history hook ----------
function useCommandHistory(max = 300) {
const { send } = useJsonRpc();
const [items, setItems] = useState<string[]>([]);
useEffect(() => {
send("getSerialCommandHistory", {}, (resp: JsonRpcResponse) => {
if ("error" in resp) {
notifications.error(
`Failed to get command history: ${resp.error.data || "Unknown error"}`,
);
} else if ("result" in resp) {
setItems(resp.result as string[]);
}
});
}, [send]);
const [pointer, setPointer] = useState<number>(-1); // -1 = fresh line
const [anchorPrefix, setAnchorPrefix] = useState<string | null>(null);
useEffect(() => {
if (items.length > 1) {
send("setSerialCommandHistory", { commandHistory: items }, (resp: JsonRpcResponse) => {
if ("error" in resp) {
notifications.error(`Failed to update command history: ${resp.error.data || "Unknown error"}`);
return;
}
});
}
}, [items, send]);
const push = useCallback((cmd: string) => {
if (!cmd.trim()) return;
setItems((prev) => {
const next = prev[prev.length - 1] === cmd ? prev : [...prev, cmd];
return next.slice(-max);
});
setPointer(-1);
setAnchorPrefix(null);
}, [max]);
const resetTraversal = useCallback(() => {
setPointer(-1);
setAnchorPrefix(null);
}, []);
const up = useCallback((draft: string) => {
const pref = anchorPrefix ?? draft;
if (anchorPrefix == null) setAnchorPrefix(pref);
let i = pointer < 0 ? items.length - 1 : pointer - 1;
for (; i >= 0; i--) {
if (items[i].startsWith(pref)) {
setPointer(i);
return items[i];
}
}
return draft;
}, [items, pointer, anchorPrefix]);
const down = useCallback((draft: string) => {
const pref = anchorPrefix ?? draft;
if (anchorPrefix == null) setAnchorPrefix(pref);
let i = pointer < 0 ? 0 : pointer + 1;
for (; i < items.length; i++) {
if (items[i].startsWith(pref)) {
setPointer(i);
return items[i];
}
}
setPointer(-1);
return draft;
}, [items, pointer, anchorPrefix]);
const search = useCallback((query: string): Hit[] => {
if (!query) return [];
const q = query.toLowerCase();
return [...items]
.map((value, index) => ({ value, index }))
.filter((x) => x.value.toLowerCase().includes(q))
.reverse(); // newest first
}, [items]);
return { push, up, down, resetTraversal, search };
}
function Portal({ children }: { children: React.ReactNode }) {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) return null;
return createPortal(children, document.body);
}
// ---------- reverse search popup ----------
function ReverseSearch({
open, results, sel, setSel, onPick, onClose,
}: {
open: boolean;
results: Hit[];
sel: number;
setSel: (i: number) => void;
onPick: (val: string) => void;
onClose: () => void;
}) {
const listRef = React.useRef<HTMLDivElement>(null);
// keep selected item in view when sel changes
useEffect(() => {
if (!listRef.current) return;
const el = listRef.current.querySelector<HTMLDivElement>(`[data-idx="${sel}"]`);
el?.scrollIntoView({ block: "nearest" });
}, [sel, results]);
if (!open) return null;
return (
<Portal>
<div
className="absolute bottom-12 left-0 right-0 ml-17 mr-8 mb-5 rounded-md border border-slate-600 bg-slate-900/95 p-2 shadow-lg"
role="listbox"
aria-activedescendant={`rev-opt-${sel}`}
>
<div ref={listRef} className="max-h-48 overflow-auto">
{results.length === 0 ? (
<div className="px-2 py-1 text-sm text-slate-400">No matches</div>
) : results.map((r, i) => (
<div
id={`rev-opt-${i}`}
data-idx={i}
key={`${r.index}-${i}`}
role="option"
aria-selected={i === sel}
className={clsx(
"px-2 py-1 font-mono text-sm cursor-pointer",
i === sel ? "bg-slate-700 text-white rounded" : "text-slate-200",
)}
onMouseEnter={() => setSel(i)}
onClick={() => onPick(r.value)}
>
{r.value}
</div>
))}
</div>
<div className="mt-1 flex justify-between text-s text-slate-400">
<span>/ select Enter accept Esc close</span>
<button className="underline" onClick={onClose}>Close</button>
</div>
</div>
</Portal>
);
}
// ---------- main component ----------
interface CommandInputProps {
onSend: (line: string) => void; // called on Enter
storageKey?: string; // localStorage key for history
placeholder?: string; // input placeholder
className?: string; // container className
disabled?: boolean; // disable input (optional)
}
export function CommandInput({
onSend,
placeholder = "Type serial command… (Enter to send • ↑/↓ history • Ctrl+R search)",
className,
disabled,
}: CommandInputProps) {
const [cmd, setCmd] = useState("");
const [revOpen, setRevOpen] = useState(false);
const [revQuery, setRevQuery] = useState("");
const [sel, setSel] = useState(0);
const { push, up, down, resetTraversal, search } = useCommandHistory();
const results = useMemo(() => search(revQuery), [revQuery, search]);
useEffect(() => { setSel(0); }, [results]);
const cmdInputRef = React.useRef<HTMLInputElement>(null);
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const isMeta = e.ctrlKey || e.metaKey;
if (e.key === "Enter" && !e.shiftKey && !isMeta) {
e.preventDefault();
if (!cmd) return;
onSend(cmd);
push(cmd);
setCmd("");
resetTraversal();
setRevOpen(false);
return;
}
if (e.key === "ArrowUp") {
e.preventDefault();
setCmd((prev) => up(prev));
return;
}
if (e.key === "ArrowDown") {
e.preventDefault();
setCmd((prev) => down(prev));
return;
}
if (isMeta && e.key.toLowerCase() === "r") {
e.preventDefault();
setRevOpen(true);
setRevQuery(cmd);
setSel(0);
return;
}
if (e.key === "Escape" && revOpen) {
e.preventDefault();
setRevOpen(false);
return;
}
};
return (
<div className={clsx("relative", className)}>
<div className="flex items-center gap-2" style={{visibility: revOpen ? "hidden" : "unset"} }>
<span className="text-xs text-slate-400 select-none">CMD</span>
<InputField
ref={cmdInputRef}
size="MD"
disabled={disabled}
value={cmd}
onChange={(e) => { setCmd(e.target.value); resetTraversal(); }}
onKeyDown={handleKeyDown}
placeholder={placeholder}
className="font-mono"
/>
</div>
{/* Reverse search controls */}
{revOpen && (
<div className="mt-[-40px]">
<div className="flex items-center gap-2 bg-[#0f172a]">
<span className="text-s text-slate-400 select-none">Search</span>
<InputField
size="MD"
autoFocus
value={revQuery}
onChange={(e) => setRevQuery(e.target.value)}
onKeyDown={(e) => {
if (e.key === "ArrowDown") {
e.preventDefault();
setSel((i) => (i + 1) % Math.max(1, results.length));
} else if (e.key === "ArrowUp") {
e.preventDefault();
setSel((i) => (i - 1 + results.length) % Math.max(1, results.length));
} else if (e.key === "Enter") {
e.preventDefault();
const pick = results[sel]?.value ?? results[0]?.value;
if (pick) {
setCmd(pick);
setRevOpen(false);
requestAnimationFrame(() => cmdInputRef.current?.focus());
}
} else if (e.key === "Escape") {
e.preventDefault();
setRevOpen(false);
requestAnimationFrame(() => cmdInputRef.current?.focus());
}
}}
placeholder="Type to filter history…"
className="font-mono"
/>
</div>
<ReverseSearch
open={revOpen}
results={results}
sel={sel}
setSel={setSel}
onPick={(v) => { setCmd(v); setRevOpen(false); requestAnimationFrame(() => cmdInputRef.current?.focus()); }}
onClose={() => {setRevOpen(false); requestAnimationFrame(() => cmdInputRef.current?.focus());}}
/>
</div>
)}
</div>
);
};
export default CommandInput;

View File

@ -1,6 +1,6 @@
import "react-simple-keyboard/build/css/index.css";
import { ChevronDownIcon } from "@heroicons/react/16/solid";
import { useEffect, useMemo } from "react";
import { useEffect, useMemo, useCallback } from "react";
import { useXTerm } from "react-xtermjs";
import { FitAddon } from "@xterm/addon-fit";
import { WebLinksAddon } from "@xterm/addon-web-links";
@ -10,9 +10,11 @@ import { ClipboardAddon } from "@xterm/addon-clipboard";
import { cx } from "@/cva.config";
import { AvailableTerminalTypes, useUiStore } from "@/hooks/stores";
import { CommandInput } from "@/components/CommandInput";
import { Button } from "./Button";
const isWebGl2Supported = !!document.createElement("canvas").getContext("webgl2");
// Terminal theme configuration
@ -65,13 +67,20 @@ function Terminal({
readonly dataChannel: RTCDataChannel;
readonly type: AvailableTerminalTypes;
}) {
const { terminalType, setTerminalType, setDisableVideoFocusTrap } = useUiStore();
const { terminalLineMode, terminalType, setTerminalType, setDisableVideoFocusTrap } = useUiStore();
const { instance, ref } = useXTerm({ options: TERMINAL_CONFIG });
const isTerminalTypeEnabled = useMemo(() => {
console.log("Terminal type:", terminalType, "Checking against:", type);
return terminalType == type;
}, [terminalType, type]);
useEffect(() => {
if (!instance) return;
instance.options.disableStdin = !terminalLineMode;
instance.options.cursorStyle = terminalLineMode ? "bar" : "block";
}, [instance, terminalLineMode]);
useEffect(() => {
setTimeout(() => {
setDisableVideoFocusTrap(isTerminalTypeEnabled);
@ -161,6 +170,11 @@ function Terminal({
};
}, [instance]);
const sendLine = useCallback((line: string) => {
// Just send; echo/normalization handled elsewhere as you planned
dataChannel.send(line + "\r\n"); // adjust CR/LF to taste
}, [dataChannel]);
return (
<div
onKeyDown={e => e.stopPropagation()}
@ -199,7 +213,14 @@ function Terminal({
</div>
<div className="h-[calc(100%-36px)] p-3">
<div ref={ref} style={{ height: "100%", width: "100%" }} />
<div key="serial" ref={ref} style={{height: (terminalType === "serial" && terminalLineMode) ? "90%" : "100%", width: "100%" }} />
{terminalType == "serial" && terminalLineMode && (
<CommandInput
placeholder="Type serial command… (Enter to send • ↑/↓ history • Ctrl+R search)"
onSend={sendLine}
className="mt-2"
/>
)}
</div>
</div>
</div>

View File

@ -0,0 +1,500 @@
import { LuPlus, LuTrash2, LuPencil, LuSettings2, LuEye, LuEyeOff, LuSave, LuArrowBigUp, LuArrowBigDown, LuCircleX, LuTerminal } from "react-icons/lu";
import { useEffect, useMemo, useState } from "react";
import { Button } from "@components/Button";
import Card from "@components/Card";
import { SettingsPageHeader } from "@components/SettingsPageheader";
import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc";
import notifications from "@/notifications";
import { SelectMenuBasic } from "@components/SelectMenuBasic";
import { InputFieldWithLabel } from "@components/InputField";
import { useUiStore } from "@/hooks/stores";
import Checkbox from "../../components/Checkbox";
import { SettingsItem } from "../../routes/devices.$id.settings";
/** ============== Types ============== */
interface QuickButton {
id: string; // uuid-ish
label: string; // shown on the button
command: string; // raw command to send (without auto-terminator)
terminator: {label: string, value: string}; // None/CR/LF/CRLF/LFCR
sort: number; // for stable ordering
}
interface CustomButtonSettings {
baudRate: string;
dataBits: string;
stopBits: string;
parity: string;
terminator: {label: string, value: string}; // None/CR/LF/CRLF/LFCR
lineMode: boolean;
hideSerialSettings: boolean;
enableEcho: boolean; // future use
buttons: QuickButton[];
}
/** ============== Component ============== */
export function SerialButtons() {
const { setTerminalType, setTerminalLineMode } = useUiStore();
// This will receive all JSON-RPC notifications (method + no id)
const { send } = useJsonRpc((payload) => {
if (payload.method !== "serial.rx") return;
// if (paused) return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const p = payload.params as any;
let chunk = "";
if (typeof p?.base64 === "string") {
try {
chunk = atob(p.base64);
} catch {
// ignore malformed base64
}
} else if (typeof p?.data === "string") {
// fallback if you ever send plain text
chunk = p.data;
}
if (!chunk) return;
// Normalize CRLF for display
chunk = chunk.replace(/\r\n/g, "\n");
// setSerialResponse(prev => (prev + chunk).slice(-MAX_CHARS));
});
// extension config (buttons + prefs)
const [buttonConfig, setButtonConfig] = useState<CustomButtonSettings>({
baudRate: "9600",
dataBits: "8",
stopBits: "1",
parity: "none",
terminator: {label: "CR (\\r)", value: "\r"},
lineMode: true,
hideSerialSettings: false,
enableEcho: false,
buttons: [],
});
// editor modal state
const [editorOpen, setEditorOpen] = useState<null | { id?: string }>(null);
const [draftLabel, setDraftLabel] = useState("");
const [draftCmd, setDraftCmd] = useState("");
const [draftTerminator, setDraftTerminator] = useState({label: "CR (\\r)", value: "\r"});
// load serial settings like SerialConsole
useEffect(() => {
send("getSerialButtonConfig", {}, (resp: JsonRpcResponse) => {
if ("error" in resp) {
notifications.error(
`Failed to get button config: ${resp.error.data || "Unknown error"}`,
);
return;
}
setButtonConfig(resp.result as CustomButtonSettings);
setTerminalLineMode((resp.result as CustomButtonSettings).lineMode);
});
}, [send, setTerminalLineMode]);
const handleSerialButtonConfigChange = (config: keyof CustomButtonSettings, value: unknown) => {
const newButtonConfig = { ...buttonConfig, [config]: value };
send("setSerialButtonConfig", { config: newButtonConfig }, (resp: JsonRpcResponse) => {
if ("error" in resp) {
notifications.error(`Failed to update button config: ${resp.error.data || "Unknown error"}`);
return;
}
});
setButtonConfig(newButtonConfig);
};
const onClickButton = (btn: QuickButton) => {
const command = btn.command + btn.terminator.value;
const terminator = btn.terminator.value;
send("sendCustomCommand", { command, terminator }, (resp: JsonRpcResponse) => {
if ("error" in resp) {
notifications.error(
`Failed to send custom command: ${resp.error.data || "Unknown error"}`,
);
}
});
};
/** CRUD helpers */
const addNew = () => {
setEditorOpen({ id: undefined });
setDraftLabel("");
setDraftCmd("");
setDraftTerminator({label: "CR (\\r)", value: "\r"});
};
const editBtn = (btn: QuickButton) => {
setEditorOpen({ id: btn.id });
setDraftLabel(btn.label);
setDraftCmd(btn.command);
setDraftTerminator(btn.terminator);
};
const removeBtn = (id: string) => {
const nextButtons = buttonConfig.buttons.filter(b => b.id !== id).map((b, i) => ({ ...b, sort: i })) ;
handleSerialButtonConfigChange("buttons", stableSort(nextButtons) );
setEditorOpen(null);
};
const moveUpBtn = (id: string) => {
// Make a copy so we don't mutate state directly
const newButtons = [...buttonConfig.buttons];
// Find the index of the button to move
const index = newButtons.findIndex(b => b.id === id);
if (index > 0) {
// Swap with the previous element
[newButtons[index - 1], newButtons[index]] = [
newButtons[index],
newButtons[index - 1],
];
}
// Re-assign sort values
const nextButtons = newButtons.map((b, i) => ({ ...b, sort: i }));
handleSerialButtonConfigChange("buttons", stableSort(nextButtons) );
setEditorOpen(null);
};
const moveDownBtn = (id: string) => {
// Make a copy so we don't mutate state directly
const newButtons = [...buttonConfig.buttons];
// Find the index of the button to move
const index = newButtons.findIndex(b => b.id === id);
if (index >= 0 && index < newButtons.length - 1) {
// Swap with the next element
[newButtons[index], newButtons[index + 1]] = [
newButtons[index + 1],
newButtons[index],
];
}
// Re-assign sort values
const nextButtons = newButtons.map((b, i) => ({ ...b, sort: i }));
handleSerialButtonConfigChange("buttons", stableSort(nextButtons) );
setEditorOpen(null);
};
const saveDraft = () => {
const label = draftLabel.trim() || "Unnamed";
const command = draftCmd;
if (!command) {
notifications.error("Command cannot be empty.");
return;
}
const terminator = draftTerminator;
// if editing, get current id, otherwise undefined => new button
const currentID = editorOpen?.id;
// either update existing or add new
// if new, assign next sort index
// if existing, keep sort index
const nextButtons = currentID
? buttonConfig.buttons.map(b => (b.id === currentID ? { ...b, label, command } : b))
: [...buttonConfig.buttons, { id: genId(), label, command, terminator, sort: buttonConfig.buttons.length }];
handleSerialButtonConfigChange("buttons", stableSort(nextButtons) );
setEditorOpen(null);
};
/** simple reordering: alphabetical by sort, then label */
const sortedButtons = useMemo(() => buttonConfig.buttons, [buttonConfig.buttons]);
return (
<div className="space-y-4">
<SettingsPageHeader
title="Serial Buttons"
description="Quick custom commands over the extension serial port"
/>
<Card className="animate-fadeIn opacity-0">
<div className="space-y-4 p-3">
{/* Top actions */}
<div className="flex flex-wrap justify-around items-center gap-3">
<Button
size="XS"
theme="primary"
LeadingIcon={buttonConfig.hideSerialSettings ? LuEye : LuEyeOff}
text={buttonConfig.hideSerialSettings ? "Show Settings" : "Hide Settings"}
onClick={() => handleSerialButtonConfigChange("hideSerialSettings", !buttonConfig.hideSerialSettings )}
/>
<Button
size="XS"
theme="primary"
LeadingIcon={LuPlus}
text="Add Button"
onClick={addNew}
/>
<Button
size="XS"
theme="primary"
LeadingIcon={LuTerminal}
text="Open Console"
onClick={() => {
setTerminalType("serial");
console.log("Opening serial console with settings: ", buttonConfig);
}}
/>
</div>
<hr className="border-slate-700/30 dark:border-slate-600/30" />
{/* Serial settings (collapsible) */}
{!buttonConfig.hideSerialSettings && (
<>
<div className="grid grid-cols-2 gap-4">
<SelectMenuBasic
label="Baud Rate"
options={[
{ label: "1200", value: "1200" },
{ label: "2400", value: "2400" },
{ label: "4800", value: "4800" },
{ label: "9600", value: "9600" },
{ label: "19200", value: "19200" },
{ label: "38400", value: "38400" },
{ label: "57600", value: "57600" },
{ label: "115200", value: "115200" },
]}
value={buttonConfig.baudRate}
onChange={(e) => handleSerialButtonConfigChange("baudRate", e.target.value)}
/>
<SelectMenuBasic
label="Data Bits"
options={[
{ label: "8", value: "8" },
{ label: "7", value: "7" },
]}
value={buttonConfig.dataBits}
onChange={(e) => handleSerialButtonConfigChange("dataBits", e.target.value)}
/>
<SelectMenuBasic
label="Stop Bits"
options={[
{ label: "1", value: "1" },
{ label: "1.5", value: "1.5" },
{ label: "2", value: "2" },
]}
value={buttonConfig.stopBits}
onChange={(e) => handleSerialButtonConfigChange("stopBits", e.target.value)}
/>
<SelectMenuBasic
label="Parity"
options={[
{ label: "None", value: "none" },
{ label: "Even", value: "even" },
{ label: "Odd", value: "odd" },
]}
value={buttonConfig.parity}
onChange={(e) => handleSerialButtonConfigChange("parity", e.target.value)}
/>
<div>
<SelectMenuBasic
className="mb-1"
label="Line ending"
options={[
{ label: "None", value: "" },
{ label: "CR (\\r)", value: "\r" },
{ label: "LF (\\n)", value: "\n" },
{ label: "CRLF (\\r\\n)", value: "\r\n" },
{ label: "LFCR (\\n\\r)", value: "\n\r" },
]}
value={buttonConfig.terminator.value}
onChange={(e) => handleSerialButtonConfigChange("terminator", {label: e.target.selectedOptions[0].text, value: e.target.value})}
/>
<div className="text-xs text-white opacity-70 mt-0 ml-2">
When sent, the selected line ending ({buttonConfig.terminator.label}) will be appended.
</div>
</div>
<div>
<SelectMenuBasic
className="mb-1"
label="Terminal Mode"
options={[
{ label: "Raw Mode", value: "raw" },
{ label: "Line Mode", value: "line" },
]}
value={buttonConfig.lineMode ? "line" : "raw"}
onChange={(e) => {
handleSerialButtonConfigChange("lineMode", e.target.value === "line")
setTerminalLineMode(e.target.value === "line");
}}
/>
<div className="text-xs text-white opacity-70 mt-0 ml-2">
{buttonConfig.lineMode
? "In Line Mode, input is sent when you press Enter in the input field."
: "In Raw Mode, input is sent immediately as you type in the console."}
</div>
</div>
</div>
<div className="space-y-4 m-2">
<SettingsItem
title="Local Echo"
description="Whether to echo received characters back to the sender"
>
<Checkbox
checked={buttonConfig.enableEcho}
onChange={e => {
handleSerialButtonConfigChange("enableEcho", e.target.checked);
}}
/>
</SettingsItem>
</div>
<hr className="border-slate-700/30 dark:border-slate-600/30" />
</>
)}
{/* Buttons grid */}
<div className="grid grid-cols-2 gap-2 pt-2">
{sortedButtons.map((btn) => (
<div key={btn.id} className="flex items-stretch gap-2 min-w-0">
<div className=" flex-1 min-w-0 ">
<Button
size="MD"
fullWidth
className="overflow-hidden text-ellipsis whitespace-nowrap"
theme="primary"
text={btn.label}
onClick={() => onClickButton(btn)}
/>
</div>
<Button
size="MD"
theme="light"
className="shrink-0"
LeadingIcon={LuPencil}
onClick={() => editBtn(btn)}
aria-label={`Edit ${btn.label}`}
/>
</div>
))}
{sortedButtons.length === 0 && (
<div className="col-span-2 text-sm text-black dark:text-slate-300">No buttons yet. Click Add Button.</div>
)}
</div>
{/* Editor drawer/modal (inline lightweight) */}
{editorOpen && (
<div className="mt-4 border rounded-md p-3 bg-slate-50 dark:bg-slate-900/30">
<div className="flex items-center gap-2 mb-2">
<LuSettings2 className="h-3.5 text-white shrink-0 justify-start" />
<div className="font-medium text-black dark:text-white">{editorOpen.id ? "Edit Button" : "New Button"}</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3 h-23">
<div>
<InputFieldWithLabel
size="SM"
type="text"
label="Label"
placeholder="New Command"
value={draftLabel}
onChange={e => {
setDraftLabel(e.target.value);
}}
/>
</div>
<div>
<InputFieldWithLabel
size="SM"
type="text"
label="Command"
placeholder="Command to send"
value={draftCmd}
onChange={e => {
setDraftCmd(e.target.value);
}}
/>
{draftTerminator.value != "" && (
<div className="text-xs text-white opacity-70 mt-1">
When sent, the selected line ending ({draftTerminator.label}) will be appended.
</div>
)}
</div>
</div>
<div className="flex justify-around items-end">
<SelectMenuBasic
label="Line ending"
options={[
{ label: "None", value: "" },
{ label: "CR (\\r)", value: "\r" },
{ label: "LF (\\n)", value: "\n" },
{ label: "CRLF (\\r\\n)", value: "\r\n" },
{ label: "LFCR (\\n\\r)", value: "\n\r" },
]}
value={draftTerminator.value}
onChange={(e) => setDraftTerminator({label: e.target.selectedOptions[0].text, value: e.target.value})}
/>
<div className="pb-[3px]">
<Button size="SM" theme="primary" LeadingIcon={LuSave} text="Save" onClick={saveDraft} />
</div>
<div className="pb-[3px]">
<Button size="SM" theme="primary" LeadingIcon={LuCircleX} text="Cancel" onClick={() => setEditorOpen(null)} />
</div>
</div>
<div className="flex justify-around mt-3">
{editorOpen.id && (
<>
<Button
size="SM"
theme="danger"
LeadingIcon={LuTrash2}
text="Delete"
onClick={() => removeBtn(editorOpen.id!)}
aria-label={`Delete ${draftLabel}`}
/>
<Button
size="SM"
theme="primary"
LeadingIcon={LuArrowBigUp}
text="Move Up"
aria-label={`Move ${draftLabel} up`}
disabled={sortedButtons.findIndex(b => b.id === editorOpen.id) === 0}
onClick={() => moveUpBtn(editorOpen.id!)}
/>
<Button
size="SM"
theme="primary"
LeadingIcon={LuArrowBigDown}
text="Move Down"
aria-label={`Move ${draftLabel} down`}
disabled={sortedButtons.findIndex(b => b.id === editorOpen.id)+1 === sortedButtons.length}
onClick={() => moveDownBtn(editorOpen.id!)}
/>
</>
)}
</div>
</div>
)}
</div>
</Card>
</div>
);
}
/** ============== helpers ============== */
function genId() {
return "b_" + Math.random().toString(36).slice(2, 10);
}
function stableSort(arr: QuickButton[]) {
return [...arr].sort((a, b) => (a.sort - b.sort) || a.label.localeCompare(b.label));
}

View File

@ -7,6 +7,7 @@ import { SettingsPageHeader } from "@components/SettingsPageheader";
import { ATXPowerControl } from "@components/extensions/ATXPowerControl";
import { DCPowerControl } from "@components/extensions/DCPowerControl";
import { SerialConsole } from "@components/extensions/SerialConsole";
import { SerialButtons } from "@components/extensions/SerialButtons";
import { Button } from "@components/Button";
import notifications from "@/notifications";
@ -36,6 +37,12 @@ const AVAILABLE_EXTENSIONS: Extension[] = [
description: "Access your serial console extension",
icon: LuTerminal,
},
{
id: "serial-buttons",
name: "Serial Buttons",
description: "Send custom serial signals by buttons",
icon: LuTerminal,
},
];
export default function ExtensionPopover() {
@ -76,6 +83,8 @@ export default function ExtensionPopover() {
return <DCPowerControl />;
case "serial-console":
return <SerialConsole />;
case "serial-buttons":
return <SerialButtons />;
default:
return null;
}

View File

@ -69,6 +69,9 @@ export interface UIState {
terminalType: AvailableTerminalTypes;
setTerminalType: (type: UIState["terminalType"]) => void;
terminalLineMode: boolean;
setTerminalLineMode: (enabled: boolean) => void;
}
export const useUiStore = create<UIState>(set => ({
@ -96,6 +99,9 @@ export const useUiStore = create<UIState>(set => ({
isAttachedVirtualKeyboardVisible: true,
setAttachedVirtualKeyboardVisibility: (enabled: boolean) =>
set({ isAttachedVirtualKeyboardVisible: enabled }),
terminalLineMode: true,
setTerminalLineMode: (enabled: boolean) => set({ terminalLineMode: enabled }),
}));
export interface RTCState {
@ -465,7 +471,7 @@ export interface KeysDownState {
keys: number[];
}
export type USBStates =
export type USBStates =
| "configured"
| "attached"
| "not attached"

View File

@ -153,13 +153,13 @@ body {
@property --grid-color-start {
syntax: "<color>";
initial-value: var(--color-blue-50/10);
initial-value: oklch(97% 0.014 254.604 / 10); /* var(--color-blue-50/10) */
inherits: false;
}
@property --grid-color-end {
syntax: "<color>";
initial-value: var(--color-blue-50/100);
initial-value: oklch(97% 0.014 254.604 / 100); /* var(--color-blue-50/100) */
inherits: false;
}
@ -175,8 +175,8 @@ body {
}
.group:hover .grid-card {
--grid-color-start: var(--color-blue-100/50);
--grid-color-end: var(--color-blue-50/50);
--grid-color-start: oklch(from var(--color-blue-100) l c h / 50);
--grid-color-end: oklch(from var(--color-blue-50) l c h / 50);
}
video::-webkit-media-controls {