Backport (3-0-x) - fix: deprecate properties in app.getAppMetrics() (#13453)
* fix: deprecate properties in app.getAppMetrics() * address feedback from review * fix deprecated property location * simplify test
This commit is contained in:
parent
ec993214a2
commit
93edf2edd3
4 changed files with 47 additions and 6 deletions
|
@ -35,9 +35,9 @@ app.releaseSingleInstanceLock()
|
|||
```
|
||||
|
||||
|
||||
# Planned Breaking API Changes (3.0)
|
||||
# Breaking API Changes (3.0)
|
||||
|
||||
The following list includes the breaking API changes planned for Electron 3.0.
|
||||
The following list includes the breaking API changes in Electron 3.0.
|
||||
|
||||
## `app`
|
||||
|
||||
|
@ -46,6 +46,12 @@ The following list includes the breaking API changes planned for Electron 3.0.
|
|||
app.getAppMemoryInfo()
|
||||
// Replace with
|
||||
app.getAppMetrics()
|
||||
|
||||
// Deprecated
|
||||
const metrics = app.getAppMetrics()
|
||||
const {memory} = metrics[0]
|
||||
memory.privateBytes // Deprecated property
|
||||
memory.sharedBytes // Deprecated property
|
||||
```
|
||||
|
||||
## `BrowserWindow`
|
||||
|
@ -124,6 +130,15 @@ nativeImage.createFromBuffer(buffer, {
|
|||
})
|
||||
```
|
||||
|
||||
## `process`
|
||||
|
||||
```js
|
||||
// Deprecated
|
||||
const info = process.getProcessMemoryInfo()
|
||||
const privateBytes = info.privateBytes // deprecated property
|
||||
const sharedBytes = info.sharedBytes // deprecated property
|
||||
```
|
||||
|
||||
## `screen`
|
||||
|
||||
```js
|
||||
|
|
|
@ -58,6 +58,13 @@ Object.assign(app, {
|
|||
}
|
||||
})
|
||||
|
||||
const nativeFn = app.getAppMetrics
|
||||
app.getAppMetrics = () => {
|
||||
deprecate.removeProperty(nativeFn, 'privateBytes')
|
||||
deprecate.removeProperty(nativeFn, 'sharedBytes')
|
||||
return nativeFn.call(app)
|
||||
}
|
||||
|
||||
app.isPackaged = (() => {
|
||||
const execFile = path.basename(process.execPath).toLowerCase()
|
||||
if (process.platform === 'win32') {
|
||||
|
|
|
@ -88,8 +88,14 @@ deprecate.getHandler = () => deprecationHandler
|
|||
// }
|
||||
// }
|
||||
|
||||
// Deprecate the old name of a property
|
||||
deprecate.property = (object, deprecatedName, newName) => {
|
||||
deprecate.removeProperty = (object, deprecatedName) => {
|
||||
if (!process.noDeprecation) {
|
||||
deprecate.log(`The '${deprecatedName}' property has been deprecated.`)
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the old name of a property
|
||||
deprecate.renameProperty = (object, deprecatedName, newName) => {
|
||||
let warned = false
|
||||
let warn = () => {
|
||||
if (!(warned || process.noDeprecation)) {
|
||||
|
|
|
@ -65,7 +65,7 @@ describe('deprecations', () => {
|
|||
expect(o).to.not.have.a.property(oldPropertyName)
|
||||
expect(o).to.have.a.property(newPropertyName).that.is.a('number')
|
||||
|
||||
deprecate.property(o, oldPropertyName, newPropertyName)
|
||||
deprecate.renameProperty(o, oldPropertyName, newPropertyName)
|
||||
o[oldPropertyName] = ++value
|
||||
|
||||
expect(msg).to.be.a('string')
|
||||
|
@ -76,6 +76,19 @@ describe('deprecations', () => {
|
|||
expect(o).to.have.a.property(oldPropertyName).that.is.equal(value)
|
||||
})
|
||||
|
||||
it('deprecates a property of an object', () => {
|
||||
let msg
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
||||
const propertyName = 'itMustGo'
|
||||
const o = { [propertyName]: 0 }
|
||||
|
||||
deprecate.removeProperty(o, propertyName)
|
||||
|
||||
expect(msg).to.be.a('string')
|
||||
expect(msg).to.include(propertyName)
|
||||
})
|
||||
|
||||
it('warns if deprecated property is already set', () => {
|
||||
let msg
|
||||
deprecations.setHandler((m) => { msg = m })
|
||||
|
@ -85,7 +98,7 @@ describe('deprecations', () => {
|
|||
const value = 0
|
||||
|
||||
let o = { [oldPropertyName]: value }
|
||||
deprecate.property(o, oldPropertyName, newPropertyName)
|
||||
deprecate.renameProperty(o, oldPropertyName, newPropertyName)
|
||||
|
||||
expect(msg).to.be.a('string')
|
||||
expect(msg).to.include(oldPropertyName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue