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 throwIfExistingHandleNotGood = false
) => { ) => {
options.fileName = options.fileName || 'Untitled'; options.fileName = options.fileName || 'Untitled';
console.log(options.fileName,"ddddddddddd")
const accept = {}; const accept = {};
if (options.mimeTypes) { if (options.mimeTypes) {
options.mimeTypes.push(blob.type); options.mimeTypes.push(blob.type);

View File

@ -1,14 +1,14 @@
// import {
// fileOpen,
// fileSave,
// } from '../../extlib/fs/index';
import { import {
fileOpen, fileOpen,
fileSave, fileSave,
} from 'browser-fs-access'; } from '../../extlib/fs/index';
// import {
// fileOpen,
// fileSave,
// } from 'browser-fs-access';
// https://web.dev/file-system-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 { try {
const fileHandle = await fileSave(new Blob([file], { type: 'application/json' }), { const writable = await fileHandle.createWritable();
// fileName: 'unamed.json', await writable.write(file);
extensions: ['.json'], await writable.close()
})
dispatch({ type: 'set-file-handle', fileHandle, modified: false }) dispatch({ type: 'set-file-handle', fileHandle, modified: false })
@ -67,7 +109,6 @@ export async function saveFileAs(file, dispatch) {
}; };
export async function openFile(dispatch) { export async function openFile(dispatch) {
let file let file