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
|
||||
routine to determine the save path; this usually prompts a save dialog.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md): use the `savePath` property instead.**
|
||||
|
||||
#### `downloadItem.getSavePath()`
|
||||
|
||||
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
|
||||
save dialog.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md): use the `savePath` property instead.**
|
||||
|
||||
#### `downloadItem.setSaveDialogOptions(options)`
|
||||
|
||||
* `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.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
#### `image.isTemplateImage()`
|
||||
|
||||
Returns `Boolean` - Whether the image is a template image.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
#### `image.crop(rect)`
|
||||
|
||||
* `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.
|
||||
|
||||
**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_
|
||||
|
||||
|
@ -369,8 +369,6 @@ Returns `String` - Can be `dark`, `light` or `unknown`.
|
|||
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)
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
### `systemPreferences.getAppLevelAppearance()` _macOS_ _Deprecated_
|
||||
|
||||
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).
|
||||
You can use the `setAppLevelAppearance` API to set this value.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_ _Deprecated_
|
||||
|
||||
* `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
|
||||
system default and override the value of `getEffectiveAppearance`.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
### `systemPreferences.canPromptTouchID()` _macOS_
|
||||
|
||||
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)
|
||||
EventEmitter.call(systemPreferences)
|
||||
|
||||
if ('appLevelAppearance' in systemPreferences) {
|
||||
deprecate.fnToProperty(
|
||||
SystemPreferences.prototype,
|
||||
'appLevelAppearance',
|
||||
'_getAppLevelAppearance',
|
||||
'_setAppLevelAppearance'
|
||||
)
|
||||
if ('getAppLevelAppearance' in systemPreferences) {
|
||||
const nativeALAGetter = systemPreferences.getAppLevelAppearance
|
||||
const nativeALASetter = systemPreferences.setAppLevelAppearance
|
||||
Object.defineProperty(SystemPreferences.prototype, 'appLevelAppearance', {
|
||||
get: () => nativeALAGetter.call(systemPreferences),
|
||||
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
|
||||
})
|
||||
}
|
||||
|
||||
if ('effectiveAppearance' in systemPreferences) {
|
||||
deprecate.fnToProperty(
|
||||
SystemPreferences.prototype,
|
||||
'effectiveAppearance',
|
||||
'_getEffectiveAppearance'
|
||||
)
|
||||
if ('getEffectiveAppearance' in systemPreferences) {
|
||||
const nativeEAGetter = systemPreferences.getAppLevelAppearance
|
||||
Object.defineProperty(SystemPreferences.prototype, 'effectiveAppearance', {
|
||||
get: () => nativeEAGetter.call(systemPreferences)
|
||||
})
|
||||
}
|
||||
|
||||
SystemPreferences.prototype.isDarkMode = deprecate.moveAPI(
|
||||
|
|
|
@ -5,7 +5,7 @@ const { EventEmitter } = require('events')
|
|||
const electron = require('electron')
|
||||
const path = require('path')
|
||||
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 NavigationController = require('@electron/internal/browser/navigation-controller')
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
const { deprecate } = require('electron')
|
||||
const { NativeImage, nativeImage } = process.electronBinding('native_image')
|
||||
|
||||
deprecate.fnToProperty(NativeImage.prototype, 'isMacTemplateImage', '_isTemplateImage', '_setTemplateImage')
|
||||
const { nativeImage } = process.electronBinding('native_image')
|
||||
|
||||
module.exports = nativeImage
|
||||
|
|
|
@ -99,17 +99,12 @@ void SystemPreferences::BuildPrototype(
|
|||
.SetMethod("removeUserDefault", &SystemPreferences::RemoveUserDefault)
|
||||
.SetMethod("isSwipeTrackingFromScrollEventsEnabled",
|
||||
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
||||
.SetMethod("_getEffectiveAppearance",
|
||||
.SetMethod("getEffectiveAppearance",
|
||||
&SystemPreferences::GetEffectiveAppearance)
|
||||
.SetMethod("_getAppLevelAppearance",
|
||||
.SetMethod("getAppLevelAppearance",
|
||||
&SystemPreferences::GetAppLevelAppearance)
|
||||
.SetMethod("_setAppLevelAppearance",
|
||||
.SetMethod("setAppLevelAppearance",
|
||||
&SystemPreferences::SetAppLevelAppearance)
|
||||
.SetProperty("appLevelAppearance",
|
||||
&SystemPreferences::GetAppLevelAppearance,
|
||||
&SystemPreferences::SetAppLevelAppearance)
|
||||
.SetProperty("effectiveAppearance",
|
||||
&SystemPreferences::GetEffectiveAppearance)
|
||||
.SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
|
||||
.SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
|
||||
.SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)
|
||||
|
|
|
@ -510,8 +510,8 @@ void NativeImage::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("toDataURL", &NativeImage::ToDataURL)
|
||||
.SetMethod("isEmpty", &NativeImage::IsEmpty)
|
||||
.SetMethod("getSize", &NativeImage::GetSize)
|
||||
.SetMethod("_setTemplateImage", &NativeImage::SetTemplateImage)
|
||||
.SetMethod("_isTemplateImage", &NativeImage::IsTemplateImage)
|
||||
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
|
||||
.SetMethod("isTemplateImage", &NativeImage::IsTemplateImage)
|
||||
.SetProperty("isMacTemplateImage", &NativeImage::IsTemplateImage,
|
||||
&NativeImage::SetTemplateImage)
|
||||
.SetMethod("resize", &NativeImage::Resize)
|
||||
|
|
|
@ -187,12 +187,47 @@ describe('systemPreferences module', () => {
|
|||
})
|
||||
|
||||
ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => {
|
||||
it('has an appLevelAppearance property', () => {
|
||||
expect(systemPreferences).to.have.property('appLevelAppearance')
|
||||
const options = ['dark', 'light', 'unknown', null]
|
||||
describe('with properties', () => {
|
||||
it('returns a valid appearance', () => {
|
||||
const appearance = systemPreferences.appLevelAppearance
|
||||
expect(options).to.include(appearance)
|
||||
})
|
||||
|
||||
// TODO(codebytere): remove when propertyification is complete
|
||||
expect(systemPreferences.setAppLevelAppearance).to.be.a('function')
|
||||
expect(() => { systemPreferences.getAppLevelAppearance() }).to.not.throw()
|
||||
it('can be changed', () => {
|
||||
systemPreferences.appLevelAppearance = 'dark'
|
||||
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 { nativeImage } = require('electron')
|
||||
const { ifdescribe, ifit } = require('./spec-helpers')
|
||||
const path = require('path')
|
||||
|
||||
describe('nativeImage module', () => {
|
||||
|
@ -101,31 +102,41 @@ describe('nativeImage module', () => {
|
|||
return matchingImage
|
||||
}
|
||||
|
||||
describe('isMacTemplateImage property', () => {
|
||||
before(function () {
|
||||
if (process.platform !== 'darwin') this.skip()
|
||||
ifdescribe(process.platform === 'darwin')('isMacTemplateImage state', () => {
|
||||
describe('with properties', () => {
|
||||
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', () => {
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||
describe('with functions', () => {
|
||||
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')
|
||||
expect(image.setTemplateImage).to.be.a('function')
|
||||
})
|
||||
it('sets a template image', function () {
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||
expect(image.isTemplateImage()).to.be.false()
|
||||
|
||||
it('correctly recognizes a template image', () => {
|
||||
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()
|
||||
image.setTemplateImage(true)
|
||||
expect(image.isTemplateImage()).to.be.true()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue