Skip to content

Commit

Permalink
feat: expose __dateTimeConfigurationChangeNotification (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Jun 25, 2024
1 parent 6286203 commit 5088f5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NativeScript/runtime/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class Runtime {
void DefinePerformanceObject(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
void DefineTimeMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);
void DefineDrainMicrotaskMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);

void DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate);

static void PerformanceNowCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Isolate* isolate_;
std::unique_ptr<ModuleInternal> moduleInternal_;
Expand Down
26 changes: 26 additions & 0 deletions NativeScript/runtime/Runtime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
SimpleAllocator allocator_;
NSDictionary* AppPackageJson = nil;

// TODO: consider listening to timezone changes and automatically reseting the DateTime. Probably makes more sense to move it to its own file
//void UpdateTimezoneNotificationCallback(CFNotificationCenterRef center,
// void *observer,
// CFStringRef name,
// const void *object,
// CFDictionaryRef userInfo) {
// Runtime* r = (Runtime*)observer;
// auto isolate = r->GetIsolate();
//
// CFRunLoopPerformBlock(r->RuntimeLoop(), kCFRunLoopDefaultMode, ^() {
// TODO: lock isolate here?
// isolate->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
// });
//}
// add this to register (most likely on setting up isolate
//CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, &UpdateTimezoneNotificationCallback, kCFTimeZoneSystemTimeZoneDidChangeNotification, nullptr, CFNotificationSuspensionBehaviorDeliverImmediately);
// add this to remove the observer
//CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), this, kCFTimeZoneSystemTimeZoneDidChangeNotification, NULL);

void DisposeIsolateWhenPossible(Isolate* isolate) {
// most of the time, this will never delay disposal
// occasionally this can happen when the runtime is destroyed by actions of its own isolate
Expand Down Expand Up @@ -379,6 +398,13 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
globalTemplate->Set(ToV8String(isolate, "__drainMicrotaskQueue"), drainMicrotaskTemplate);
}

void Runtime::DefineDateTimeConfigurationChangeNotificationMethod(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> globalTemplate) {
Local<FunctionTemplate> drainMicrotaskTemplate = FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) {
info.GetIsolate()->DateTimeConfigurationChangeNotification(Isolate::TimeZoneDetection::kRedetect);
});
globalTemplate->Set(ToV8String(isolate, "__dateTimeConfigurationChangeNotification"), drainMicrotaskTemplate);
}

bool Runtime::IsAlive(const Isolate* isolate) {
// speedup lookup by avoiding locking if thread locals match
// note: this can be a problem when the Runtime is deleted in a different thread that it was created
Expand Down

0 comments on commit 5088f5f

Please sign in to comment.