Skip to content

[Bug]: Documentation & TypeScript Types inaccuracte for set systemPreferences.appLevelAppearance #30413

Closed as not planned
@nathanlesage

Description

@nathanlesage

Preflight Checklist

Electron Version

13.1.8

What operating system are you using?

macOS

Operating System Version

macOS Big Sur 11.4

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

After attempting to reset the appLevelAppearance from either light or dark to using the operating system appearance does not work by setting it to unknown. That gave me a "conversion error".

Taking a look into the source code for the systemPreferences API, one can see that there are in fact three possible ways of setting the appLevelAppearance – light, dark and one being undocumented – namely the null value:

if (val->IsNull()) {
*out = nil;
return true;
}

In fact, the appLevelAppearance can successfully be reset by using the following line of code:

systemPreferences.appLevelAppearance = null

I tested this and it worked out of the box.

Actual Behavior

However, upon trying this and set the appLevelAppearance to null, it turned out the Electron types (used for TypeScript) give me an error. But they do not give me an error using the wrong value of 'unknown' which throws the above-mentioned "conversion error".

I recommend the following updates:

  1. Update the Electron typings so that the appLevelAppearance setter accepts null as a valid property to set the app-level appearance to nil
  2. Update the documentation to reflect that you can reset the appLevelAppearance at runtime by setting it to null

Further, I think it might be more appropriate to consolidate getter and setter and, instead of returning "unknown" return the JavaScript representation of nil, namely: null (or even undefined). Alternatively, the setter might accept unknown and convert that internally to nil.

Testcase Gist URL

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions