chore: more modules to dual prop/fn support (#22688)
This commit is contained in:
parent
01d5154f4f
commit
674e4a9fdd
10 changed files with 91 additions and 68 deletions
|
@ -82,16 +82,12 @@ The API is only available in session's `will-download` callback function.
|
||||||
If user doesn't set the save path via the API, Electron will use the original
|
If user doesn't set the save path via the API, Electron will use the original
|
||||||
routine to determine the save path; this usually prompts a save dialog.
|
routine to determine the save path; this usually prompts a save dialog.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md): use the `savePath` property instead.**
|
|
||||||
|
|
||||||
#### `downloadItem.getSavePath()`
|
#### `downloadItem.getSavePath()`
|
||||||
|
|
||||||
Returns `String` - The save path of the download item. This will be either the path
|
Returns `String` - The save path of the download item. This will be either the path
|
||||||
set via `downloadItem.setSavePath(path)` or the path selected from the shown
|
set via `downloadItem.setSavePath(path)` or the path selected from the shown
|
||||||
save dialog.
|
save dialog.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md): use the `savePath` property instead.**
|
|
||||||
|
|
||||||
#### `downloadItem.setSaveDialogOptions(options)`
|
#### `downloadItem.setSaveDialogOptions(options)`
|
||||||
|
|
||||||
* `options` SaveDialogOptions - Set the save file dialog options. This object has the same
|
* `options` SaveDialogOptions - Set the save file dialog options. This object has the same
|
||||||
|
|
|
@ -276,14 +276,10 @@ Returns [`Size`](structures/size.md)
|
||||||
|
|
||||||
Marks the image as a template image.
|
Marks the image as a template image.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `image.isTemplateImage()`
|
#### `image.isTemplateImage()`
|
||||||
|
|
||||||
Returns `Boolean` - Whether the image is a template image.
|
Returns `Boolean` - Whether the image is a template image.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
#### `image.crop(rect)`
|
#### `image.crop(rect)`
|
||||||
|
|
||||||
* `rect` [Rectangle](structures/rectangle.md) - The area of the image to crop.
|
* `rect` [Rectangle](structures/rectangle.md) - The area of the image to crop.
|
||||||
|
|
|
@ -360,7 +360,7 @@ Returns `Boolean` - `true` if an inverted color scheme (a high contrast color sc
|
||||||
|
|
||||||
Returns `Boolean` - `true` if a high contrast theme is active, `false` otherwise.
|
Returns `Boolean` - `true` if a high contrast theme is active, `false` otherwise.
|
||||||
|
|
||||||
**Depreacted:** Should use the new [`nativeTheme.shouldUseHighContrastColors`](native-theme.md#nativethemeshouldusehighcontrastcolors-macos-windows-readonly) API.
|
**Deprecated:** Should use the new [`nativeTheme.shouldUseHighContrastColors`](native-theme.md#nativethemeshouldusehighcontrastcolors-macos-windows-readonly) API.
|
||||||
|
|
||||||
### `systemPreferences.getEffectiveAppearance()` _macOS_
|
### `systemPreferences.getEffectiveAppearance()` _macOS_
|
||||||
|
|
||||||
|
@ -369,8 +369,6 @@ Returns `String` - Can be `dark`, `light` or `unknown`.
|
||||||
Gets the macOS appearance setting that is currently applied to your application,
|
Gets the macOS appearance setting that is currently applied to your application,
|
||||||
maps to [NSApplication.effectiveAppearance](https://developer.apple.com/documentation/appkit/nsapplication/2967171-effectiveappearance?language=objc)
|
maps to [NSApplication.effectiveAppearance](https://developer.apple.com/documentation/appkit/nsapplication/2967171-effectiveappearance?language=objc)
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `systemPreferences.getAppLevelAppearance()` _macOS_ _Deprecated_
|
### `systemPreferences.getAppLevelAppearance()` _macOS_ _Deprecated_
|
||||||
|
|
||||||
Returns `String` | `null` - Can be `dark`, `light` or `unknown`.
|
Returns `String` | `null` - Can be `dark`, `light` or `unknown`.
|
||||||
|
@ -379,8 +377,6 @@ Gets the macOS appearance setting that you have declared you want for
|
||||||
your application, maps to [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc).
|
your application, maps to [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc).
|
||||||
You can use the `setAppLevelAppearance` API to set this value.
|
You can use the `setAppLevelAppearance` API to set this value.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_ _Deprecated_
|
### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_ _Deprecated_
|
||||||
|
|
||||||
* `appearance` String | null - Can be `dark` or `light`
|
* `appearance` String | null - Can be `dark` or `light`
|
||||||
|
@ -388,8 +384,6 @@ You can use the `setAppLevelAppearance` API to set this value.
|
||||||
Sets the appearance setting for your application, this should override the
|
Sets the appearance setting for your application, this should override the
|
||||||
system default and override the value of `getEffectiveAppearance`.
|
system default and override the value of `getEffectiveAppearance`.
|
||||||
|
|
||||||
**[Deprecated](modernization/property-updates.md)**
|
|
||||||
|
|
||||||
### `systemPreferences.canPromptTouchID()` _macOS_
|
### `systemPreferences.canPromptTouchID()` _macOS_
|
||||||
|
|
||||||
Returns `Boolean` - whether or not this device has the ability to use Touch ID.
|
Returns `Boolean` - whether or not this device has the ability to use Touch ID.
|
||||||
|
|
|
@ -6,21 +6,20 @@ const { systemPreferences, SystemPreferences } = process.electronBinding('system
|
||||||
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype)
|
||||||
EventEmitter.call(systemPreferences)
|
EventEmitter.call(systemPreferences)
|
||||||
|
|
||||||
if ('appLevelAppearance' in systemPreferences) {
|
if ('getAppLevelAppearance' in systemPreferences) {
|
||||||
deprecate.fnToProperty(
|
const nativeALAGetter = systemPreferences.getAppLevelAppearance
|
||||||
SystemPreferences.prototype,
|
const nativeALASetter = systemPreferences.setAppLevelAppearance
|
||||||
'appLevelAppearance',
|
Object.defineProperty(SystemPreferences.prototype, 'appLevelAppearance', {
|
||||||
'_getAppLevelAppearance',
|
get: () => nativeALAGetter.call(systemPreferences),
|
||||||
'_setAppLevelAppearance'
|
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('effectiveAppearance' in systemPreferences) {
|
if ('getEffectiveAppearance' in systemPreferences) {
|
||||||
deprecate.fnToProperty(
|
const nativeEAGetter = systemPreferences.getAppLevelAppearance
|
||||||
SystemPreferences.prototype,
|
Object.defineProperty(SystemPreferences.prototype, 'effectiveAppearance', {
|
||||||
'effectiveAppearance',
|
get: () => nativeEAGetter.call(systemPreferences)
|
||||||
'_getEffectiveAppearance'
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemPreferences.prototype.isDarkMode = deprecate.moveAPI(
|
SystemPreferences.prototype.isDarkMode = deprecate.moveAPI(
|
||||||
|
|
|
@ -5,7 +5,7 @@ const { EventEmitter } = require('events')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const url = require('url')
|
const url = require('url')
|
||||||
const { app, ipcMain, session, deprecate } = electron
|
const { app, ipcMain, session } = electron
|
||||||
|
|
||||||
const { internalWindowOpen } = require('@electron/internal/browser/guest-window-manager')
|
const { internalWindowOpen } = require('@electron/internal/browser/guest-window-manager')
|
||||||
const NavigationController = require('@electron/internal/browser/navigation-controller')
|
const NavigationController = require('@electron/internal/browser/navigation-controller')
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { deprecate } = require('electron')
|
const { nativeImage } = process.electronBinding('native_image')
|
||||||
const { NativeImage, nativeImage } = process.electronBinding('native_image')
|
|
||||||
|
|
||||||
deprecate.fnToProperty(NativeImage.prototype, 'isMacTemplateImage', '_isTemplateImage', '_setTemplateImage')
|
|
||||||
|
|
||||||
module.exports = nativeImage
|
module.exports = nativeImage
|
||||||
|
|
|
@ -99,17 +99,12 @@ void SystemPreferences::BuildPrototype(
|
||||||
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
||||||
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
||||||
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
||||||
.SetMethod("_getEffectiveAppearance",
|
.SetMethod("getEffectiveAppearance",
|
||||||
&SystemPreferences::GetEffectiveAppearance)
|
&SystemPreferences::GetEffectiveAppearance)
|
||||||
.SetMethod("_getAppLevelAppearance",
|
.SetMethod("getAppLevelAppearance",
|
||||||
&SystemPreferences::GetAppLevelAppearance)
|
&SystemPreferences::GetAppLevelAppearance)
|
||||||
.SetMethod("_setAppLevelAppearance",
|
.SetMethod("setAppLevelAppearance",
|
||||||
&SystemPreferences::SetAppLevelAppearance)
|
&SystemPreferences::SetAppLevelAppearance)
|
||||||
.SetProperty("appLevelAppearance",
|
|
||||||
&SystemPreferences::GetAppLevelAppearance,
|
|
||||||
&SystemPreferences::SetAppLevelAppearance)
|
|
||||||
.SetProperty("effectiveAppearance",
|
|
||||||
&SystemPreferences::GetEffectiveAppearance)
|
|
||||||
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
||||||
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
|
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
|
||||||
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
|
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
|
||||||
|
|
|
@ -510,8 +510,8 @@ void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||||
.SetMethod("getSize", &NativeImage::GetSize)
|
.SetMethod("getSize", &NativeImage::GetSize)
|
||||||
.SetMethod("_setTemplateImage", &NativeImage::SetTemplateImage)
|
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
|
||||||
.SetMethod("_isTemplateImage", &NativeImage::IsTemplateImage)
|
.SetMethod("isTemplateImage", &NativeImage::IsTemplateImage)
|
||||||
.SetProperty("isMacTemplateImage", &NativeImage::IsTemplateImage,
|
.SetProperty("isMacTemplateImage", &NativeImage::IsTemplateImage,
|
||||||
&NativeImage::SetTemplateImage)
|
&NativeImage::SetTemplateImage)
|
||||||
.SetMethod("resize", &NativeImage::Resize)
|
.SetMethod("resize", &NativeImage::Resize)
|
||||||
|
|
|
@ -187,12 +187,47 @@ describe('systemPreferences module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => {
|
ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => {
|
||||||
it('has an appLevelAppearance property', () => {
|
const options = ['dark', 'light', 'unknown', null]
|
||||||
expect(systemPreferences).to.have.property('appLevelAppearance')
|
describe('with properties', () => {
|
||||||
|
it('returns a valid appearance', () => {
|
||||||
|
const appearance = systemPreferences.appLevelAppearance
|
||||||
|
expect(options).to.include(appearance)
|
||||||
|
})
|
||||||
|
|
||||||
// TODO(codebytere): remove when propertyification is complete
|
it('can be changed', () => {
|
||||||
expect(systemPreferences.setAppLevelAppearance).to.be.a('function')
|
systemPreferences.appLevelAppearance = 'dark'
|
||||||
expect(() => { systemPreferences.getAppLevelAppearance() }).to.not.throw()
|
expect(systemPreferences.appLevelAppearance).to.eql('dark')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with functions', () => {
|
||||||
|
it('returns a valid appearance', () => {
|
||||||
|
const appearance = systemPreferences.getAppLevelAppearance()
|
||||||
|
expect(options).to.include(appearance)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can be changed', () => {
|
||||||
|
systemPreferences.setAppLevelAppearance('dark')
|
||||||
|
const appearance = systemPreferences.getAppLevelAppearance()
|
||||||
|
expect(appearance).to.eql('dark')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('systemPreferences.effectiveAppearance', () => {
|
||||||
|
const options = ['dark', 'light', 'unknown']
|
||||||
|
describe('with properties', () => {
|
||||||
|
it('returns a valid appearance', () => {
|
||||||
|
const appearance = systemPreferences.effectiveAppearance
|
||||||
|
expect(options).to.include(appearance)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with functions', () => {
|
||||||
|
it('returns a valid appearance', () => {
|
||||||
|
const appearance = systemPreferences.getEffectiveAppearance()
|
||||||
|
expect(options).to.include(appearance)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
const { nativeImage } = require('electron')
|
const { nativeImage } = require('electron')
|
||||||
|
const { ifdescribe, ifit } = require('./spec-helpers')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
describe('nativeImage module', () => {
|
describe('nativeImage module', () => {
|
||||||
|
@ -101,31 +102,41 @@ describe('nativeImage module', () => {
|
||||||
return matchingImage
|
return matchingImage
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('isMacTemplateImage property', () => {
|
ifdescribe(process.platform === 'darwin')('isMacTemplateImage state', () => {
|
||||||
before(function () {
|
describe('with properties', () => {
|
||||||
if (process.platform !== 'darwin') this.skip()
|
it('correctly recognizes a template image', () => {
|
||||||
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||||
|
expect(image.isMacTemplateImage).to.be.false()
|
||||||
|
|
||||||
|
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'))
|
||||||
|
expect(templateImage.isMacTemplateImage).to.be.true()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets a template image', function () {
|
||||||
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||||
|
expect(image.isMacTemplateImage).to.be.false()
|
||||||
|
|
||||||
|
image.isMacTemplateImage = true
|
||||||
|
expect(image.isMacTemplateImage).to.be.true()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns whether the image is a template image', () => {
|
describe('with functions', () => {
|
||||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
it('correctly recognizes a template image', () => {
|
||||||
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||||
|
expect(image.isTemplateImage()).to.be.false()
|
||||||
|
|
||||||
expect(image.isMacTemplateImage).to.be.a('boolean')
|
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'))
|
||||||
|
expect(templateImage.isTemplateImage()).to.be.true()
|
||||||
|
})
|
||||||
|
|
||||||
expect(image.isTemplateImage).to.be.a('function')
|
it('sets a template image', function () {
|
||||||
expect(image.setTemplateImage).to.be.a('function')
|
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||||
})
|
expect(image.isTemplateImage()).to.be.false()
|
||||||
|
|
||||||
it('correctly recognizes a template image', () => {
|
image.setTemplateImage(true)
|
||||||
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'))
|
expect(image.isTemplateImage()).to.be.true()
|
||||||
expect(templateImage.isMacTemplateImage).to.be.true()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
it('sets a template image', function () {
|
|
||||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
|
||||||
expect(image.isMacTemplateImage).to.be.false()
|
|
||||||
|
|
||||||
image.isMacTemplateImage = true
|
|
||||||
expect(image.isMacTemplateImage).to.be.true()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue