diff --git a/Libraries/LibCore/CMakeLists.txt b/Libraries/LibCore/CMakeLists.txt index 245cc4db61..84f265312c 100644 --- a/Libraries/LibCore/CMakeLists.txt +++ b/Libraries/LibCore/CMakeLists.txt @@ -90,6 +90,12 @@ elseif (APPLE AND NOT IOS) Platform/ProcessStatisticsMach.cpp TimeZoneWatcherMacOS.mm ) +elseif (WIN32) + list(APPEND SOURCES + FileWatcherUnimplemented.cpp + Platform/ProcessStatisticsUnimplemented.cpp + TimeZoneWatcherWindows.cpp + ) else() list(APPEND SOURCES FileWatcherUnimplemented.cpp diff --git a/Libraries/LibCore/TimeZoneWatcherWindows.cpp b/Libraries/LibCore/TimeZoneWatcherWindows.cpp new file mode 100644 index 0000000000..9c875d7de9 --- /dev/null +++ b/Libraries/LibCore/TimeZoneWatcherWindows.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025, ayeteadoe + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#if !defined(AK_OS_WINDOWS) +static_assert(false, "This file must only be used for Windows"); +#endif + +namespace Core { + +class TimeZoneWatcherImpl final : public TimeZoneWatcher { +public: + static ErrorOr> create() + { + return adopt_own(*new TimeZoneWatcherImpl()); + } + +private: + TimeZoneWatcherImpl() = default; +}; + +ErrorOr> TimeZoneWatcher::create() +{ + return TimeZoneWatcherImpl::create(); +} + +} diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index c6828ed31f..dd725308ef 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -362,7 +362,7 @@ ErrorOr Application::launch_services() } else { m_time_zone_watcher = time_zone_watcher.release_value(); - m_time_zone_watcher->on_time_zone_changed = []() { + m_time_zone_watcher->on_time_zone_changed = [] { WebContentClient::for_each_client([&](WebView::WebContentClient& client) { client.async_system_time_zone_changed(); return IterationDecision::Continue; @@ -874,6 +874,13 @@ void Application::refresh_tab_list() m_devtools->refresh_tab_list(); } +Optional Application::time_zone_watcher() +{ + if (m_time_zone_watcher != nullptr) + return *m_time_zone_watcher; + return {}; +} + Vector Application::tab_list() const { Vector tabs; diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h index 34185cbb11..75d563a506 100644 --- a/Libraries/LibWebView/Application.h +++ b/Libraries/LibWebView/Application.h @@ -105,6 +105,8 @@ public: ErrorOr toggle_devtools_enabled(); void refresh_tab_list(); + Optional time_zone_watcher(); + protected: explicit Application(Optional ladybird_binary_path = {}); diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp index 0cf39f4fb3..8d50ceef48 100644 --- a/UI/Qt/Application.cpp +++ b/UI/Qt/Application.cpp @@ -18,8 +18,39 @@ #include #include +#if defined(AK_OS_WINDOWS) +# include +# include +# include +#endif + namespace Ladybird { +#if defined(AK_OS_WINDOWS) +class NativeWindowsTimeChangeEventFilter : public QAbstractNativeEventFilter { +public: + NativeWindowsTimeChangeEventFilter(Core::TimeZoneWatcher& time_zone_watcher) + : m_time_zone_watcher(time_zone_watcher) + { + } + + bool nativeEventFilter(QByteArray const& event_type, void* message, qintptr*) override + { + if (event_type == QByteArrayLiteral("windows_generic_MSG")) { + auto msg = static_cast(message); + if (msg->message == WM_TIMECHANGE) { + m_time_zone_watcher.on_time_zone_changed(); + } + } + return false; + } + +private: + Core::TimeZoneWatcher& m_time_zone_watcher; +}; + +#endif + class LadybirdQApplication : public QApplication { public: explicit LadybirdQApplication(Main::Arguments& arguments) @@ -31,6 +62,14 @@ public: { auto& application = static_cast(WebView::Application::the()); +#if defined(AK_OS_WINDOWS) + static Optional time_change_event_filter {}; + if (auto time_zone_watcher = application.time_zone_watcher(); !time_change_event_filter.has_value() && time_zone_watcher.has_value()) { + time_change_event_filter.emplace(time_zone_watcher.value()); + installNativeEventFilter(&time_change_event_filter.value()); + } +#endif + switch (event->type()) { case QEvent::FileOpen: { if (!application.on_open_file)