Skip to content

Commit

Permalink
feat: expose __dateTimeConfigurationChangeNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni committed Jun 21, 2023
1 parent 5a6c2ee commit f6b39ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions NativeScript/runtime/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ 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 @@ -34,6 +34,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 @@ -298,6 +317,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) {
SpinLock lock(isolatesMutex_);
return std::find(Runtime::isolates_.begin(), Runtime::isolates_.end(), isolate) != Runtime::isolates_.end();
Expand Down

0 comments on commit f6b39ed

Please sign in to comment.