Skip to content

feat: expose __dateTimeConfigurationChangeNotification #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading