chore: document deprecated systemPreferences APIs (#39343)
* chore: document deprecated systemPreferences APIs * chore: forgot systemPreferences.appLevelAppearance * test: expect deprecation messages
This commit is contained in:
parent
d5f31c2208
commit
1b3e4dae8d
5 changed files with 97 additions and 19 deletions
|
@ -417,7 +417,7 @@ Returns an object with system animation settings.
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
### `systemPreferences.appLevelAppearance` _macOS_
|
### `systemPreferences.appLevelAppearance` _macOS_ _Deprecated_
|
||||||
|
|
||||||
A `string` property that can be `dark`, `light` or `unknown`. It determines the macOS appearance setting for
|
A `string` property that can be `dark`, `light` or `unknown`. It determines the macOS appearance setting for
|
||||||
your application. This maps to values in: [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc). Setting this will override the
|
your application. This maps to values in: [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc). Setting this will override the
|
||||||
|
|
|
@ -63,6 +63,41 @@ w.webContents.getPrintersAsync().then((printers) => {
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Deprecated: `systemPreferences.{get,set}AppLevelAppearance` and `systemPreferences.appLevelAppearance`
|
||||||
|
|
||||||
|
The `systemPreferences.getAppLevelAppearance` and `systemPreferences.setAppLevelAppearance`
|
||||||
|
methods have been deprecated, as well as the `systemPreferences.appLevelAppearance` property.
|
||||||
|
Use the `nativeTheme` module instead.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Deprecated
|
||||||
|
systemPreferences.getAppLevelAppearance()
|
||||||
|
// Replace with
|
||||||
|
nativeTheme.shouldUseDarkColors
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
systemPreferences.appLevelAppearance
|
||||||
|
// Replace with
|
||||||
|
nativeTheme.shouldUseDarkColors
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
systemPreferences.setAppLevelAppearance('dark')
|
||||||
|
// Replace with
|
||||||
|
nativeTheme.themeSource = 'dark'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deprecated: `alternate-selected-control-text` value for `systemPreferences.getColor`
|
||||||
|
|
||||||
|
The `alternate-selected-control-text` value for `systemPreferences.getColor`
|
||||||
|
has been deprecated. Use `selected-content-background` instead.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Deprecated
|
||||||
|
systemPreferences.getColor('alternate-selected-control-text')
|
||||||
|
// Replace with
|
||||||
|
systemPreferences.getColor('selected-content-background')
|
||||||
|
```
|
||||||
|
|
||||||
## Planned Breaking API Changes (25.0)
|
## Planned Breaking API Changes (25.0)
|
||||||
|
|
||||||
### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol`
|
### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol`
|
||||||
|
|
|
@ -1,12 +1,31 @@
|
||||||
|
import * as deprecate from '@electron/internal/common/deprecate';
|
||||||
|
|
||||||
const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
||||||
|
|
||||||
if ('getAppLevelAppearance' in systemPreferences) {
|
if ('getAppLevelAppearance' in systemPreferences) {
|
||||||
const nativeALAGetter = systemPreferences.getAppLevelAppearance;
|
const nativeALAGetter = systemPreferences.getAppLevelAppearance;
|
||||||
const nativeALASetter = systemPreferences.setAppLevelAppearance;
|
const nativeALASetter = systemPreferences.setAppLevelAppearance;
|
||||||
|
const warnALA = deprecate.warnOnce('appLevelAppearance');
|
||||||
|
const warnALAGetter = deprecate.warnOnce('getAppLevelAppearance function');
|
||||||
|
const warnALASetter = deprecate.warnOnce('setAppLevelAppearance function');
|
||||||
Object.defineProperty(systemPreferences, 'appLevelAppearance', {
|
Object.defineProperty(systemPreferences, 'appLevelAppearance', {
|
||||||
get: () => nativeALAGetter.call(systemPreferences),
|
get: () => {
|
||||||
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
|
warnALA();
|
||||||
|
return nativeALAGetter.call(systemPreferences);
|
||||||
|
},
|
||||||
|
set: (appearance) => {
|
||||||
|
warnALA();
|
||||||
|
nativeALASetter.call(systemPreferences, appearance);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
systemPreferences.getAppLevelAppearance = () => {
|
||||||
|
warnALAGetter();
|
||||||
|
return nativeALAGetter.call(systemPreferences);
|
||||||
|
};
|
||||||
|
systemPreferences.setAppLevelAppearance = (appearance) => {
|
||||||
|
warnALASetter();
|
||||||
|
nativeALASetter.call(systemPreferences, appearance);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('getEffectiveAppearance' in systemPreferences) {
|
if ('getEffectiveAppearance' in systemPreferences) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { once } from 'node:events';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import { setTimeout } from 'node:timers/promises';
|
import { setTimeout } from 'node:timers/promises';
|
||||||
|
|
||||||
|
import { expectDeprecationMessages } from './lib/deprecate-helpers';
|
||||||
import { ifdescribe } from './lib/spec-helpers';
|
import { ifdescribe } from './lib/spec-helpers';
|
||||||
import { closeAllWindows } from './lib/window-helpers';
|
import { closeAllWindows } from './lib/window-helpers';
|
||||||
|
|
||||||
|
@ -59,11 +60,16 @@ describe('nativeTheme module', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
ifdescribe(process.platform === 'darwin')('on macOS', () => {
|
ifdescribe(process.platform === 'darwin')('on macOS', () => {
|
||||||
it('should update appLevelAppearance when set', () => {
|
it('should update appLevelAppearance when set', async () => {
|
||||||
nativeTheme.themeSource = 'dark';
|
await expectDeprecationMessages(
|
||||||
expect(systemPreferences.appLevelAppearance).to.equal('dark');
|
() => {
|
||||||
nativeTheme.themeSource = 'light';
|
nativeTheme.themeSource = 'dark';
|
||||||
expect(systemPreferences.appLevelAppearance).to.equal('light');
|
expect(systemPreferences.appLevelAppearance).to.equal('dark');
|
||||||
|
nativeTheme.themeSource = 'light';
|
||||||
|
expect(systemPreferences.appLevelAppearance).to.equal('light');
|
||||||
|
},
|
||||||
|
"(electron) 'appLevelAppearance' is deprecated and will be removed."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { systemPreferences } from 'electron/main';
|
import { systemPreferences } from 'electron/main';
|
||||||
|
import { expectDeprecationMessages } from './lib/deprecate-helpers';
|
||||||
import { ifdescribe } from './lib/spec-helpers';
|
import { ifdescribe } from './lib/spec-helpers';
|
||||||
|
|
||||||
describe('systemPreferences module', () => {
|
describe('systemPreferences module', () => {
|
||||||
|
@ -174,9 +175,8 @@ describe('systemPreferences module', () => {
|
||||||
}).to.throw(`Unknown color: ${color}`);
|
}).to.throw(`Unknown color: ${color}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a valid color', () => {
|
it('returns a valid color', async () => {
|
||||||
const colors = [
|
const colors = [
|
||||||
'alternate-selected-control-text',
|
|
||||||
'control-background',
|
'control-background',
|
||||||
'control',
|
'control',
|
||||||
'control-text',
|
'control-text',
|
||||||
|
@ -209,12 +209,20 @@ describe('systemPreferences module', () => {
|
||||||
'unemphasized-selected-text',
|
'unemphasized-selected-text',
|
||||||
'window-background',
|
'window-background',
|
||||||
'window-frame-text'
|
'window-frame-text'
|
||||||
];
|
] as const;
|
||||||
|
|
||||||
colors.forEach(color => {
|
colors.forEach(color => {
|
||||||
const sysColor = systemPreferences.getColor(color as any);
|
const sysColor = systemPreferences.getColor(color);
|
||||||
expect(sysColor).to.be.a('string');
|
expect(sysColor).to.be.a('string');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await expectDeprecationMessages(
|
||||||
|
() => {
|
||||||
|
const sysColor = systemPreferences.getColor('alternate-selected-control-text');
|
||||||
|
expect(sysColor).to.be.a('string');
|
||||||
|
},
|
||||||
|
"'alternate-selected-control-text' is deprecated as an input to getColor. Use 'selected-content-background' instead."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -233,15 +241,25 @@ describe('systemPreferences module', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with functions', () => {
|
describe('with functions', () => {
|
||||||
it('returns a valid appearance', () => {
|
it('returns a valid appearance', async () => {
|
||||||
const appearance = systemPreferences.getAppLevelAppearance();
|
await expectDeprecationMessages(
|
||||||
expect(options).to.include(appearance);
|
() => {
|
||||||
|
const appearance = systemPreferences.getAppLevelAppearance();
|
||||||
|
expect(options).to.include(appearance);
|
||||||
|
},
|
||||||
|
"(electron) 'getAppLevelAppearance function' is deprecated and will be removed."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be changed', () => {
|
it('can be changed', async () => {
|
||||||
systemPreferences.setAppLevelAppearance('dark');
|
await expectDeprecationMessages(
|
||||||
const appearance = systemPreferences.getAppLevelAppearance();
|
() => {
|
||||||
expect(appearance).to.eql('dark');
|
systemPreferences.setAppLevelAppearance('dark');
|
||||||
|
const appearance = systemPreferences.getAppLevelAppearance();
|
||||||
|
expect(appearance).to.eql('dark');
|
||||||
|
},
|
||||||
|
"(electron) 'setAppLevelAppearance function' is deprecated and will be removed."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue