xiaoyifang / goldendict-ng

The Next Generation GoldenDict
https://xiaoyifang.github.io/goldendict-ng/
Other
1.6k stars 87 forks source link

Dark reader mode: welcome page's text also get dark when turning on. #1450

Closed atauzki closed 2 months ago

atauzki commented 6 months ago

The version I used is compiled with qt6.7.0: https://cloud.freemdict.com/index.php/s/psF3GZstsYZ3JZc

step:

  1. open goldendict
  2. set "Dark reader mode" to "ON"
  3. text are getting black.

This is the screenshort: https://github.com/xiaoyifang/goldendict-ng/assets/19769843/26695d63-5a8d-4855-9d90-96970d2b8927

atauzki commented 6 months ago

And I also tried the latest version on Github, it takes no effect before relaunching the program or make a word query.

shenlebantongying commented 6 months ago

I don't have time right now due to exams in the following weeks.

However, these are my guesses:

  1. This change is problematic https://github.com/xiaoyifang/goldendict-ng/pull/1406
  2. Various code were added to Qt6.7 that enables Chrome's built-in dark mode. Qt6.7 has this new ForceDarkMode (which is an exp experimental feature flag chrome://flags/#enable-force-dark)
  3. We need to bump dark-reader.js which is almost 2 years behind
    1. https://github.com/xiaoyifang/goldendict-ng/blob/staged/src/scripts/darkreader.js
    2. https://github.com/darkreader/darkreader/blob/main/CHANGELOG.md#4958-sep-22-2022
xiaoyifang commented 6 months ago

https://github.com/xiaoyifang/goldendict-ng/pull/1452

@atauzki can you help to try this PR?

atauzki commented 6 months ago

background and text in welcome page dont change to black before query or restart just like before.

xiaoyifang commented 5 months ago

I guess the reason is that the welcome page does not refresh when the dark mode setting changes

shenlebantongying commented 4 months ago

I tried all configurations other than on Windows. I cannot reproduce in any way.

Maybe you have local article-style.css affecting it?

atauzki commented 4 months ago

article-style.css

.mdict + .mdict {
    margin-top: 20px
}

.mwiki {
    font-size: 14px
}

compiled last code, and comment these code, still reproducable.

shenlebantongying commented 4 months ago

Don't screenshot code my friend, just copy and paste 🫠🫠🫠🫠🫠

I will check it when I can access a Windows machine today.

shenlebantongying commented 4 months ago

I still cannot reproduce, the article-style.css is inserted.

Maybe a bug of re-release Qt6.7? This issue was opened when Qt6.7 was not yet released.

image

atauzki commented 4 months ago

I tried 6.6.2 build on github action build on Mar 31, the day I proposed this issue. And qt 6.7.0 action is not completed that time. In 6.6.2, the welcome page has no change at all after turn on the dark reader mode until restart. (not portable mode, so no extra config takes effect) Maybe the background change affected 6.7.0 but doesn't affect 6.6.2. Then I inspected the page shows darkreader.js doesn't loads until restart in both version.

shenlebantongying commented 4 months ago

This problem is super weird.

Set a breakpoint here: https://github.com/xiaoyifang/goldendict-ng/blob/fb91eba36f90ee31a2c40936b0323834780310ef/src/ui/mainwindow.cc#L2277-L2283

view.currentWord is "welcome!", so the right widget got picked up.

needReload is true, the webview's reload is called.

Manually calling view.reload(); is debugger -> won't trigger reload. The reload is called, but LocalSchemeHandler::requestStarted will not be triggered (????)

However, when switching dark mode on and off, you can rigger reload inside the browser's inspector by calling location.reload() in JavaScript and the welcome page will successfully reload and dark theme will be correctly set. (????)

All other pages other than welcome are OK.

xiaoyifang commented 2 months ago

Fixed.

try with latest source code