feature/gui-configuration:支持从 GUI 配置程序。 #4

Merged
Ivan merged 19 commits from feature/gui-configuration into master 2023-01-26 23:44:19 +08:00
Showing only changes of commit 56f65fed10 - Show all commits

View File

@ -14,7 +14,6 @@ import { update } from 'ramda';
const getPickerConfig = () => invoke<PickerConfiguration>('get_picker_config');
const getScreenshotOfDisplays = () =>
invoke<ScreenshotDto[]>('take_snapshot').then((items) => {
console.log(items);
return items;
});
const getScreenshotByConfig = async (config: DisplayConfig) => {
@ -41,33 +40,23 @@ export const Configurator: FC = () => {
const { loading: pendingGetLedColorsByConfig, execute: onDisplayConfigChange } =
useAsyncCallback(async (value: DisplayConfig) => {
console.log('onDisplayConfigChange', value);
const screenshot = await getScreenshotByConfig(value);
setScreenshotOfDisplays((old) => {
const index = old.findIndex((it) => it.config.id === screenshot.config.id);
const newValue = update(index, screenshot, old);
console.log({ old, n: newValue });
savedPickerConfig &&
writePickerConfig({
...savedPickerConfig,
display_configs: newValue.map((it) => it.config),
}).then(() => {
console.log('writing config is successful.', {
...savedPickerConfig,
display_configs: newValue.map((it) => it.config),
});
});
return newValue;
});
console.log('screenshot', screenshot);
});
const [displayConfigs, setDisplayConfigs] = useState<DisplayConfig[]>([]);
useEffect(() => {
const displayConfigs = savedPickerConfig?.display_configs;
console.log('displayConfigs change', displayConfigs);
if (displayConfigs && defaultScreenshotOfDisplays) {
setDisplayConfigs(displayConfigs);
setScreenshotOfDisplays(defaultScreenshotOfDisplays);
@ -82,7 +71,6 @@ export const Configurator: FC = () => {
const displays = useMemo(() => {
if (screenshotOfDisplays) {
console.log({ c: screenshotOfDisplays });
return screenshotOfDisplays.map((screenshot, index) => (
<DisplayWithLedStrips
key={index}