Add exportFileBinary to FlipperLib
Reviewed By: antonk52 Differential Revision: D39692937 fbshipit-source-id: 7b3c78d004a9734cd8ae660d5782be1f02c00009
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f3b7552338
commit
3314c77ce9
@@ -151,6 +151,18 @@ export async function initializeElectron(
|
||||
await fs.promises.writeFile(filePath, data, {encoding});
|
||||
return filePath;
|
||||
},
|
||||
async exportFileBinary(data, {defaultPath} = {}) {
|
||||
const {filePath} = await electronIpcClient.send('showSaveDialog', {
|
||||
defaultPath,
|
||||
});
|
||||
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
await fs.promises.writeFile(filePath, data, {encoding: 'binary'});
|
||||
return filePath;
|
||||
},
|
||||
openLink(url: string) {
|
||||
shell.openExternal(url);
|
||||
},
|
||||
|
||||
@@ -126,6 +126,7 @@ export interface RenderHost {
|
||||
showSelectDirectoryDialog?(defaultPath?: string): Promise<string | undefined>;
|
||||
importFile: FlipperLib['importFile'];
|
||||
exportFile: FlipperLib['exportFile'];
|
||||
exportFileBinary: FlipperLib['exportFileBinary'];
|
||||
hasFocus(): boolean;
|
||||
onIpcEvent<Event extends keyof MainProcessEvents>(
|
||||
event: Event,
|
||||
|
||||
@@ -36,6 +36,7 @@ export function baseFlipperLibImplementation(
|
||||
openLink: renderHost.openLink,
|
||||
importFile: renderHost.importFile,
|
||||
exportFile: renderHost.exportFile,
|
||||
exportFileBinary: renderHost.exportFileBinary,
|
||||
paths: {
|
||||
appPath: renderHost.serverConfig.paths.appPath,
|
||||
homePath: renderHost.serverConfig.paths.homePath,
|
||||
|
||||
@@ -172,6 +172,25 @@ export interface FlipperLib {
|
||||
encoding?: FileEncoding;
|
||||
},
|
||||
): Promise<string | undefined>;
|
||||
/**
|
||||
* @returns
|
||||
* An exported file path (if available) or a file name.
|
||||
* If user cancelled a file selection - undefined.
|
||||
*/
|
||||
exportFileBinary(
|
||||
/**
|
||||
* New file data
|
||||
*/
|
||||
data: Uint8Array,
|
||||
options?: {
|
||||
/**
|
||||
* A file path suggestion for a new file.
|
||||
* A dialog to save file will use it as a starting point.
|
||||
* Either a complete path to the newly created file, a path to a directory containing the file, or the file name.
|
||||
*/
|
||||
defaultPath?: string;
|
||||
},
|
||||
): Promise<string | undefined>;
|
||||
paths: {
|
||||
appPath: string;
|
||||
homePath: string;
|
||||
|
||||
@@ -60,6 +60,7 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
||||
openLink: createStubFunction(),
|
||||
showNotification: createStubFunction(),
|
||||
exportFile: createStubFunction(),
|
||||
exportFileBinary: createStubFunction(),
|
||||
importFile: createStubFunction(),
|
||||
paths: {
|
||||
appPath: process.cwd(),
|
||||
|
||||
@@ -28,6 +28,9 @@ export function initializeRenderHost(
|
||||
async exportFile() {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
async exportFileBinary() {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
openLink(url: string) {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
|
||||
@@ -48,6 +48,9 @@ export function initializeRenderHost(
|
||||
async exportFile() {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
async exportFileBinary() {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
openLink(url: string) {
|
||||
window.open(url, '_blank');
|
||||
},
|
||||
|
||||
@@ -170,6 +170,9 @@ function createStubRenderHost(): RenderHost {
|
||||
async exportFile() {
|
||||
return undefined;
|
||||
},
|
||||
async exportFileBinary() {
|
||||
return undefined;
|
||||
},
|
||||
hasFocus() {
|
||||
return true;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user