clipboard.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. const clipboard = process.electronBinding('clipboard')
  3. if (process.type === 'renderer') {
  4. const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils')
  5. const typeUtils = require('@electron/internal/common/type-utils')
  6. const makeRemoteMethod = function (method) {
  7. return (...args) => {
  8. args = typeUtils.serialize(args)
  9. const result = ipcRendererUtils.invokeSync('ELECTRON_BROWSER_CLIPBOARD', method, ...args)
  10. return typeUtils.deserialize(result)
  11. }
  12. }
  13. if (process.platform === 'linux') {
  14. // On Linux we could not access clipboard in renderer process.
  15. for (const method of Object.keys(clipboard)) {
  16. clipboard[method] = makeRemoteMethod(method)
  17. }
  18. } else if (process.platform === 'darwin') {
  19. // Read/write to find pasteboard over IPC since only main process is notified of changes
  20. clipboard.readFindText = makeRemoteMethod('readFindText')
  21. clipboard.writeFindText = makeRemoteMethod('writeFindText')
  22. }
  23. }
  24. module.exports = clipboard