feat: add new nativeTheme API (#19656)
* feat: add new nativeTheme API * chore: deprecate and clean up old systemPreferences theme APIs in favor of new nativeTheme module * chore: clean up and deprecate things per feedback * chore: add tests for deprecate and clean up invert impl * build: when is a boolean not a boolean???
This commit is contained in:
parent
246187a20f
commit
efa1818cb4
16 changed files with 343 additions and 29 deletions
|
@ -51,7 +51,15 @@ const deprecate: ElectronInternal.DeprecationUtil = {
|
|||
const warn = warnOnce(`${fn.name} function`, `${newName} function`)
|
||||
return function (this: any) {
|
||||
warn()
|
||||
fn.apply(this, arguments)
|
||||
return fn.apply(this, arguments)
|
||||
}
|
||||
},
|
||||
|
||||
moveAPI: (fn: Function, oldUsage: string, newUsage: string) => {
|
||||
const warn = warnOnce(oldUsage, newUsage)
|
||||
return function (this: any) {
|
||||
warn()
|
||||
return fn.apply(this, arguments)
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -69,7 +77,7 @@ const deprecate: ElectronInternal.DeprecationUtil = {
|
|||
},
|
||||
|
||||
// deprecate a getter/setter function pair in favor of a property
|
||||
fnToProperty: (prototype: any, prop: string, getter: string, setter: string) => {
|
||||
fnToProperty: (prototype: any, prop: string, getter: string, setter?: string) => {
|
||||
const withWarnOnce = function (obj: any, key: any, oldName: string, newName: string) {
|
||||
const warn = warnOnce(oldName, newName)
|
||||
const method = obj[key]
|
||||
|
@ -80,7 +88,9 @@ const deprecate: ElectronInternal.DeprecationUtil = {
|
|||
}
|
||||
|
||||
prototype[getter.substr(1)] = withWarnOnce(prototype, getter, `${getter.substr(1)} function`, `${prop} property`)
|
||||
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`)
|
||||
if (setter) {
|
||||
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`)
|
||||
}
|
||||
},
|
||||
|
||||
// remove a property with no replacement
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
module.exports = [
|
||||
{ name: 'clipboard', loader: () => require('./clipboard') },
|
||||
{ name: 'nativeImage', loader: () => require('./native-image') },
|
||||
{ name: 'nativeTheme', loader: () => require('./native-theme') },
|
||||
{ name: 'shell', loader: () => require('./shell') },
|
||||
// The internal modules, invisible unless you know their names.
|
||||
{ name: 'deprecate', loader: () => require('./deprecate'), private: true }
|
||||
|
|
8
lib/common/api/native-theme.ts
Normal file
8
lib/common/api/native-theme.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { EventEmitter } from 'events'
|
||||
|
||||
const { NativeTheme, nativeTheme } = process.electronBinding('native_theme')
|
||||
|
||||
Object.setPrototypeOf(NativeTheme.prototype, EventEmitter.prototype)
|
||||
EventEmitter.call(nativeTheme as any)
|
||||
|
||||
module.exports = nativeTheme
|
Loading…
Add table
Add a link
Reference in a new issue