2023-03-26 22:39:47 +08:00
|
|
|
import { createEffect, onCleanup } from 'solid-js';
|
|
|
|
import { invoke } from '@tauri-apps/api/tauri';
|
2023-03-20 09:27:47 +08:00
|
|
|
import { DisplayView } from './components/display-view';
|
2023-03-19 11:19:20 +08:00
|
|
|
import { DisplayListContainer } from './components/display-list-container';
|
|
|
|
import { displayStore, setDisplayStore } from './stores/display.store';
|
2023-03-26 10:48:50 +08:00
|
|
|
import { LedStripConfig } from './models/led-strip-config';
|
|
|
|
import { setLedStripStore } from './stores/led-strip.store';
|
2023-03-26 22:39:47 +08:00
|
|
|
import { listen } from '@tauri-apps/api/event';
|
2023-03-18 13:46:46 +08:00
|
|
|
|
|
|
|
function App() {
|
|
|
|
createEffect(() => {
|
2023-03-18 16:41:15 +08:00
|
|
|
invoke<string>('list_display_info').then((displays) => {
|
2023-03-19 11:19:20 +08:00
|
|
|
setDisplayStore({
|
|
|
|
displays: JSON.parse(displays),
|
|
|
|
});
|
2023-03-18 13:46:46 +08:00
|
|
|
});
|
2023-03-26 10:48:50 +08:00
|
|
|
invoke<LedStripConfig[]>('read_led_strip_configs').then((strips) => {
|
2023-03-26 22:39:47 +08:00
|
|
|
setLedStripStore({
|
|
|
|
strips,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-03-26 10:48:50 +08:00
|
|
|
|
2023-03-26 22:39:47 +08:00
|
|
|
// register tauri event listeners
|
|
|
|
createEffect(() => {
|
|
|
|
const unlisten = listen('config_changed', (event) => {
|
|
|
|
const strips = event.payload as LedStripConfig[];
|
2023-03-26 10:48:50 +08:00
|
|
|
setLedStripStore({
|
|
|
|
strips,
|
|
|
|
});
|
|
|
|
});
|
2023-03-26 22:39:47 +08:00
|
|
|
|
|
|
|
onCleanup(() => {
|
|
|
|
unlisten.then((unlisten) => unlisten());
|
|
|
|
});
|
2023-03-18 13:46:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2023-03-21 23:42:02 +08:00
|
|
|
<div>
|
2023-03-19 11:19:20 +08:00
|
|
|
<DisplayListContainer>
|
|
|
|
{displayStore.displays.map((display) => {
|
2023-03-19 10:15:26 +08:00
|
|
|
return <DisplayView display={display} />;
|
2023-03-18 16:41:15 +08:00
|
|
|
})}
|
2023-03-19 11:19:20 +08:00
|
|
|
</DisplayListContainer>
|
2023-03-18 13:46:46 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|