/* * Copyright (c) 2024, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #if !defined(AK_OS_MACOS) static_assert(false, "This file must only be used for macOS"); #endif #include namespace Core { class TimeZoneWatcherImpl final : public TimeZoneWatcher { public: static ErrorOr> create() { return adopt_own(*new TimeZoneWatcherImpl()); } virtual ~TimeZoneWatcherImpl() override { CFNotificationCenterRemoveObserver( CFNotificationCenterGetLocalCenter(), this, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr); } private: explicit TimeZoneWatcherImpl() { CFNotificationCenterAddObserver( CFNotificationCenterGetLocalCenter(), this, time_zone_changed, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately); } static void time_zone_changed(CFNotificationCenterRef, void* observer, CFStringRef, void const*, CFDictionaryRef) { auto const& time_zone_watcher = *reinterpret_cast(observer); if (time_zone_watcher.on_time_zone_changed) time_zone_watcher.on_time_zone_changed(); } }; ErrorOr> TimeZoneWatcher::create() { return TimeZoneWatcherImpl::create(); } }