createPaste

Reviewed By: jknoxville

Differential Revision: D14224400

fbshipit-source-id: 9a9a8578de00d276d65a7928964eae619f5bc41f
This commit is contained in:
Daniel Büchele
2019-02-28 07:25:07 -08:00
committed by Facebook Github Bot
parent 6118dee3e7
commit 99ea11b8e6
9 changed files with 18 additions and 57 deletions

View File

@@ -37,7 +37,8 @@ import {
updateCategoryBlacklist,
} from './reducers/notifications';
import {selectPlugin} from './reducers/connections';
import {createPaste, textContent} from './utils/index';
import {textContent} from './utils/index';
import createPaste from './fb-stubs/createPaste';
export default class Notifications extends FlipperDevicePlugin<{}> {
static id = 'notifications';

View File

@@ -297,7 +297,7 @@ class PluginDebugger extends Component<Props> {
<InfoText>
The table lists all plugins known to Flipper. Some of them might be
blocked by GKs, others may not show up, because none of the
connected apps is supporting it.
connected apps are supporting it.
</InfoText>
<TableContainer>
<ManagedTable

View File

@@ -18,7 +18,7 @@ import DetailSidebar from './chrome/DetailSidebar';
import {FlipperPlugin} from './plugin';
import SearchableTable from './ui/components/searchable/SearchableTable';
import textContent from './utils/textContent.js';
import createPaste from './utils/createPaste.js';
import createPaste from './fb-stubs/createPaste.js';
type ID = string;

View File

@@ -0,0 +1,10 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export default function createPaste(input: string): Promise<?string> {
return Promise.reject('Not implemented!');
}

View File

@@ -9,6 +9,7 @@ export {default as styled} from 'react-emotion';
export * from './ui/index.js';
export * from './utils/index.js';
export {default as GK} from './fb-stubs/GK.js';
export {default as createPaste} from './fb-stubs/createPaste.js';
export {
FlipperBasePlugin,
FlipperPlugin,
@@ -17,7 +18,7 @@ export {
export type {PluginClient} from './plugin.js';
export {clipboard} from 'electron';
export * from './fb-stubs/constants.js';
export * from './utils/createPaste.js';
export * from './fb-stubs/createPaste.js';
export {connect} from 'react-redux';
export {selectPlugin} from './reducers/connections';
export {getPluginKey, getPersistedState} from './utils/pluginUtils.js';

View File

@@ -11,7 +11,7 @@ import ContextMenu from '../ContextMenu.js';
import Tooltip from '../Tooltip.js';
import styled from '../../styled/index.js';
import DataPreview from './DataPreview.js';
import createPaste from '../../../utils/createPaste.js';
import createPaste from '../../../fb-stubs/createPaste.js';
import {reportInteraction} from '../../../utils/InteractionTracker.js';
import {getSortedKeys} from './utils.js';
import {colors} from '../colors.js';

View File

@@ -27,7 +27,7 @@ import TableHead from './TableHead.js';
import TableRow from './TableRow.js';
import ContextMenu from '../ContextMenu.js';
import FlexColumn from '../FlexColumn.js';
import createPaste from '../../../utils/createPaste.js';
import createPaste from '../../../fb-stubs/createPaste.js';
import debounceRender from 'react-debounce-render';
import debounce from 'lodash.debounce';
import {DEFAULT_ROW_HEIGHT} from './types';

View File

@@ -1,50 +0,0 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import child_process from 'child_process';
import {clipboard, shell} from 'electron';
import JSONStream from 'JSONStream';
type PasteResponse =
| string
| {
createdPaste: {
id: number,
url: string,
},
};
export default function createPaste(input: string): Promise<?string> {
return new Promise((resolve, reject) => {
const child = child_process.spawn('pastry', ['--json']);
let lastMessage: ?PasteResponse;
child.stdout
.pipe(JSONStream.parse([true]))
.on('data', (data: PasteResponse) => {
if (typeof data === 'string' && lastMessage === 'error') {
new window.Notification('Failed to create paste', {
body: data,
});
reject(data);
} else if (typeof data === 'object' && data.createdPaste) {
const {url, id} = data.createdPaste;
clipboard.writeText(url);
const notification = new window.Notification(`Paste P${id} created`, {
body: 'URL copied to clipboard',
});
notification.onclick = () => shell.openExternal(url);
resolve(url);
}
lastMessage = data;
});
child.stdin.write(input);
child.stdin.end();
});
}

View File

@@ -6,4 +6,3 @@
*/
export {default as textContent} from './textContent.js';
export {default as createPaste} from './createPaste.js';