Skip to content

Commit 5088f5f

Browse files
authored
feat: expose __dateTimeConfigurationChangeNotification (#220)
1 parent 6286203 commit 5088f5f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

NativeScript/runtime/Runtime.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ 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-
72+
void DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
73+
7374
static void PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
7475
v8::Isolate* isolate_;
7576
std::unique_ptr<ModuleInternal> moduleInternal_;

NativeScript/runtime/Runtime.mm

+26
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@
3838
SimpleAllocator allocator_;
3939
NSDictionary* AppPackageJson = nil;
4040

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

401+
void Runtime::DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate) {
402+
Local<FunctionTemplate> drainMicrotaskTemplate = FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) {
403+
info.GetIsolate()->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
404+
});
405+
globalTemplate->Set(ToV8String(isolate, "__dateTimeConfigurationChangeNotification"), drainMicrotaskTemplate);
406+
}
407+
382408
bool Runtime::IsAlive(const Isolate* isolate) {
383409
// speedup lookup by avoiding locking if thread locals match
384410
// note: this can be a problem when the Runtime is deleted in a different thread that it was created

0 commit comments

Comments
 (0)