Bits & pieces
Summary: Added a command to let a file be opened by the OS, and some other small bits and pieces to make Flipper browser compatible. Reviewed By: lblasa Differential Revision: D32721748 fbshipit-source-id: a4ad1c2f662f4651ddf6c20c57e5af1e123914a8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f5f9608098
commit
eab4f0d3d3
@@ -36,6 +36,7 @@ import {saveLauncherSettings} from './utils/launcherSettings';
|
||||
import {KeytarManager} from './utils/keytar';
|
||||
import {PluginManager} from './plugins/PluginManager';
|
||||
import {runHealthcheck, getHealthChecks} from './utils/runHealthchecks';
|
||||
import {openFile} from './utils/openFile';
|
||||
|
||||
/**
|
||||
* FlipperServer takes care of all incoming device & client connections.
|
||||
@@ -272,6 +273,7 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
'plugin-source': (path) => this.pluginManager.loadSource(path),
|
||||
'doctor-get-healthchecks': getHealthChecks,
|
||||
'doctor-run-healthcheck': runHealthcheck,
|
||||
'open-file': openFile,
|
||||
};
|
||||
|
||||
registerDevice(device: ServerDevice) {
|
||||
|
||||
32
desktop/flipper-server-core/src/utils/openFile.tsx
Normal file
32
desktop/flipper-server-core/src/utils/openFile.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import open from 'open';
|
||||
|
||||
export async function openFile(path: string | null) {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fileStat;
|
||||
try {
|
||||
fileStat = await fs.stat(path);
|
||||
} catch (err) {
|
||||
throw new Error(`Couldn't open file: ${path}: ${err}`);
|
||||
}
|
||||
|
||||
// Rather randomly chosen. Some FSs still reserve 8 bytes for empty files.
|
||||
// If this doesn't reliably catch "corrupt" files, you might want to increase this.
|
||||
if (fileStat.size <= 8) {
|
||||
throw new Error('File seems to be (almost) empty: ' + path);
|
||||
}
|
||||
|
||||
await open(path);
|
||||
}
|
||||
Reference in New Issue
Block a user