diff --git a/browser/src/components/menu/mouse/index.tsx b/browser/src/components/menu/mouse/index.tsx index d5ba87a..4c0bbf4 100644 --- a/browser/src/components/menu/mouse/index.tsx +++ b/browser/src/components/menu/mouse/index.tsx @@ -4,7 +4,6 @@ import { useAtom, useSetAtom } from 'jotai'; import { MouseIcon } from 'lucide-react'; import { - mouseJigglerModeAtom, mouseModeAtom, mouseStyleAtom, scrollDirectionAtom, @@ -13,7 +12,6 @@ import { import * as storage from '@/libs/storage'; import { Direction } from './direction.tsx'; -import { Jiggler } from './jiggler.tsx'; import { Mode } from './mode.tsx'; import { Speed } from './speed.tsx'; import { Style } from './style.tsx'; @@ -23,7 +21,6 @@ export const Mouse = () => { const [mouseMode, setMouseMode] = useAtom(mouseModeAtom); const setScrollDirection = useSetAtom(scrollDirectionAtom); const setScrollInterval = useSetAtom(scrollIntervalAtom); - const [mouseJigglerMode, setMouseJigglerMode] = useAtom(mouseJigglerModeAtom); const [isPopoverOpen, setIsPopoverOpen] = useState(false); @@ -51,11 +48,6 @@ export const Mouse = () => { if (interval) { setScrollInterval(interval); } - - const jiggler = storage.getMouseJigglerMode(); - if (mouseJigglerMode !== jiggler) { - setMouseJigglerMode(jiggler); - } } const content = ( @@ -64,7 +56,6 @@ export const Mouse = () => { - ); diff --git a/browser/src/components/menu/mouse/jiggler.tsx b/browser/src/components/menu/mouse/jiggler.tsx deleted file mode 100644 index b3c74f5..0000000 --- a/browser/src/components/menu/mouse/jiggler.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Popover } from 'antd'; -import clsx from 'clsx'; -import { useAtom } from 'jotai'; -import { MousePointerIcon } from 'lucide-react'; -import { useTranslation } from 'react-i18next'; - -import { mouseJigglerModeAtom } from '@/jotai/mouse.ts'; -import * as storage from '@/libs/storage'; - -export const Jiggler = () => { - const { t } = useTranslation(); - const [mouseJigglerMode, setMouseJigglerMode] = useAtom(mouseJigglerModeAtom); - const mouseJigglerModes = [ - { name: t('mouse.jiggler.enable'), value: 'enable' }, - { name: t('mouse.jiggler.disable'), value: 'disable' } - ]; - - function update(mode: string) { - setMouseJigglerMode(mode); - storage.setMouseJigglerMode(mode); - } - - const content = ( - <> - {mouseJigglerModes.map((mode) => ( -
update(mode.value)} - > - {mode.name} -
- ))} - - ); - return ( - -
-
- -
- {t('mouse.jiggler.title')} -
-
- ); -}; diff --git a/browser/src/components/mouse/absolute.tsx b/browser/src/components/mouse/absolute.tsx index 1adb1f5..9fa14de 100644 --- a/browser/src/components/mouse/absolute.tsx +++ b/browser/src/components/mouse/absolute.tsx @@ -1,13 +1,8 @@ import { useEffect, useRef } from 'react'; -import { useAtomValue, useSetAtom } from 'jotai'; +import { useAtomValue } from 'jotai'; import { resolutionAtom } from '@/jotai/device.ts'; -import { - mouseJigglerModeAtom, - mouseLastMoveTimeAtom, - scrollDirectionAtom, - scrollIntervalAtom -} from '@/jotai/mouse.ts'; +import { scrollDirectionAtom, scrollIntervalAtom } from '@/jotai/mouse.ts'; import { device } from '@/libs/device'; import { Key } from '@/libs/device/mouse.ts'; @@ -15,8 +10,6 @@ export const Absolute = () => { const resolution = useAtomValue(resolutionAtom); const scrollDirection = useAtomValue(scrollDirectionAtom); const scrollInterval = useAtomValue(scrollIntervalAtom); - const mouseJigglerMode = useAtomValue(mouseJigglerModeAtom); - const setMouseLastMoveTime = useSetAtom(mouseLastMoveTimeAtom); const keyRef = useRef(new Key()); const lastScrollTimeRef = useRef(0); @@ -81,11 +74,6 @@ export const Absolute = () => { async function handleMouseMove(event: any) { disableEvent(event); await send(event); - - // mouse jiggler record last move time - if (mouseJigglerMode === 'enable') { - setMouseLastMoveTime(Date.now()); - } } // mouse scroll @@ -157,7 +145,7 @@ export const Absolute = () => { canvas.removeEventListener('click', disableEvent); canvas.removeEventListener('contextmenu', disableEvent); }; - }, [resolution, scrollDirection, scrollInterval, mouseJigglerMode, setMouseLastMoveTime]); + }, [resolution, scrollDirection, scrollInterval]); // disable default events function disableEvent(event: any) { diff --git a/browser/src/components/mouse/index.tsx b/browser/src/components/mouse/index.tsx index 32e558a..ddbd4ae 100644 --- a/browser/src/components/mouse/index.tsx +++ b/browser/src/components/mouse/index.tsx @@ -1,15 +1,6 @@ -import { useEffect, useRef } from 'react'; -import { useAtom, useAtomValue } from 'jotai'; +import { useAtomValue } from 'jotai'; -import { - mouseJigglerIntervalAtom, - mouseJigglerModeAtom, - mouseJigglerTimerAtom, - mouseLastMoveTimeAtom, - mouseModeAtom -} from '@/jotai/mouse.ts'; -import { device } from '@/libs/device/index.ts'; -import { Key } from '@/libs/device/mouse.ts'; +import { mouseModeAtom } from '@/jotai/mouse.ts'; import { Absolute } from './absolute.tsx'; import { Relative } from './relative.tsx'; @@ -17,48 +8,5 @@ import { Relative } from './relative.tsx'; export const Mouse = () => { const mouseMode = useAtomValue(mouseModeAtom); - // mouse jiggler - const mouseJigglerMode = useAtomValue(mouseJigglerModeAtom); - const [mouseJigglerTimer, setMouseJigglerTimer] = useAtom(mouseJigglerTimerAtom); - const mouseJigglerInterval = useAtomValue(mouseJigglerIntervalAtom); - const mouseLastMoveTime = useAtomValue(mouseLastMoveTimeAtom); - const mouseLastMoveTimeRef = useRef(mouseLastMoveTime); - const emptyKeyRef = useRef(new Key()); - useEffect(() => { - // sync mouseLastMoveTime through ref - mouseLastMoveTimeRef.current = mouseLastMoveTime; - }, [mouseLastMoveTime]); - useEffect(() => { - async function jigglerTimerCallback() { - if (Date.now() - mouseLastMoveTimeRef.current < mouseJigglerInterval) { - return; - } - - const rect = document.getElementById('video')!.getBoundingClientRect(); - - await device.sendMouseAbsoluteData( - emptyKeyRef.current, - rect.width, - rect.height, - rect.width / 2, - rect.height / 2, - 0 - ); - } - - // configure interval timer - if (mouseJigglerMode === 'enable') { - if (mouseJigglerTimer === null) { - const timer = setInterval(jigglerTimerCallback, mouseJigglerInterval); - setMouseJigglerTimer(timer); - } - } else { - if (mouseJigglerTimer) { - clearInterval(mouseJigglerTimer); - setMouseJigglerTimer(null); - } - } - }, [mouseJigglerMode]); - return <>{mouseMode === 'relative' ? : }; }; diff --git a/browser/src/components/mouse/relative.tsx b/browser/src/components/mouse/relative.tsx index 22bf8d6..0caecba 100644 --- a/browser/src/components/mouse/relative.tsx +++ b/browser/src/components/mouse/relative.tsx @@ -1,15 +1,10 @@ import { useEffect, useRef } from 'react'; import { message } from 'antd'; -import { useAtomValue, useSetAtom } from 'jotai'; +import { useAtomValue } from 'jotai'; import { useTranslation } from 'react-i18next'; import { resolutionAtom } from '@/jotai/device.ts'; -import { - mouseJigglerModeAtom, - mouseLastMoveTimeAtom, - scrollDirectionAtom, - scrollIntervalAtom -} from '@/jotai/mouse.ts'; +import { scrollDirectionAtom, scrollIntervalAtom } from '@/jotai/mouse.ts'; import { device } from '@/libs/device'; import { Key } from '@/libs/device/mouse.ts'; @@ -20,8 +15,6 @@ export const Relative = () => { const resolution = useAtomValue(resolutionAtom); const scrollDirection = useAtomValue(scrollDirectionAtom); const scrollInterval = useAtomValue(scrollIntervalAtom); - const mouseJigglerMode = useAtomValue(mouseJigglerModeAtom); - const setMouseLastMoveTime = useSetAtom(mouseLastMoveTimeAtom); const isLockedRef = useRef(false); const keyRef = useRef(new Key()); @@ -117,11 +110,6 @@ export const Relative = () => { if (x === 0 && y === 0) return; await send(Math.abs(x) < 10 ? x * 2 : x, Math.abs(y) < 10 ? y * 2 : y, 0); - - // mouse jiggler record last move time - if (mouseJigglerMode === 'enable') { - setMouseLastMoveTime(Date.now()); - } } // mouse scroll @@ -150,7 +138,7 @@ export const Relative = () => { canvas.removeEventListener('wheel', handleWheel); canvas.removeEventListener('contextmenu', disableEvent); }; - }, [resolution, scrollDirection, scrollInterval, mouseJigglerMode, setMouseLastMoveTime]); + }, [resolution, scrollDirection, scrollInterval]); async function send(x: number, y: number, scroll: number) { await device.sendMouseRelativeData(keyRef.current, x, y, scroll); diff --git a/browser/src/i18n/locales/en.ts b/browser/src/i18n/locales/en.ts index 153a9e6..64041f2 100644 --- a/browser/src/i18n/locales/en.ts +++ b/browser/src/i18n/locales/en.ts @@ -69,12 +69,7 @@ const en = { speed: 'Wheel speed', fast: 'Fast', slow: 'Slow', - requestPointer: 'Using relative mode. Please click desktop to get mouse pointer.', - jiggler: { - title: 'Mouse Jiggler', - enable: 'Enable', - disable: 'Disable' - } + requestPointer: 'Using relative mode. Please click desktop to get mouse pointer.' }, settings: { language: 'Language', diff --git a/browser/src/i18n/locales/zh.ts b/browser/src/i18n/locales/zh.ts index 5245371..00f0b5f 100644 --- a/browser/src/i18n/locales/zh.ts +++ b/browser/src/i18n/locales/zh.ts @@ -67,12 +67,7 @@ const zh = { speed: '滚轮速度', fast: '快', slow: '慢', - requestPointer: '正在使用鼠标相对模式,请点击桌面获取鼠标指针。', - jiggler: { - title: '闲时晃动', - enable: '启用', - disable: '禁用' - } + requestPointer: '正在使用鼠标相对模式,请点击桌面获取鼠标指针。' }, settings: { language: '语言', diff --git a/browser/src/jotai/mouse.ts b/browser/src/jotai/mouse.ts index 162484a..7678c93 100644 --- a/browser/src/jotai/mouse.ts +++ b/browser/src/jotai/mouse.ts @@ -9,17 +9,6 @@ export const mouseModeAtom = atom('absolute'); // mouse scroll direction: 1 or -1 export const scrollDirectionAtom = atom(1); +// mouse scroll interval (unit: ms) // mouse scroll interval (unit: ms) export const scrollIntervalAtom = atom(0); - -// mouse jiggler mode: enable or disable -export const mouseJigglerModeAtom = atom('disable'); - -// mouse jiggler timer id -export const mouseJigglerTimerAtom = atom(null); - -// mouse jiggler interval (unit: ms) -export const mouseJigglerIntervalAtom = atom(15_000); - -// mouse jiggler last move time -export const mouseLastMoveTimeAtom = atom(0); diff --git a/browser/src/libs/storage/index.ts b/browser/src/libs/storage/index.ts index 53749b1..0b58087 100644 --- a/browser/src/libs/storage/index.ts +++ b/browser/src/libs/storage/index.ts @@ -11,7 +11,6 @@ const MOUSE_STYLE_KEY = 'nanokvm-usb-mouse-style'; const MOUSE_MODE_KEY = 'nanokvm-usb-mouse-mode'; const MOUSE_SCROLL_DIRECTION_KEY = 'nanokvm-usb-mouse-scroll-direction'; const MOUSE_SCROLL_INTERVAL_KEY = 'nanokvm-usb-mouse-scroll-interval'; -const MOUSE_JIGGLER_MODE_KEY = 'nanokvm-usb-mouse-jiggler-mode'; const SHORTCUTS_KEY = 'nanokvm-usb-shortcuts'; export function getLanguage() { @@ -124,15 +123,6 @@ export function setMouseScrollInterval(interval: number): void { localStorage.setItem(MOUSE_SCROLL_INTERVAL_KEY, String(interval)); } -export function getMouseJigglerMode(): string { - const jiggler = localStorage.getItem(MOUSE_JIGGLER_MODE_KEY); - return jiggler && jiggler === 'enable' ? 'enable' : 'disable'; -} - -export function setMouseJigglerMode(jiggler: string): void { - localStorage.setItem(MOUSE_JIGGLER_MODE_KEY, jiggler); -} - export function getShortcuts(): ShortcutProps[] { const shortcuts = localStorage.getItem(SHORTCUTS_KEY); if (!shortcuts) return [];