Flipper export file implementation
Summary: ^ Changelog: add export file implementation for browsers Reviewed By: antonk52 Differential Revision: D46840341 fbshipit-source-id: 8a011f2a7c0ce329286cb8813def8f9c0572d133
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f0ccad9bb3
commit
daa3a38ed3
@@ -10,9 +10,11 @@
|
||||
"license": "MIT",
|
||||
"bugs": "https://github.com/facebook/flipper/issues",
|
||||
"dependencies": {
|
||||
"file-saver": "^2.0.5",
|
||||
"reconnecting-websocket": "^4.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/file-saver": "^2.0.5",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"flipper-common": "0.0.0",
|
||||
"flipper-frontend-core": "0.0.0",
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
wrapRequire,
|
||||
} from 'flipper-common';
|
||||
import type {RenderHost} from 'flipper-ui-core';
|
||||
import FileSaver from 'file-saver';
|
||||
|
||||
declare module globalThis {
|
||||
let require: any;
|
||||
@@ -44,11 +45,22 @@ export function initializeRenderHost(
|
||||
async importFile() {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
async exportFile() {
|
||||
throw new Error('Not implemented');
|
||||
async exportFile(data: string, {defaultPath}: {defaultPath?: string}) {
|
||||
const file = new File([data], defaultPath ?? 'unknown', {
|
||||
type: 'text/plain;charset=utf-8',
|
||||
});
|
||||
FileSaver.saveAs(file);
|
||||
return defaultPath;
|
||||
},
|
||||
async exportFileBinary() {
|
||||
throw new Error('Not implemented');
|
||||
async exportFileBinary(
|
||||
data: Uint8Array,
|
||||
{defaultPath}: {defaultPath?: string},
|
||||
) {
|
||||
const file = new File([data], defaultPath ?? 'unknown', {
|
||||
type: 'application/octet-stream',
|
||||
});
|
||||
FileSaver.saveAs(file);
|
||||
return defaultPath;
|
||||
},
|
||||
openLink(url: string) {
|
||||
window.open(url, '_blank');
|
||||
|
||||
Reference in New Issue
Block a user