LibWebView+WebContent: Monitor for system time zone changes

This creates a TimeZoneWatcher in the UI process to inform all open
WebContent processes when the time zone changes. The WebContent process
will clear its time zone cache to retrieve a fresh zone the next time
it is asked for one.
This commit is contained in:
Timothy Flynn 2024-08-24 12:15:20 -04:00 committed by Andreas Kling
commit d8c69a0e9e
Notes: github-actions[bot] 2024-08-25 07:48:36 +00:00
5 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,8 @@
#include <AK/Debug.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/TimeZoneWatcher.h>
#include <LibImageDecoderClient/Client.h>
#include <LibWebView/Application.h>
#include <LibWebView/URL.h>
@ -20,6 +22,22 @@ Application::Application()
VERIFY(!s_the);
s_the = this;
// No need to monitor the system time zone if the TZ environment variable is set, as it overrides system preferences.
if (!Core::Environment::has("TZ"sv)) {
if (auto time_zone_watcher = Core::TimeZoneWatcher::create(); time_zone_watcher.is_error()) {
warnln("Unable to monitor system time zone: {}", time_zone_watcher.error());
} else {
m_time_zone_watcher = time_zone_watcher.release_value();
m_time_zone_watcher->on_time_zone_changed = []() {
WebContentClient::for_each_client([&](WebView::WebContentClient& client) {
client.async_system_time_zone_changed();
return IterationDecision::Continue;
});
};
}
}
m_process_manager.on_process_exited = [this](Process&& process) {
process_did_exit(move(process));
};