Skip to content

Commit 9c7b2c3

Browse files
committed
feat: expose __dateTimeConfigurationChangeNotification
1 parent 5a6c2ee commit 9c7b2c3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

NativeScript/runtime/Runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Runtime {
6969
void DefinePerformanceObject(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
7070
void DefineTimeMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
7171
void DefineDrainMicrotaskMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
72+
void DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
7273
static void PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
7374
v8::Isolate* isolate_;
7475
std::unique_ptr<ModuleInternal> moduleInternal_;

NativeScript/runtime/Runtime.mm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
SimpleAllocator allocator_;
3535
NSDictionary* AppPackageJson = nil;
3636

37+
// TODO: consider listening to timezone changes and automatically reseting the DateTime. Probably makes more sense to move it to its own file
38+
//void UpdateTimezoneNotificationCallback(CFNotificationCenterRef center,
39+
// void *observer,
40+
// CFStringRef name,
41+
// const void *object,
42+
// CFDictionaryRef userInfo) {
43+
// Runtime* r = (Runtime*)observer;
44+
// auto isolate = r->GetIsolate();
45+
//
46+
// CFRunLoopPerformBlock(r->RuntimeLoop(), kCFRunLoopDefaultMode, ^() {
47+
// isolate->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
48+
// });
49+
//}
50+
// add this to register (most likely on setting up isolate
51+
//CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, &UpdateTimezoneNotificationCallback, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately);
52+
// add this to remove the observer
53+
//CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kCFTimeZoneSystemTimeZoneDidChangeNotification, NULL);
54+
3755
void DisposeIsolateWhenPossible(Isolate* isolate) {
3856
// most of the time, this will never delay disposal
3957
// occasionally this can happen when the runtime is destroyed by actions of its own isolate
@@ -298,6 +316,13 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
298316
globalTemplate->Set(ToV8String(isolate, "__drainMicrotaskQueue"), drainMicrotaskTemplate);
299317
}
300318

319+
void Runtime::DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate) {
320+
Local<FunctionTemplate> drainMicrotaskTemplate = FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) {
321+
info.GetIsolate()->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
322+
});
323+
globalTemplate->Set(ToV8String(isolate, "__dateTimeConfigurationChangeNotification"), drainMicrotaskTemplate);
324+
}
325+
301326
bool Runtime::IsAlive(const Isolate* isolate) {
302327
SpinLock lock(isolatesMutex_);
303328
return std::find(Runtime::isolates_.begin(), Runtime::isolates_.end(), isolate) != Runtime::isolates_.end();

0 commit comments

Comments
 (0)