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});
|
await fs.promises.writeFile(filePath, data, {encoding});
|
||||||
return filePath;
|
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) {
|
openLink(url: string) {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export interface RenderHost {
|
|||||||
showSelectDirectoryDialog?(defaultPath?: string): Promise<string | undefined>;
|
showSelectDirectoryDialog?(defaultPath?: string): Promise<string | undefined>;
|
||||||
importFile: FlipperLib['importFile'];
|
importFile: FlipperLib['importFile'];
|
||||||
exportFile: FlipperLib['exportFile'];
|
exportFile: FlipperLib['exportFile'];
|
||||||
|
exportFileBinary: FlipperLib['exportFileBinary'];
|
||||||
hasFocus(): boolean;
|
hasFocus(): boolean;
|
||||||
onIpcEvent<Event extends keyof MainProcessEvents>(
|
onIpcEvent<Event extends keyof MainProcessEvents>(
|
||||||
event: Event,
|
event: Event,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export function baseFlipperLibImplementation(
|
|||||||
openLink: renderHost.openLink,
|
openLink: renderHost.openLink,
|
||||||
importFile: renderHost.importFile,
|
importFile: renderHost.importFile,
|
||||||
exportFile: renderHost.exportFile,
|
exportFile: renderHost.exportFile,
|
||||||
|
exportFileBinary: renderHost.exportFileBinary,
|
||||||
paths: {
|
paths: {
|
||||||
appPath: renderHost.serverConfig.paths.appPath,
|
appPath: renderHost.serverConfig.paths.appPath,
|
||||||
homePath: renderHost.serverConfig.paths.homePath,
|
homePath: renderHost.serverConfig.paths.homePath,
|
||||||
|
|||||||
@@ -172,6 +172,25 @@ export interface FlipperLib {
|
|||||||
encoding?: FileEncoding;
|
encoding?: FileEncoding;
|
||||||
},
|
},
|
||||||
): Promise<string | undefined>;
|
): 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: {
|
paths: {
|
||||||
appPath: string;
|
appPath: string;
|
||||||
homePath: string;
|
homePath: string;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
|||||||
openLink: createStubFunction(),
|
openLink: createStubFunction(),
|
||||||
showNotification: createStubFunction(),
|
showNotification: createStubFunction(),
|
||||||
exportFile: createStubFunction(),
|
exportFile: createStubFunction(),
|
||||||
|
exportFileBinary: createStubFunction(),
|
||||||
importFile: createStubFunction(),
|
importFile: createStubFunction(),
|
||||||
paths: {
|
paths: {
|
||||||
appPath: process.cwd(),
|
appPath: process.cwd(),
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ export function initializeRenderHost(
|
|||||||
async exportFile() {
|
async exportFile() {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
},
|
},
|
||||||
|
async exportFileBinary() {
|
||||||
|
throw new Error('Not implemented');
|
||||||
|
},
|
||||||
openLink(url: string) {
|
openLink(url: string) {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ export function initializeRenderHost(
|
|||||||
async exportFile() {
|
async exportFile() {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
},
|
},
|
||||||
|
async exportFileBinary() {
|
||||||
|
throw new Error('Not implemented');
|
||||||
|
},
|
||||||
openLink(url: string) {
|
openLink(url: string) {
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ function createStubRenderHost(): RenderHost {
|
|||||||
async exportFile() {
|
async exportFile() {
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
|
async exportFileBinary() {
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
hasFocus() {
|
hasFocus() {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user