fix: nativeImage.createThumbnailFromPath and shell.openExternal in renderer (#41875)

* fix: nativeImage.createThumbnailFromPath in renderer

* also fix shell.openExternal
This commit is contained in:
Jeremy Rose 2024-04-19 06:43:01 -07:00 committed by GitHub
parent c4aeb17245
commit ed9fec7da4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 34 deletions

View file

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { nativeImage } from 'electron/common';
import { ifdescribe, ifit } from './lib/spec-helpers';
import { ifdescribe, ifit, itremote, useRemoteContext } from './lib/spec-helpers';
import * as path from 'node:path';
describe('nativeImage module', () => {
@ -426,6 +426,8 @@ describe('nativeImage module', () => {
});
ifdescribe(process.platform !== 'linux')('createThumbnailFromPath(path, size)', () => {
useRemoteContext({ webPreferences: { contextIsolation: false, nodeIntegration: true } });
it('throws when invalid size is passed', async () => {
const badSize = { width: -1, height: -1 };
@ -473,6 +475,13 @@ describe('nativeImage module', () => {
const result = await nativeImage.createThumbnailFromPath(imgPath, maxSize);
expect(result.getSize()).to.deep.equal(maxSize);
});
itremote('works in the renderer', async (path: string) => {
const { nativeImage } = require('electron');
const goodSize = { width: 100, height: 100 };
const result = await nativeImage.createThumbnailFromPath(path, goodSize);
expect(result.isEmpty()).to.equal(false);
}, [path.join(fixturesPath, 'assets', 'logo.png')]);
});
describe('addRepresentation()', () => {