master
howard 2021-04-23 00:01:07 -07:00
parent 34ba6424dd
commit 4e68e61b67
2 changed files with 54 additions and 12 deletions

View File

@ -26,6 +26,7 @@ export default async (
throwIfExistingHandleNotGood = false
) => {
options.fileName = options.fileName || 'Untitled';
console.log(options.fileName,"ddddddddddd")
const accept = {};
if (options.mimeTypes) {
options.mimeTypes.push(blob.type);

View File

@ -1,14 +1,14 @@
// import {
// fileOpen,
// fileSave,
// } from '../../extlib/fs/index';
import {
fileOpen,
fileSave,
} from 'browser-fs-access';
} from '../../extlib/fs/index';
// import {
// fileOpen,
// fileSave,
// } from 'browser-fs-access';
// https://web.dev/file-system-access/
@ -46,14 +46,56 @@ export async function saveFile(fileHandle, file, dispatch) {
}
};
export async function saveFileAs(file, dispatch) {
// export async function saveFileAs(file, dispatch) {
// try {
// console.log('heeeeeeeeeeeeeer')
// const fileHandle = await fileSave(new Blob([file], { type: 'application/json' }), {
// fileName: 'unamed',
// extensions: ['.json'],
// })
// dispatch({ type: 'set-file-handle', fileHandle, modified: false })
// } catch (ex) {
// const msg = 'Unable to save file.';
// console.error(msg, ex);
// alert(msg);
// return;
// }
// };
export async function saveFileAs(file, dispatch) {
let fileHandle;
try {
const opts = {
suggestedName: 'test',
types: [{
description: 'Text file',
accept: { 'application/json': ['.json'] },
}],
};
fileHandle = await showSaveFilePicker(opts)
} catch (ex) {
if (ex.name === 'AbortError') {
console.log('aborted')
return;
}
const msg = 'An error occured trying to open the file.';
console.error(msg, ex);
alert(msg);
return;
}
try {
const fileHandle = await fileSave(new Blob([file], { type: 'application/json' }), {
// fileName: 'unamed.json',
extensions: ['.json'],
})
const writable = await fileHandle.createWritable();
await writable.write(file);
await writable.close()
dispatch({ type: 'set-file-handle', fileHandle, modified: false })
@ -67,7 +109,6 @@ export async function saveFileAs(file, dispatch) {
};
export async function openFile(dispatch) {
let file