feat: 灯光跟随屏幕内容。

feat: 灯光跟随屏幕内容。
This commit is contained in:
2022-11-24 23:21:46 +08:00
parent 1b10c6bea9
commit 56edd8ac77
7 changed files with 139 additions and 84 deletions

View File

@ -4,17 +4,12 @@ import { invoke } from '@tauri-apps/api/tauri';
import './App.css';
import clsx from 'clsx';
type Mode = 'Flowing' | 'Follow' | null;
function App() {
const [greetMsg, setGreetMsg] = useState('');
const [name, setName] = useState('');
const [screenshots, setScreenshots] = useState<string[]>([]);
const [ledStripColors, setLedStripColors] = useState<string[]>([]);
const [flowingLightMode, setFlowingLightMode] = useState<boolean>(false);
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
setGreetMsg(await invoke('greet', { name }));
}
const [currentMode, setCurrentMode] = useState<Mode>(null);
async function takeSnapshot() {
const base64TextList: string[] = await invoke('take_snapshot');
@ -30,16 +25,20 @@ function App() {
setLedStripColors(await invoke('get_led_strip_colors'));
}, []);
const switchFlowingLightMode = useCallback(async () => {
console.log('A', flowingLightMode);
if (flowingLightMode) {
await invoke('stop_flowing_light');
} else {
invoke('play_flowing_light');
}
console.log('B', flowingLightMode);
setFlowingLightMode(!flowingLightMode);
}, [flowingLightMode]);
const switchCurrentMode = useCallback(
async (targetMode: Mode) => {
console.log(targetMode, currentMode, currentMode === targetMode);
if (currentMode === targetMode) {
await invoke('play_mode', { targetMode: 'None' });
setCurrentMode(null);
} else {
await invoke('play_mode', { targetMode });
setCurrentMode(targetMode);
}
console.log(targetMode, currentMode, currentMode === targetMode);
},
[currentMode, setCurrentMode],
);
return (
<div>
@ -81,13 +80,22 @@ function App() {
</button>
<button
className={clsx('bg-black', 'bg-opacity-20', {
'bg-gradient-to-r from-purple-500 to-blue-500': flowingLightMode,
'bg-gradient-to-r from-purple-500 to-blue-500': currentMode === 'Flowing',
})}
type="button"
onClick={() => switchFlowingLightMode()}
onClick={() => switchCurrentMode('Flowing')}
>
Flowing Light
</button>
<button
className={clsx('bg-black', 'bg-opacity-20', {
'bg-gradient-to-r from-purple-500 to-blue-500': currentMode === 'Follow',
})}
type="button"
onClick={() => switchCurrentMode('Follow')}
>
Follow
</button>
</div>
<div className="flex gap-5 justify-center">