Browse Source

chore: remove deprecated systemPreferences APIs (#39804)

Co-authored-by: John Kleinschmidt <[email protected]>
David Sanders 1 year ago
parent
commit
686adf9d15

+ 0 - 26
docs/api/system-preferences.md

@@ -273,7 +273,6 @@ This API is only available on macOS 10.14 Mojave or newer.
     * `window-frame` - Window frame.
     * `window-text` - Text in windows.
   * On **macOS**
-    * `alternate-selected-control-text` - The text on a selected surface in a list or table. _Deprecated_
     * `control-background` - The background of a large interface element, such as a browser or table.
     * `control` - The surface of a control.
     * `control-text` -The text of a control that isn’t disabled.
@@ -339,21 +338,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)
 
-### `systemPreferences.getAppLevelAppearance()` _macOS_ _Deprecated_
-
-Returns `string` | `null` - Can be `dark`, `light` or `unknown`.
-
-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.
-
-### `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`.
-
 ### `systemPreferences.canPromptTouchID()` _macOS_
 
 Returns `boolean` - whether or not this device has the ability to use Touch ID.
@@ -417,16 +401,6 @@ Returns an object with system animation settings.
 
 ## Properties
 
-### `systemPreferences.appLevelAppearance` _macOS_ _Deprecated_
-
-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
-system default as well as the value of `getEffectiveAppearance`.
-
-Possible values that can be set are `dark` and `light`, and possible return values are `dark`, `light`, and `unknown`.
-
-This property is only available on macOS 10.14 Mojave or newer.
-
 ### `systemPreferences.effectiveAppearance` _macOS_ _Readonly_
 
 A `string` property that can be `dark`, `light` or `unknown`.

+ 35 - 0
docs/breaking-changes.md

@@ -61,6 +61,41 @@ w.webContents.getPrintersAsync().then((printers) => {
 })
 ```
 
+### Removed: `systemPreferences.{get,set}AppLevelAppearance` and `systemPreferences.appLevelAppearance`
+
+The `systemPreferences.getAppLevelAppearance` and `systemPreferences.setAppLevelAppearance`
+methods have been removed, as well as the `systemPreferences.appLevelAppearance` property.
+Use the `nativeTheme` module instead.
+
+```js
+// Removed
+systemPreferences.getAppLevelAppearance()
+// Replace with
+nativeTheme.shouldUseDarkColors
+
+// Removed
+systemPreferences.appLevelAppearance
+// Replace with
+nativeTheme.shouldUseDarkColors
+
+// Removed
+systemPreferences.setAppLevelAppearance('dark')
+// Replace with
+nativeTheme.themeSource = 'dark'
+```
+
+### Removed: `alternate-selected-control-text` value for `systemPreferences.getColor`
+
+The `alternate-selected-control-text` value for `systemPreferences.getColor`
+has been removed. Use `selected-content-background` instead.
+
+```js
+// Removed
+systemPreferences.getColor('alternate-selected-control-text')
+// Replace with
+systemPreferences.getColor('selected-content-background')
+```
+
 ## Planned Breaking API Changes (26.0)
 
 ### Deprecated: `webContents.getPrinters`

+ 0 - 28
lib/browser/api/system-preferences.ts

@@ -1,33 +1,5 @@
-import * as deprecate from '@electron/internal/common/deprecate';
-
 const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
 
-if ('getAppLevelAppearance' in systemPreferences) {
-  const nativeALAGetter = systemPreferences.getAppLevelAppearance;
-  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', {
-    get: () => {
-      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) {
   const nativeEAGetter = systemPreferences.getEffectiveAppearance;
   Object.defineProperty(systemPreferences, 'effectiveAppearance', {

+ 0 - 4
shell/browser/api/electron_api_system_preferences.cc

@@ -90,10 +90,6 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
                  &SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
       .SetMethod("getEffectiveAppearance",
                  &SystemPreferences::GetEffectiveAppearance)
-      .SetMethod("getAppLevelAppearance",
-                 &SystemPreferences::GetAppLevelAppearance)
-      .SetMethod("setAppLevelAppearance",
-                 &SystemPreferences::SetAppLevelAppearance)
       .SetMethod("getSystemColor", &SystemPreferences::GetSystemColor)
       .SetMethod("canPromptTouchID", &SystemPreferences::CanPromptTouchID)
       .SetMethod("promptTouchID", &SystemPreferences::PromptTouchID)

+ 0 - 2
shell/browser/api/electron_api_system_preferences.h

@@ -112,8 +112,6 @@ class SystemPreferences
   // TODO(MarshallOfSound): Write tests for these methods once we
   // are running tests on a Mojave machine
   v8::Local<v8::Value> GetEffectiveAppearance(v8::Isolate* isolate);
-  v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
-  void SetAppLevelAppearance(gin::Arguments* args);
 #endif
   v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
 

+ 1 - 23
shell/browser/api/electron_api_system_preferences_mac.mm

@@ -475,14 +475,7 @@ bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
 std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
                                         const std::string& color) {
   NSColor* sysColor = nil;
-  if (color == "alternate-selected-control-text") {
-    sysColor = [NSColor alternateSelectedControlTextColor];
-    EmitWarning(
-        node::Environment::GetCurrent(thrower.isolate()),
-        "'alternate-selected-control-text' is deprecated as an input to "
-        "getColor.  Use 'selected-content-background' instead.",
-        "electron");
-  } else if (color == "control-background") {
+  if (color == "control-background") {
     sysColor = [NSColor controlBackgroundColor];
   } else if (color == "control") {
     sysColor = [NSColor controlColor];
@@ -609,19 +602,4 @@ v8::Local<v8::Value> SystemPreferences::GetEffectiveAppearance(
       isolate, [NSApplication sharedApplication].effectiveAppearance);
 }
 
-v8::Local<v8::Value> SystemPreferences::GetAppLevelAppearance(
-    v8::Isolate* isolate) {
-  return gin::ConvertToV8(isolate,
-                          [NSApplication sharedApplication].appearance);
-}
-
-void SystemPreferences::SetAppLevelAppearance(gin::Arguments* args) {
-  NSAppearance* appearance;
-  if (args->GetNext(&appearance)) {
-    [[NSApplication sharedApplication] setAppearance:appearance];
-  } else {
-    args->ThrowError();
-  }
-}
-
 }  // namespace electron::api

+ 1 - 17
spec/api-native-theme-spec.ts

@@ -1,11 +1,9 @@
 import { expect } from 'chai';
-import { nativeTheme, systemPreferences, BrowserWindow, ipcMain } from 'electron/main';
+import { nativeTheme, BrowserWindow, ipcMain } from 'electron/main';
 import { once } from 'node:events';
 import * as path from 'node:path';
 import { setTimeout } from 'node:timers/promises';
 
-import { expectDeprecationMessages } from './lib/deprecate-helpers';
-import { ifdescribe } from './lib/spec-helpers';
 import { closeAllWindows } from './lib/window-helpers';
 
 describe('nativeTheme module', () => {
@@ -59,20 +57,6 @@ describe('nativeTheme module', () => {
       expect(called).to.equal(false);
     });
 
-    ifdescribe(process.platform === 'darwin')('on macOS', () => {
-      it('should update appLevelAppearance when set', async () => {
-        await expectDeprecationMessages(
-          () => {
-            nativeTheme.themeSource = 'dark';
-            expect(systemPreferences.appLevelAppearance).to.equal('dark');
-            nativeTheme.themeSource = 'light';
-            expect(systemPreferences.appLevelAppearance).to.equal('light');
-          },
-          "(electron) 'appLevelAppearance' is deprecated and will be removed."
-        );
-      });
-    });
-
     const getPrefersColorSchemeIsDark = async (w: Electron.BrowserWindow) => {
       const isDark: boolean = await w.webContents.executeJavaScript(
         'matchMedia("(prefers-color-scheme: dark)").matches'

+ 0 - 47
spec/api-system-preferences-spec.ts

@@ -1,6 +1,5 @@
 import { expect } from 'chai';
 import { systemPreferences } from 'electron/main';
-import { expectDeprecationMessages } from './lib/deprecate-helpers';
 import { ifdescribe } from './lib/spec-helpers';
 
 describe('systemPreferences module', () => {
@@ -215,52 +214,6 @@ describe('systemPreferences module', () => {
         const sysColor = systemPreferences.getColor(color);
         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."
-      );
-    });
-  });
-
-  ifdescribe(process.platform === 'darwin')('systemPreferences.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', async () => {
-        await expectDeprecationMessages(
-          () => {
-            const appearance = systemPreferences.getAppLevelAppearance();
-            expect(options).to.include(appearance);
-          },
-          "(electron) 'getAppLevelAppearance function' is deprecated and will be removed."
-        );
-      });
-
-      it('can be changed', async () => {
-        await expectDeprecationMessages(
-          () => {
-            systemPreferences.setAppLevelAppearance('dark');
-            const appearance = systemPreferences.getAppLevelAppearance();
-            expect(appearance).to.eql('dark');
-          },
-          "(electron) 'setAppLevelAppearance function' is deprecated and will be removed."
-        );
-      });
     });
   });
 

+ 8 - 0
spec/ts-smoke/electron/main.ts

@@ -377,6 +377,14 @@ if (process.platform === 'darwin') {
   console.log(value);
   const value2 = systemPreferences.getUserDefault('Foo', 'boolean');
   console.log(value2);
+  // @ts-expect-error Removed API
+  console.log(systemPreferences.getAppLevelAppearance());
+  // @ts-expect-error Removed API
+  systemPreferences.setAppLevelAppearance('dark');
+  // @ts-expect-error Removed API
+  console.log(systemPreferences.appLevelAppearance);
+  // @ts-expect-error Removed API
+  console.log(systemPreferences.getColor('alternate-selected-control-text'));
 }
 
 // Create the window.