feat: add nativeImage.createThumbnailFromPath API (#24802)
* initial commit, mac implementation * add documentation * convert createThumbnailFromPath to async function * windows impl protoype * add tests * added test * fix * fix test * clean up * update docs * cleaning up code * fix test * retrigger CI * retrigger CI * refactor from app to native_image * windows build * lint * lint * add smart pointers, fix test * change tests and update docs * fix test, remove nolint * add renderer-main process routing to fix tests * lint * thanks sam * thanks sam
This commit is contained in:
parent
b403e64ef2
commit
beaf60de0a
17 changed files with 221 additions and 8 deletions
|
@ -16,6 +16,7 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [
|
|||
{ name: 'Menu', loader: () => require('./menu') },
|
||||
{ name: 'MenuItem', loader: () => require('./menu-item') },
|
||||
{ name: 'MessageChannelMain', loader: () => require('./message-channel') },
|
||||
{ name: 'nativeImage', loader: () => require('./native-image') },
|
||||
{ name: 'nativeTheme', loader: () => require('./native-theme') },
|
||||
{ name: 'net', loader: () => require('./net') },
|
||||
{ name: 'netLog', loader: () => require('./net-log') },
|
||||
|
|
|
@ -18,6 +18,7 @@ export const browserModuleNames = [
|
|||
'inAppPurchase',
|
||||
'Menu',
|
||||
'MenuItem',
|
||||
'nativeImage',
|
||||
'nativeTheme',
|
||||
'net',
|
||||
'netLog',
|
||||
|
|
|
@ -4,7 +4,6 @@ import * as fs from 'fs';
|
|||
import { Socket } from 'net';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
|
||||
const Module = require('module');
|
||||
|
||||
// We modified the original process.argv to let node.js load the init.js,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { app } from 'electron/main';
|
||||
import type { IpcMainInvokeEvent, WebContents } from 'electron/main';
|
||||
import { clipboard, crashReporter } from 'electron/common';
|
||||
import { clipboard, crashReporter, nativeImage } from 'electron/common';
|
||||
import * as fs from 'fs';
|
||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
||||
|
@ -136,3 +136,7 @@ ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_SET_UPLOAD_TO_SERVER', (event:
|
|||
ipcMainUtils.handleSync('ELECTRON_CRASH_REPORTER_GET_CRASHES_DIRECTORY', () => {
|
||||
return crashReporter.getCrashesDirectory();
|
||||
});
|
||||
|
||||
ipcMainInternal.handle('ELECTRON_NATIVE_IMAGE_CREATE_THUMBNAIL_FROM_PATH', async (_, path: string, size: Electron.Size) => {
|
||||
return typeUtils.serialize(await nativeImage.createThumbnailFromPath(path, size));
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// 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') },
|
||||
// The internal modules, invisible unless you know their names.
|
||||
{ name: 'deprecate', loader: () => require('./deprecate'), private: true }
|
||||
|
|
|
@ -7,6 +7,7 @@ export const rendererModuleList: ElectronInternal.ModuleEntry[] = [
|
|||
{ name: 'contextBridge', loader: () => require('./context-bridge') },
|
||||
{ name: 'crashReporter', loader: () => require('./crash-reporter') },
|
||||
{ name: 'ipcRenderer', loader: () => require('./ipc-renderer') },
|
||||
{ name: 'nativeImage', loader: () => require('./native-image') },
|
||||
{ name: 'webFrame', loader: () => require('./web-frame') }
|
||||
];
|
||||
|
||||
|
|
10
lib/renderer/api/native-image.ts
Normal file
10
lib/renderer/api/native-image.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
|
||||
import { deserialize } from '@electron/internal/common/type-utils';
|
||||
|
||||
const { nativeImage } = process._linkedBinding('electron_common_native_image');
|
||||
|
||||
nativeImage.createThumbnailFromPath = async (path: string, size: Electron.Size) => {
|
||||
return deserialize(await ipcRendererInternal.invoke('ELECTRON_NATIVE_IMAGE_CREATE_THUMBNAIL_FROM_PATH', path, size));
|
||||
};
|
||||
|
||||
export default nativeImage;
|
|
@ -13,7 +13,7 @@ export const moduleList: ElectronInternal.ModuleEntry[] = [
|
|||
},
|
||||
{
|
||||
name: 'nativeImage',
|
||||
loader: () => require('@electron/internal/common/api/native-image')
|
||||
loader: () => require('@electron/internal/renderer/api/native-image')
|
||||
},
|
||||
{
|
||||
name: 'webFrame',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue