Skip to content

Commit f6b39ed

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

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

NativeScript/runtime/Runtime.h

+1
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

+26
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@
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+
// TODO: lock isolate here?
48+
// isolate->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
49+
// });
50+
//}
51+
// add this to register (most likely on setting up isolate
52+
//CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, &UpdateTimezoneNotificationCallback, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately);
53+
// add this to remove the observer
54+
//CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kCFTimeZoneSystemTimeZoneDidChangeNotification, NULL);
55+
3756
void DisposeIsolateWhenPossible(Isolate* isolate) {
3857
// most of the time, this will never delay disposal
3958
// occasionally this can happen when the runtime is destroyed by actions of its own isolate
@@ -298,6 +317,13 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
298317
globalTemplate->Set(ToV8String(isolate, "__drainMicrotaskQueue"), drainMicrotaskTemplate);
299318
}
300319

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

0 commit comments

Comments
 (0)