From 9b9f5d15a15fab747b492eaaa29273655ba5ee88 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 15 Jul 2021 01:51:58 -0700 Subject: [PATCH] Avoid using electron directly for writing to clipboard Summary: Similarly to previous stack, remove the need to import Electron to write things to clipboard. Introduced linter to prevent future use. Reviewed By: timur-valiev Differential Revision: D29661777 fbshipit-source-id: 7bc67ede40b65c5f232b69128f3a423e232ddc1b --- desktop/.eslintrc.js | 5 +++++ desktop/app/src/ui/components/table/ManagedTable.tsx | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/desktop/.eslintrc.js b/desktop/.eslintrc.js index 284cd6d59..d8c2a175f 100644 --- a/desktop/.eslintrc.js +++ b/desktop/.eslintrc.js @@ -86,6 +86,11 @@ module.exports = { message: "Direct imports from 'flipper' are deprecated. Import from 'flipper-plugin' instead, which can be tested and distributed stand-alone. See https://fbflipper.com/docs/extending/sandy-migration for more details.", }, + { + name: 'electron', + message: + "Direct imports from 'electron' are deprecated. Most functions can be found in getFlipperLib() from flipper-plugin package instead.", + }, ], // additional rules for this project diff --git a/desktop/app/src/ui/components/table/ManagedTable.tsx b/desktop/app/src/ui/components/table/ManagedTable.tsx index 3727f4209..641c59614 100644 --- a/desktop/app/src/ui/components/table/ManagedTable.tsx +++ b/desktop/app/src/ui/components/table/ManagedTable.tsx @@ -22,7 +22,7 @@ import React from 'react'; import styled from '@emotion/styled'; import AutoSizer from 'react-virtualized-auto-sizer'; import {VariableSizeList as List} from 'react-window'; -import {clipboard, MenuItemConstructorOptions} from 'electron'; +import {MenuItemConstructorOptions} from 'electron'; import TableHead from './TableHead'; import TableRow from './TableRow'; import ContextMenu from '../ContextMenu'; @@ -33,6 +33,7 @@ import {debounce} from 'lodash'; import {DEFAULT_ROW_HEIGHT} from './types'; import textContent from '../../../utils/textContent'; import {notNull} from '../../../utils/typeUtils'; +import {getFlipperLib} from 'flipper-plugin'; const EMPTY_OBJECT = {}; Object.freeze(EMPTY_OBJECT); @@ -319,7 +320,7 @@ export class ManagedTable extends React.Component< }; onCopy = (withHeader: boolean) => { - clipboard.writeText( + getFlipperLib().writeTextToClipboard( [ ...(withHeader ? [this.getHeaderText()] : []), this.getSelectedText(), @@ -520,7 +521,7 @@ export class ManagedTable extends React.Component< onCopyCell = (rowId: string, index: number) => { const cellText = this.getTextContentOfRow(rowId)[index]; - clipboard.writeText(cellText); + getFlipperLib().writeTextToClipboard(cellText); }; buildContextMenuItems: () => Array = () => {