desktop/src/App.tsx

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-03-18 13:46:46 +08:00
import { createEffect, createSignal } from "solid-js";
import { invoke } from "@tauri-apps/api/tauri";
import "./App.css";
2023-03-18 16:41:15 +08:00
import { DisplayInfo } from './models/display-info.model';
import { DisplayInfoPanel } from './components/display-info-panel';
2023-03-18 13:46:46 +08:00
function App() {
const [screenshots, setScreenshots] = createSignal<string[]>([]);
const [displays, setDisplays] = createSignal<DisplayInfo[]>([]);
createEffect(() => {
2023-03-18 16:41:15 +08:00
invoke<string>('list_display_info').then((displays) => {
2023-03-18 13:46:46 +08:00
setDisplays(JSON.parse(displays));
});
});
createEffect(() => {
take_all_display_screenshot();
}, [displays]);
async function take_all_display_screenshot() {
2023-03-18 16:41:15 +08:00
console.log('take_all_display_screenshot');
2023-03-18 13:46:46 +08:00
displays().forEach((display) => {
2023-03-18 16:41:15 +08:00
invoke<string>('take_screenshot', {
displayId: display.id,
scaleFactor: display.scale_factor,
}).then((image) => {
2023-03-18 13:46:46 +08:00
setScreenshots((screenshots) => [...screenshots, image]);
});
});
}
return (
<div class="container">
<ol>
2023-03-18 16:41:15 +08:00
{displays().map((display) => {
return (
<li>
<DisplayInfoPanel display={display} />
</li>
);
})}
2023-03-18 13:46:46 +08:00
</ol>
<ol>
2023-03-18 16:41:15 +08:00
{screenshots().map((screenshot) => {
return (
<li>
<img
style="object-fit: contain; height: 400px; width: 600px"
src={screenshot}
/>
</li>
);
})}
2023-03-18 13:46:46 +08:00
</ol>
</div>
);
}
export default App;