-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DriverInstall.svelte help and button to Uploader.svelte (#123)
* feat: add DriverInstall.svelte help and button to Uploader.svelte * chore: fix biome issues * chore: fix translations Co-authored-by: Ronald Moesbergen <[email protected]> * chore: fix translations Co-authored-by: Ronald Moesbergen <[email protected]> * chore: uncomment code that downloads * chore: make everything use the new downloadDrivers system * fix: maybe not close the tab after the download? --------- Co-authored-by: Ronald Moesbergen <[email protected]>
- Loading branch information
1 parent
086ee2f
commit 11716d0
Showing
7 changed files
with
85 additions
and
29 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/lib/components/core/popups/popups/DriverInstall.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script lang="ts"> | ||
import install_drivers from "$assets/install_drivers.mp4"; | ||
import Button from "$components/ui/Button.svelte"; | ||
import { type PopupState, popups } from "$state/popup.svelte"; | ||
import { getContext } from "svelte"; | ||
import { _ } from "svelte-i18n"; | ||
import type { Writable } from "svelte/store"; | ||
const popupState = getContext<Writable<PopupState>>("state"); | ||
function close() { | ||
popups.close($popupState.id); | ||
} | ||
</script> | ||
|
||
<div class="content"> | ||
<h1>{$_("DRIVER_INSTALL_TITLE")}</h1> | ||
<p>{$_("DRIVER_INSTALL_TEXT")}</p> | ||
<video src={install_drivers} controls={true} width={600}></video> | ||
<Button name={$_("CLOSE")} mode={"accent"} onclick={close} bold={true} /> | ||
</div> | ||
|
||
<style> | ||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 800px; | ||
padding: 20px; | ||
gap: 20px; | ||
text-align: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import DriverInstall from "$components/core/popups/popups/DriverInstall.svelte"; | ||
import { popups } from "$state/popup.svelte"; | ||
import JSZip from "jszip"; | ||
|
||
async function downloadDrivers() { | ||
const response = await fetch( | ||
"https://api.github.com/repos/leaphy-robotics/leaphy-firmware/contents/drivers", | ||
); | ||
const data = await response.json(); | ||
const files = data.map(({ download_url }) => download_url); | ||
const zip = new JSZip(); | ||
|
||
await Promise.all( | ||
files.map(async (url) => { | ||
const res = await fetch(url); | ||
zip.file(url.split("/").pop(), await res.blob()); | ||
}), | ||
); | ||
|
||
const a = document.createElement("a"); | ||
const url = URL.createObjectURL(await zip.generateAsync({ type: "blob" })); | ||
a.href = url; | ||
a.download = "leaphy-drivers.zip"; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
await popups.open({ | ||
component: DriverInstall, | ||
data: {}, | ||
allowInteraction: true, | ||
}); | ||
} | ||
|
||
export { downloadDrivers }; |