mirror of https://github.com/jetkvm/kvm.git
Compare commits
1 Commits
9973f1f551
...
8ffae489d6
Author | SHA1 | Date |
---|---|---|
|
8ffae489d6 |
|
@ -111,7 +111,7 @@ var defaultConfig = &Config{
|
||||||
ActiveExtension: "",
|
ActiveExtension: "",
|
||||||
KeyboardMacros: []KeyboardMacro{},
|
KeyboardMacros: []KeyboardMacro{},
|
||||||
DisplayRotation: "270",
|
DisplayRotation: "270",
|
||||||
KeyboardLayout: "en_US",
|
KeyboardLayout: "en-US",
|
||||||
DisplayMaxBrightness: 64,
|
DisplayMaxBrightness: 64,
|
||||||
DisplayDimAfterSec: 120, // 2 minutes
|
DisplayDimAfterSec: 120, // 2 minutes
|
||||||
DisplayOffAfterSec: 1800, // 30 minutes
|
DisplayOffAfterSec: 1800, // 30 minutes
|
||||||
|
|
99
native.go
99
native.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -42,11 +41,6 @@ var ongoingRequests = make(map[int32]chan *CtrlResponse)
|
||||||
|
|
||||||
var lock = &sync.Mutex{}
|
var lock = &sync.Mutex{}
|
||||||
|
|
||||||
var (
|
|
||||||
nativeCmd *exec.Cmd
|
|
||||||
nativeCmdLock = &sync.Mutex{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func CallCtrlAction(action string, params map[string]interface{}) (*CtrlResponse, error) {
|
func CallCtrlAction(action string, params map[string]interface{}) (*CtrlResponse, error) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
@ -135,26 +129,16 @@ func StartNativeSocketServer(socketPath string, handleClient func(net.Conn), isC
|
||||||
scopedLogger.Info().Msg("server listening")
|
scopedLogger.Info().Msg("server listening")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
conn, err := listener.Accept()
|
||||||
conn, err := listener.Accept()
|
listener.Close()
|
||||||
|
if err != nil {
|
||||||
if err != nil {
|
scopedLogger.Warn().Err(err).Msg("failed to accept socket")
|
||||||
scopedLogger.Warn().Err(err).Msg("failed to accept socket")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if isCtrl {
|
|
||||||
// check if the channel is closed
|
|
||||||
select {
|
|
||||||
case <-ctrlClientConnected:
|
|
||||||
scopedLogger.Debug().Msg("ctrl client reconnected")
|
|
||||||
default:
|
|
||||||
close(ctrlClientConnected)
|
|
||||||
scopedLogger.Debug().Msg("first native ctrl socket client connected")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
go handleClient(conn)
|
|
||||||
}
|
}
|
||||||
|
if isCtrl {
|
||||||
|
close(ctrlClientConnected)
|
||||||
|
scopedLogger.Debug().Msg("first native ctrl socket client connected")
|
||||||
|
}
|
||||||
|
handleClient(conn)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return listener
|
return listener
|
||||||
|
@ -251,51 +235,6 @@ func handleVideoClient(conn net.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startNativeBinaryWithLock(binaryPath string) (*exec.Cmd, error) {
|
|
||||||
nativeCmdLock.Lock()
|
|
||||||
defer nativeCmdLock.Unlock()
|
|
||||||
|
|
||||||
cmd, err := startNativeBinary(binaryPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
nativeCmd = cmd
|
|
||||||
return cmd, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func restartNativeBinary(binaryPath string) error {
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
// restart the binary
|
|
||||||
nativeLogger.Info().Msg("restarting jetkvm_native binary")
|
|
||||||
cmd, err := startNativeBinary(binaryPath)
|
|
||||||
if err != nil {
|
|
||||||
nativeLogger.Warn().Err(err).Msg("failed to restart binary")
|
|
||||||
}
|
|
||||||
nativeCmd = cmd
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func superviseNativeBinary(binaryPath string) error {
|
|
||||||
nativeCmdLock.Lock()
|
|
||||||
defer nativeCmdLock.Unlock()
|
|
||||||
|
|
||||||
if nativeCmd == nil || nativeCmd.Process == nil {
|
|
||||||
return restartNativeBinary(binaryPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := nativeCmd.Wait()
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
nativeLogger.Info().Err(err).Msg("jetkvm_native binary exited with no error")
|
|
||||||
} else if exiterr, ok := err.(*exec.ExitError); ok {
|
|
||||||
nativeLogger.Warn().Int("exit_code", exiterr.ExitCode()).Msg("jetkvm_native binary exited with error")
|
|
||||||
} else {
|
|
||||||
nativeLogger.Warn().Err(err).Msg("jetkvm_native binary exited with unknown error")
|
|
||||||
}
|
|
||||||
|
|
||||||
return restartNativeBinary(binaryPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExtractAndRunNativeBin() error {
|
func ExtractAndRunNativeBin() error {
|
||||||
binaryPath := "/userdata/jetkvm/bin/jetkvm_native"
|
binaryPath := "/userdata/jetkvm/bin/jetkvm_native"
|
||||||
if err := ensureBinaryUpdated(binaryPath); err != nil {
|
if err := ensureBinaryUpdated(binaryPath); err != nil {
|
||||||
|
@ -307,28 +246,12 @@ func ExtractAndRunNativeBin() error {
|
||||||
return fmt.Errorf("failed to make binary executable: %w", err)
|
return fmt.Errorf("failed to make binary executable: %w", err)
|
||||||
}
|
}
|
||||||
// Run the binary in the background
|
// Run the binary in the background
|
||||||
cmd, err := startNativeBinaryWithLock(binaryPath)
|
cmd, err := startNativeBinary(binaryPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to start binary: %w", err)
|
return fmt.Errorf("failed to start binary: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the binary is still running every 10 seconds
|
//TODO: add auto restart
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-appCtx.Done():
|
|
||||||
nativeLogger.Info().Msg("stopping native binary supervisor")
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
err := superviseNativeBinary(binaryPath)
|
|
||||||
if err != nil {
|
|
||||||
nativeLogger.Warn().Err(err).Msg("failed to supervise native binary")
|
|
||||||
time.Sleep(1 * time.Second) // Add a short delay to prevent rapid successive calls
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-appCtx.Done()
|
<-appCtx.Done()
|
||||||
nativeLogger.Info().Int("pid", cmd.Process.Pid).Msg("killing process")
|
nativeLogger.Info().Int("pid", cmd.Process.Pid).Msg("killing process")
|
||||||
|
|
|
@ -115,18 +115,9 @@ export default function WebRTCVideo() {
|
||||||
const isFullscreenEnabled = document.fullscreenEnabled;
|
const isFullscreenEnabled = document.fullscreenEnabled;
|
||||||
|
|
||||||
const checkNavigatorPermissions = useCallback(async (permissionName: string) => {
|
const checkNavigatorPermissions = useCallback(async (permissionName: string) => {
|
||||||
if (!navigator.permissions || !navigator.permissions.query) {
|
const name = permissionName as PermissionName;
|
||||||
return false; // if can't query permissions, assume NOT granted
|
const { state } = await navigator.permissions.query({ name });
|
||||||
}
|
return state === "granted";
|
||||||
|
|
||||||
try {
|
|
||||||
const name = permissionName as PermissionName;
|
|
||||||
const { state } = await navigator.permissions.query({ name });
|
|
||||||
return state === "granted";
|
|
||||||
} catch {
|
|
||||||
// ignore errors
|
|
||||||
}
|
|
||||||
return false; // if query fails, assume NOT granted
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const requestPointerLock = useCallback(async () => {
|
const requestPointerLock = useCallback(async () => {
|
||||||
|
@ -137,11 +128,7 @@ export default function WebRTCVideo() {
|
||||||
const isPointerLockGranted = await checkNavigatorPermissions("pointer-lock");
|
const isPointerLockGranted = await checkNavigatorPermissions("pointer-lock");
|
||||||
|
|
||||||
if (isPointerLockGranted && settings.mouseMode === "relative") {
|
if (isPointerLockGranted && settings.mouseMode === "relative") {
|
||||||
try {
|
await videoElm.current.requestPointerLock();
|
||||||
await videoElm.current.requestPointerLock();
|
|
||||||
} catch {
|
|
||||||
// ignore errors
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [checkNavigatorPermissions, isPointerLockPossible, settings.mouseMode]);
|
}, [checkNavigatorPermissions, isPointerLockPossible, settings.mouseMode]);
|
||||||
|
|
||||||
|
@ -149,13 +136,10 @@ export default function WebRTCVideo() {
|
||||||
if (videoElm.current === null) return;
|
if (videoElm.current === null) return;
|
||||||
|
|
||||||
const isKeyboardLockGranted = await checkNavigatorPermissions("keyboard-lock");
|
const isKeyboardLockGranted = await checkNavigatorPermissions("keyboard-lock");
|
||||||
|
if (isKeyboardLockGranted) {
|
||||||
if (isKeyboardLockGranted && "keyboard" in navigator) {
|
if ("keyboard" in navigator) {
|
||||||
try {
|
|
||||||
// @ts-expect-error - keyboard lock is not supported in all browsers
|
// @ts-expect-error - keyboard lock is not supported in all browsers
|
||||||
await navigator.keyboard.lock();
|
await navigator.keyboard.lock();
|
||||||
} catch {
|
|
||||||
// ignore errors
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [checkNavigatorPermissions]);
|
}, [checkNavigatorPermissions]);
|
||||||
|
@ -164,12 +148,8 @@ export default function WebRTCVideo() {
|
||||||
if (videoElm.current === null || document.fullscreenElement !== videoElm.current) return;
|
if (videoElm.current === null || document.fullscreenElement !== videoElm.current) return;
|
||||||
|
|
||||||
if ("keyboard" in navigator) {
|
if ("keyboard" in navigator) {
|
||||||
try {
|
// @ts-expect-error - keyboard unlock is not supported in all browsers
|
||||||
// @ts-expect-error - keyboard unlock is not supported in all browsers
|
await navigator.keyboard.unlock();
|
||||||
await navigator.keyboard.unlock();
|
|
||||||
} catch {
|
|
||||||
// ignore errors
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ export default function PasteModal() {
|
||||||
state => state.setKeyboardLayout,
|
state => state.setKeyboardLayout,
|
||||||
);
|
);
|
||||||
|
|
||||||
// this ensures we always get the original en_US if it hasn't been set yet
|
// this ensures we always get the original en-US if it hasn't been set yet
|
||||||
const safeKeyboardLayout = useMemo(() => {
|
const safeKeyboardLayout = useMemo(() => {
|
||||||
if (keyboardLayout && keyboardLayout.length > 0)
|
if (keyboardLayout && keyboardLayout.length > 0)
|
||||||
return keyboardLayout;
|
return keyboardLayout;
|
||||||
return "en_US";
|
return "en-US";
|
||||||
}, [keyboardLayout]);
|
}, [keyboardLayout]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -25,11 +25,11 @@ export default function SettingsKeyboardRoute() {
|
||||||
state => state.setShowPressedKeys,
|
state => state.setShowPressedKeys,
|
||||||
);
|
);
|
||||||
|
|
||||||
// this ensures we always get the original en_US if it hasn't been set yet
|
// this ensures we always get the original en-US if it hasn't been set yet
|
||||||
const safeKeyboardLayout = useMemo(() => {
|
const safeKeyboardLayout = useMemo(() => {
|
||||||
if (keyboardLayout && keyboardLayout.length > 0)
|
if (keyboardLayout && keyboardLayout.length > 0)
|
||||||
return keyboardLayout;
|
return keyboardLayout;
|
||||||
return "en_US";
|
return "en-US";
|
||||||
}, [keyboardLayout]);
|
}, [keyboardLayout]);
|
||||||
|
|
||||||
const layoutOptions = Object.entries(layouts).map(([code, language]) => { return { value: code, label: language } })
|
const layoutOptions = Object.entries(layouts).map(([code, language]) => { return { value: code, label: language } })
|
||||||
|
|
Loading…
Reference in New Issue