* initial

Signed-off-by: Jess Frazelle <github@jessfraz.com>

update

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* start of tauri

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* better

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* set the default type

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add comments

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* dialog for save tauri

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* partial tsc fix

* bump kittycad lib

* Update src/lib/exportSave.ts

Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>

* updates;

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* default coords

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
Jess Frazelle
2023-08-02 16:23:17 -07:00
committed by GitHub
parent c80dd44c59
commit cd4672c98d
13 changed files with 430 additions and 31 deletions

44
src/lib/exportSave.ts Normal file
View File

@ -0,0 +1,44 @@
import { isTauri } from './isTauri'
import { deserialize_files } from '../wasm-lib/pkg/wasm_lib'
import { browserSaveFile } from './browserSaveFile'
import { save } from '@tauri-apps/api/dialog'
import { writeBinaryFile } from '@tauri-apps/api/fs'
// Saves files locally from an export call.
export async function exportSave(data: ArrayBuffer) {
// This converts the ArrayBuffer to a Rust equivalent Vec<u8>.
let uintArray = new Uint8Array(data)
try {
const files: { contents: number[]; name: string }[] =
deserialize_files(uintArray)
for (const file of files) {
if (isTauri()) {
// Open a dialog to save the file.
const filePath = await save({
defaultPath: file.name,
})
if (filePath === null) {
// The user canceled the save.
// Return early.
return
}
// Write the file.
await writeBinaryFile(filePath, uintArray)
} else {
// Download the file to the user's computer.
// Now we need to download the files to the user's downloads folder.
// Or the destination they choose.
// Iterate over the files.
// Create a new blob.
const blob = new Blob([new Uint8Array(file.contents)])
// Save the file.
browserSaveFile(blob, file.name)
}
}
} catch (e) {
// TODO: do something real with the error.
console.log(e)
}
}