Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more modules to dual prop/fn support #22734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/api/download-item.md
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions docs/api/native-image.md
Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions docs/api/system-preferences.md
Expand Up @@ -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_

Expand All @@ -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`.
Expand All @@ -379,17 +377,13 @@ 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`

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.
Expand Down
25 changes: 12 additions & 13 deletions lib/browser/api/system-preferences.ts
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions lib/common/api/native-image.js
@@ -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
11 changes: 3 additions & 8 deletions shell/browser/api/electron_api_system_preferences.cc
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions shell/common/api/electron_api_native_image.cc
Expand Up @@ -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)
Expand Down
45 changes: 40 additions & 5 deletions spec-main/api-system-preferences-spec.ts
Expand Up @@ -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)
})

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')
})
})
})

// TODO(codebytere): remove when propertyification is complete
expect(systemPreferences.setAppLevelAppearance).to.be.a('function')
expect(() => { systemPreferences.getAppLevelAppearance() }).to.not.throw()
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)
})
})
})

Expand Down
47 changes: 29 additions & 18 deletions spec/api-native-image-spec.js
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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()

it('returns whether the image is a template image', () => {
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'))
expect(templateImage.isMacTemplateImage).to.be.true()
})

expect(image.isMacTemplateImage).to.be.a('boolean')
it('sets a template image', function () {
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
expect(image.isMacTemplateImage).to.be.false()

expect(image.isTemplateImage).to.be.a('function')
expect(image.setTemplateImage).to.be.a('function')
image.isMacTemplateImage = true
expect(image.isMacTemplateImage).to.be.true()
})
})

it('correctly recognizes a template image', () => {
const templateImage = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo_Template.png'))
expect(templateImage.isMacTemplateImage).to.be.true()
})
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()

it('sets a template image', function () {
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.isTemplateImage()).to.be.true()
})

image.isMacTemplateImage = true
expect(image.isMacTemplateImage).to.be.true()
it('sets a template image', function () {
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
expect(image.isTemplateImage()).to.be.false()

image.setTemplateImage(true)
expect(image.isTemplateImage()).to.be.true()
})
})
})

Expand Down