clipboard.ts 953 B

123456789101112131415161718192021
  1. import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
  2. import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
  3. const clipboard = process._linkedBinding('electron_common_clipboard');
  4. const makeRemoteMethod = function (method: keyof Electron.Clipboard): any {
  5. return (...args: any[]) => ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_CLIPBOARD_SYNC, method, ...args);
  6. };
  7. if (process.platform === 'linux') {
  8. // On Linux we could not access clipboard in renderer process.
  9. for (const method of Object.keys(clipboard) as (keyof Electron.Clipboard)[]) {
  10. clipboard[method] = makeRemoteMethod(method);
  11. }
  12. } else if (process.platform === 'darwin') {
  13. // Read/write to find pasteboard over IPC since only main process is notified of changes
  14. clipboard.readFindText = makeRemoteMethod('readFindText');
  15. clipboard.writeFindText = makeRemoteMethod('writeFindText');
  16. }
  17. export default clipboard;