Skip to content

Commit

Permalink
feat: add default event to turn on the JavaScript GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall authored and yifei8 committed Mar 21, 2024
1 parent c6d843d commit fb0a8f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bridge/core/dom/events/event_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ NativeValue EventTarget::HandleDispatchEventFromDart(int32_t argc, const NativeV
assert(event->currentTarget() != nullptr);

auto* window = DynamicTo<Window>(event->target());
if (window != nullptr && event->type() == event_type_names::kload) {
if (window != nullptr && (event->type() == event_type_names::kload || event->type() == event_type_names::kgcopen)) {
window->OnLoadEventFired();
}

Expand Down
3 changes: 2 additions & 1 deletion bridge/core/events/event_type_names.json5
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"webglcontextrestored",
"wheel",
"zoom",
"intersectionchange"
"intersectionchange",
"gcopen"
]
}
1 change: 1 addition & 0 deletions webf/lib/src/dom/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Window extends EventTarget {
: screen = Screen(context!.contextId, document.controller.ownerFlutterView, document.controller.view),
super(context) {
BindingBridge.listenEvent(this, 'load');
BindingBridge.listenEvent(this, 'gcopen');
}

@override
Expand Down
5 changes: 5 additions & 0 deletions webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ class WebFViewController implements WidgetsBindingObserver {
window = Window(BindingContext(view, _contextId, pointer), document);
_registerPlatformBrightnessChange();

// 3 seconds should be enough for page loading, make sure the JavaScript GC was opened.
Timer(Duration(seconds: 3), () {
window.dispatchEvent(Event('gcopen'));
});

// Blur input element when new input focused.
window.addEventListener(EVENT_CLICK, (event) async {
if (event.target is Element) {
Expand Down

0 comments on commit fb0a8f6

Please sign in to comment.