refactor: split clipboard module implementation for browser / renderer (#38429)
This commit is contained in:
parent
a20896f519
commit
470b1d9e9d
7 changed files with 29 additions and 33 deletions
|
@ -196,6 +196,7 @@ auto_filenames = {
|
|||
"lib/browser/api/base-window.ts",
|
||||
"lib/browser/api/browser-view.ts",
|
||||
"lib/browser/api/browser-window.ts",
|
||||
"lib/browser/api/clipboard.ts",
|
||||
"lib/browser/api/content-tracing.ts",
|
||||
"lib/browser/api/crash-reporter.ts",
|
||||
"lib/browser/api/desktop-capturer.ts",
|
||||
|
@ -245,7 +246,6 @@ auto_filenames = {
|
|||
"lib/browser/parse-features-string.ts",
|
||||
"lib/browser/rpc-server.ts",
|
||||
"lib/browser/web-view-events.ts",
|
||||
"lib/common/api/clipboard.ts",
|
||||
"lib/common/api/module-list.ts",
|
||||
"lib/common/api/native-image.ts",
|
||||
"lib/common/api/shell.ts",
|
||||
|
@ -256,8 +256,6 @@ auto_filenames = {
|
|||
"lib/common/reset-search-paths.ts",
|
||||
"lib/common/web-view-methods.ts",
|
||||
"lib/common/webpack-globals-provider.ts",
|
||||
"lib/renderer/ipc-renderer-internal-utils.ts",
|
||||
"lib/renderer/ipc-renderer-internal.ts",
|
||||
"package.json",
|
||||
"tsconfig.electron.json",
|
||||
"tsconfig.json",
|
||||
|
@ -266,7 +264,6 @@ auto_filenames = {
|
|||
]
|
||||
|
||||
renderer_bundle_deps = [
|
||||
"lib/common/api/clipboard.ts",
|
||||
"lib/common/api/module-list.ts",
|
||||
"lib/common/api/native-image.ts",
|
||||
"lib/common/api/shell.ts",
|
||||
|
@ -276,6 +273,7 @@ auto_filenames = {
|
|||
"lib/common/reset-search-paths.ts",
|
||||
"lib/common/web-view-methods.ts",
|
||||
"lib/common/webpack-provider.ts",
|
||||
"lib/renderer/api/clipboard.ts",
|
||||
"lib/renderer/api/context-bridge.ts",
|
||||
"lib/renderer/api/crash-reporter.ts",
|
||||
"lib/renderer/api/exports/electron.ts",
|
||||
|
@ -304,7 +302,6 @@ auto_filenames = {
|
|||
]
|
||||
|
||||
worker_bundle_deps = [
|
||||
"lib/common/api/clipboard.ts",
|
||||
"lib/common/api/module-list.ts",
|
||||
"lib/common/api/native-image.ts",
|
||||
"lib/common/api/shell.ts",
|
||||
|
@ -313,6 +310,7 @@ auto_filenames = {
|
|||
"lib/common/ipc-messages.ts",
|
||||
"lib/common/reset-search-paths.ts",
|
||||
"lib/common/webpack-provider.ts",
|
||||
"lib/renderer/api/clipboard.ts",
|
||||
"lib/renderer/api/context-bridge.ts",
|
||||
"lib/renderer/api/crash-reporter.ts",
|
||||
"lib/renderer/api/exports/electron.ts",
|
||||
|
|
3
lib/browser/api/clipboard.ts
Normal file
3
lib/browser/api/clipboard.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
const clipboard = process._linkedBinding('electron_common_clipboard');
|
||||
|
||||
export default clipboard;
|
|
@ -7,6 +7,7 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [
|
|||
{ name: 'BaseWindow', loader: () => require('./base-window') },
|
||||
{ name: 'BrowserView', loader: () => require('./browser-view') },
|
||||
{ name: 'BrowserWindow', loader: () => require('./browser-window') },
|
||||
{ name: 'clipboard', loader: () => require('./clipboard') },
|
||||
{ name: 'contentTracing', loader: () => require('./content-tracing') },
|
||||
{ name: 'crashReporter', loader: () => require('./crash-reporter') },
|
||||
{ name: 'desktopCapturer', loader: () => require('./desktop-capturer') },
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
||||
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import type * as ipcRendererUtilsModule from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
||||
|
||||
const clipboard = process._linkedBinding('electron_common_clipboard');
|
||||
|
||||
if (process.type === 'renderer') {
|
||||
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils') as typeof ipcRendererUtilsModule;
|
||||
|
||||
const makeRemoteMethod = function (method: keyof Electron.Clipboard): any {
|
||||
return (...args: any[]) => ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_CLIPBOARD_SYNC, method, ...args);
|
||||
};
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
// On Linux we could not access clipboard in renderer process.
|
||||
for (const method of Object.keys(clipboard) as (keyof Electron.Clipboard)[]) {
|
||||
clipboard[method] = makeRemoteMethod(method);
|
||||
}
|
||||
} else if (process.platform === 'darwin') {
|
||||
// Read/write to find pasteboard over IPC since only main process is notified of changes
|
||||
clipboard.readFindText = makeRemoteMethod('readFindText');
|
||||
clipboard.writeFindText = makeRemoteMethod('writeFindText');
|
||||
}
|
||||
}
|
||||
|
||||
export default clipboard;
|
|
@ -1,6 +1,5 @@
|
|||
// Common modules, please sort alphabetically
|
||||
export const commonModuleList: ElectronInternal.ModuleEntry[] = [
|
||||
{ name: 'clipboard', loader: () => require('./clipboard') },
|
||||
{ name: 'nativeImage', loader: () => require('./native-image') },
|
||||
{ name: 'shell', loader: () => require('./shell') }
|
||||
];
|
||||
|
|
21
lib/renderer/api/clipboard.ts
Normal file
21
lib/renderer/api/clipboard.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
||||
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
||||
|
||||
const clipboard = process._linkedBinding('electron_common_clipboard');
|
||||
|
||||
const makeRemoteMethod = function (method: keyof Electron.Clipboard): any {
|
||||
return (...args: any[]) => ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_CLIPBOARD_SYNC, method, ...args);
|
||||
};
|
||||
|
||||
if (process.platform === 'linux') {
|
||||
// On Linux we could not access clipboard in renderer process.
|
||||
for (const method of Object.keys(clipboard) as (keyof Electron.Clipboard)[]) {
|
||||
clipboard[method] = makeRemoteMethod(method);
|
||||
}
|
||||
} else if (process.platform === 'darwin') {
|
||||
// Read/write to find pasteboard over IPC since only main process is notified of changes
|
||||
clipboard.readFindText = makeRemoteMethod('readFindText');
|
||||
clipboard.writeFindText = makeRemoteMethod('writeFindText');
|
||||
}
|
||||
|
||||
export default clipboard;
|
|
@ -1,5 +1,6 @@
|
|||
// Renderer side modules, please sort alphabetically.
|
||||
export const rendererModuleList: ElectronInternal.ModuleEntry[] = [
|
||||
{ name: 'clipboard', loader: () => require('./clipboard') },
|
||||
{ name: 'contextBridge', loader: () => require('./context-bridge') },
|
||||
{ name: 'crashReporter', loader: () => require('./crash-reporter') },
|
||||
{ name: 'ipcRenderer', loader: () => require('./ipc-renderer') },
|
||||
|
|
Loading…
Add table
Reference in a new issue