2020-10-13 23:11:06 +02:00
|
|
|
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
|
|
|
|
2022-09-20 20:25:33 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2021-05-06 03:05:01 +02:00
|
|
|
import type * as ipcRendererUtilsModule from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
|
|
|
|
2020-06-22 20:32:45 -07:00
|
|
|
const clipboard = process._linkedBinding('electron_common_clipboard');
|
2016-10-25 13:43:24 +09:00
|
|
|
|
2019-03-16 01:32:04 +01:00
|
|
|
if (process.type === 'renderer') {
|
2021-05-06 03:05:01 +02:00
|
|
|
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils') as typeof ipcRendererUtilsModule;
|
2018-10-13 19:50:07 +02:00
|
|
|
|
2021-09-07 10:37:45 -07:00
|
|
|
const makeRemoteMethod = function (method: keyof Electron.Clipboard): any {
|
|
|
|
return (...args: any[]) => ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_CLIPBOARD_SYNC, method, ...args);
|
2020-03-20 13:28:31 -07:00
|
|
|
};
|
2016-10-25 13:43:24 +09:00
|
|
|
|
2019-03-16 01:32:04 +01:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
// On Linux we could not access clipboard in renderer process.
|
2020-05-22 12:46:22 -07:00
|
|
|
for (const method of Object.keys(clipboard) as (keyof Electron.Clipboard)[]) {
|
2020-03-20 13:28:31 -07:00
|
|
|
clipboard[method] = makeRemoteMethod(method);
|
2019-03-16 01:32:04 +01:00
|
|
|
}
|
|
|
|
} else if (process.platform === 'darwin') {
|
|
|
|
// Read/write to find pasteboard over IPC since only main process is notified of changes
|
2020-03-20 13:28:31 -07:00
|
|
|
clipboard.readFindText = makeRemoteMethod('readFindText');
|
|
|
|
clipboard.writeFindText = makeRemoteMethod('writeFindText');
|
2019-03-16 01:32:04 +01:00
|
|
|
}
|
2016-01-11 18:40:23 -08:00
|
|
|
}
|
2019-03-16 01:32:04 +01:00
|
|
|
|
2020-05-22 12:46:22 -07:00
|
|
|
export default clipboard;
|