mirror of
https://github.com/sipeed/NanoKVM-USB.git
synced 2026-09-11 05:59:57 -05:00
Revert "feat: add mouse jiggler function"
This reverts commit cd0b52cc2a.
This commit is contained in:
@@ -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 = () => {
|
||||
<Mode />
|
||||
<Direction />
|
||||
<Speed />
|
||||
<Jiggler />
|
||||
</>
|
||||
);
|
||||
|
||||
|
||||
@@ -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) => (
|
||||
<div
|
||||
key={mode.value}
|
||||
className={clsx(
|
||||
'my-1 flex cursor-pointer items-center space-x-1 rounded py-1 pl-2 pr-5 hover:bg-neutral-700/50',
|
||||
mode.value === mouseJigglerMode ? 'text-blue-500' : 'text-neutral-300'
|
||||
)}
|
||||
onClick={() => update(mode.value)}
|
||||
>
|
||||
{mode.name}
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<Popover content={content} placement="rightTop" arrow={false} align={{ offset: [13, 0] }}>
|
||||
<div className="flex h-[30px] cursor-pointer items-center space-x-1 rounded px-3 text-neutral-300 hover:bg-neutral-700/50">
|
||||
<div className="flex h-[14px] w-[20px] items-end">
|
||||
<MousePointerIcon size={16} />
|
||||
</div>
|
||||
<span>{t('mouse.jiggler.title')}</span>
|
||||
</div>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
@@ -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<Key>(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) {
|
||||
|
||||
@@ -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<Key>(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' ? <Relative /> : <Absolute />}</>;
|
||||
};
|
||||
|
||||
@@ -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<Key>(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);
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -67,12 +67,7 @@ const zh = {
|
||||
speed: '滚轮速度',
|
||||
fast: '快',
|
||||
slow: '慢',
|
||||
requestPointer: '正在使用鼠标相对模式,请点击桌面获取鼠标指针。',
|
||||
jiggler: {
|
||||
title: '闲时晃动',
|
||||
enable: '启用',
|
||||
disable: '禁用'
|
||||
}
|
||||
requestPointer: '正在使用鼠标相对模式,请点击桌面获取鼠标指针。'
|
||||
},
|
||||
settings: {
|
||||
language: '语言',
|
||||
|
||||
@@ -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<number | null>(null);
|
||||
|
||||
// mouse jiggler interval (unit: ms)
|
||||
export const mouseJigglerIntervalAtom = atom(15_000);
|
||||
|
||||
// mouse jiggler last move time
|
||||
export const mouseLastMoveTimeAtom = atom(0);
|
||||
|
||||
@@ -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 [];
|
||||
|
||||
Reference in New Issue
Block a user