Commit 5d4d962
committed
Fix dark mode toolbar icon not displaying correctly on Safari launch
Problem:
The toolbar icon defaulted to light mode on fresh Safari launch because
background scripts don't have access to window.matchMedia for detecting
the system color scheme. The cachedIsDark variable was initialized to
false and only updated when the popup was opened.
Solution:
Use native messaging to query the macOS container app for the system
appearance on extension startup. The Swift SafariWebExtensionHandler
uses NSApp.effectiveAppearance to reliably detect dark mode and returns
it to the background script.
Additionally, the content script now detects and reports the color
scheme on every page load and listens for appearance changes, providing
live updates when the user toggles dark/light mode.
Detection now happens through multiple mechanisms:
1. On startup: Native messaging queries Swift for NSApp.effectiveAppearance
2. On page load: Content script sends prefers-color-scheme state
3. On appearance change: Content script listener fires
4. On popup open: Popup reports color scheme (fallback)
Changes:
- Add nativeMessaging permission to manifest.json
- Add getAppearance handler to SafariWebExtensionHandler.swift
- Add initializeAppearance() in background.js to query native app
- Add color scheme detection to content.js
- Add debug logging throughout for troubleshooting
- Remove dark mode issue from KNOWN_ISSUES.md (now resolved)1 parent f6976be commit 5d4d962
6 files changed
Lines changed: 111 additions & 20 deletions
File tree
- CF Cache Status/CF Cache Status Extension
- Resources
Lines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
46 | 74 | | |
47 | 75 | | |
48 | 76 | | |
| |||
85 | 113 | | |
86 | 114 | | |
87 | 115 | | |
| 116 | + | |
88 | 117 | | |
89 | 118 | | |
90 | 119 | | |
| |||
276 | 305 | | |
277 | 306 | | |
278 | 307 | | |
279 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
280 | 313 | | |
281 | 314 | | |
282 | 315 | | |
| 316 | + | |
283 | 317 | | |
284 | 318 | | |
285 | 319 | | |
| |||
293 | 327 | | |
294 | 328 | | |
295 | 329 | | |
296 | | - | |
| 330 | + | |
297 | 331 | | |
298 | 332 | | |
299 | 333 | | |
| |||
305 | 339 | | |
306 | 340 | | |
307 | 341 | | |
| 342 | + | |
308 | 343 | | |
309 | 344 | | |
| 345 | + | |
310 | 346 | | |
| 347 | + | |
311 | 348 | | |
312 | 349 | | |
313 | 350 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
Lines changed: 33 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
32 | 52 | | |
33 | 53 | | |
34 | | - | |
| 54 | + | |
35 | 55 | | |
36 | | - | |
| 56 | + | |
37 | 57 | | |
38 | 58 | | |
39 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
40 | 70 | | |
41 | 71 | | |
42 | 72 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
7 | 14 | | |
8 | 15 | | |
9 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
0 commit comments