8000 refactor: make templateImage a property on nativeImage by codebytere · Pull Request #18124 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: make templateImage a property on nativeImage #18124

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

Merged
merged 5 commits into from
May 7, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions atom/common/api/atom_api_native_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,10 @@ 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)
.SetMethod("crop", &NativeImage::Crop)
.SetMethod("getAspectRatio", &NativeImage::GetAspectRatio)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/modernization/property-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `DownloadItem` class
* `savePath`
* `paused`
* `NativeImage`
* `templateImage`
* `Session` module
* `preloads`
* `SystemPreferences` module
Expand All @@ -58,3 +56,5 @@ The Electron team is currently undergoing an initiative to convert separate gett
* `applicationMenu`
* `badgeCount`
* `name`
* `NativeImage`
* `isMacTemplateImage`
13 changes: 12 additions & 1 deletion docs/api/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ images/
└── icon@3x.png
```


```javascript
const { Tray } = require('electron')
let appIcon = new Tray('/Users/somebody/images/icon.png')
Expand Down Expand Up @@ -276,10 +275,14 @@ Returns [`Size`](structures/size.md)

Marks the image as a template image.

**[Deprecated Soon](modernization/property-updates.md)**

#### `image.isTemplateImage()`

Returns `Boolean` - Whether the image is a template image.

**[Deprecated Soon](modernization/property-updates.md)**

#### `image.crop(rect)`

* `rect` [Rectangle](structures/rectangle.md) - The area of the image to crop.
Expand Down Expand Up @@ -324,3 +327,11 @@ to explicitly add different scale factor representations to an image. This
can be called on empty images.

[buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer

## Properties

### `nativeImage.isMacTemplateImage` _macOS_

A `Boolean` property that determines whether the image is considered a [template image](https://developer.apple.com/documentation/appkit/nsimage/1520017-template).

Please note that this property only has an effect on macOS.
5 changes: 4 additions & 1 deletion lib/common/api/native-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict'

const { nativeImage } = process.electronBinding('native_image')
const { deprecate } = require('electron')
const { NativeImage, nativeImage } = process.electronBinding('native_image')

deprecate.fnToProperty(NativeImage.prototype, 'isMacTemplateImage', '_isTemplateImage', '_setTemplateImage')

module.exports = nativeImage
28 changes: 28 additions & 0 deletions spec/api-native-image-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ describe('nativeImage module', () => {
return matchingImage
}

describe('isMacTemplateImage property', () => {
before(function () {
if (process.platform !== 'darwin') this.skip()
})

it('returns whether the image is a template image', () => {
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))

expect(image.isMacTemplateImage).to.be.a('boolean')

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

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

describe('createEmpty()', () => {
it('returns an empty image', () => {
const empty = nativeImage.createEmpty()
Expand Down
Binary file added spec/fixtures/assets/logo_Template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0