Files
hoppscotch/packages/hoppscotch-selfhost-desktop/src/platform/io.ts
Andrew Bastin 16044b5840 feat: desktop app
Co-authored-by: Vivek R <123vivekr@gmail.com>
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
2023-11-07 14:20:03 +05:30

25 lines
619 B
TypeScript

import { IOPlatformDef } from "@hoppscotch/common/platform/io"
import { save } from "@tauri-apps/api/dialog"
import { writeBinaryFile, writeTextFile } from "@tauri-apps/api/fs"
export const ioDef: IOPlatformDef = {
async saveFileWithDialog(opts) {
const path = await save({
filters: opts.filters,
defaultPath: opts.suggestedFilename,
})
if (path === null) {
return { type: "cancelled" }
}
if (typeof opts.data === "string") {
await writeTextFile(path, opts.data)
} else {
await writeBinaryFile(path, opts.data)
}
return { type: "saved", path }
},
}