Repository: electron
Issue: [Bug]: Electron incorrectly detects light system theme instead of dark
Labels: platform/linux,bug :beetle:,30-x-y

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

30.1.2

### What operating system(s) are you using?

Other Linux

### Operating System Version

Debian GNU/Linux 12 (bookworm)

### What arch are you using?

x64

### Last Known Working Electron version

27.3.2

### Expected Behavior

Electron should detect dark GTK/system themes as Dark theme

### Actual Behavior

Electron detects the theme as dark first, then switches over to light theme. More details below.

### Testcase Gist URL

_No response_

### Additional Information

With the https://github.com/aeschli/electron-theme-test.git test application, I get the following console output:

```
~/git/tmp/electron-theme-test on  master took 8s 
❯ npm start

> burly-rate-begin-iqsp1@1.0.1 start
> electron-forge start

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook

shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
```

Note how the `shouldUseDarkColors` is initially detected as `true` but then somehow flipping over to `false`. This matches the behaviour I've seen in VS Code, where I first saw this bug: it started out with using a dark theme, then switched over to a light theme after ~0.5s or so.

These are the details of the last VS Code version which works correctly on my machine:

```
Version: 1.87.2
Commit: 863d2581ecda6849923a2118d93a088b0745d9d6
Date: 2024-03-08T15:14:59.643Z
Electron: 27.3.2
ElectronBuildId: 26836302
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Linux x64 6.1.0-20-amd64
```

This version does not work correctly:

```
Version: 1.92.2
Commit: fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
Date: 2024-08-14T17:29:30.058Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Linux x64 6.1.0-20-amd64
```

Interestingly enough, if I edit the `electron-theme-test` application like this:

```diff
diff --git package.json package.json
index 03a9f14..c858d78 100644
--- package.json
+++ package.json
@@ -16,7 +16,7 @@
   },
   "dependencies": {},
   "devDependencies": {
-    "electron": "^30.3.1",
+    "electron": "^27.3.2",
     "@electron-forge/cli": "^7.4.0",
     "@electron-forge/maker-deb": "^7.4.0",
     "@electron-forge/maker-rpm": "^7.4.0",
```

...I still get similar output re. the `shouldUseDarkColors`. :thinking: But the VS Code version using this Electron version does indeed work correctly on my machine.

```
~/git/tmp/electron-theme-test on  master [!] 
❯ npm start

> burly-rate-begin-iqsp1@1.0.1 start
> electron-forge start

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook

shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: true, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
shouldUseDarkColors: false, shouldUseHighContrastColors: false, shouldUseInvertedColorScheme: false
```

Any ideas on how we can debug this further?

Original VS Code issue: https://github.com/microsoft/vscode/issues/225470