clipboard.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. if (process.platform === 'linux' && process.type === 'renderer') {
  3. // On Linux we could not access clipboard in renderer process.
  4. const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
  5. module.exports = getRemoteForUsage('clipboard').clipboard
  6. } else {
  7. const clipboard = process.atomBinding('clipboard')
  8. // Read/write to find pasteboard over IPC since only main process is notified
  9. // of changes
  10. if (process.platform === 'darwin' && process.type === 'renderer') {
  11. const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
  12. const errorUtils = require('@electron/internal/common/error-utils')
  13. const invoke = function (command, ...args) {
  14. const [ error, result ] = ipcRenderer.sendSync(command, ...args)
  15. if (error) {
  16. throw errorUtils.deserialize(error)
  17. } else {
  18. return result
  19. }
  20. }
  21. clipboard.readFindText = (...args) => invoke('ELECTRON_BROWSER_CLIPBOARD_READ_FIND_TEXT', ...args)
  22. clipboard.writeFindText = (...args) => invoke('ELECTRON_BROWSER_CLIPBOARD_WRITE_FIND_TEXT', ...args)
  23. }
  24. module.exports = clipboard
  25. }