@@ -175,19 +175,25 @@ - (void) scrollViewDidScroll: (UIScrollView*) scrollView {
175175
176176- (void ) handleEdgePanGesture : (UIScreenEdgePanGestureRecognizer*) gesture {
177177 auto window = (Window*) objc_getAssociatedObject (self, " window" );
178- CGPoint translation = [gesture translationInView: self .view];
179- CGFloat progress = translation.x / self.view .bounds .size .width ;
178+ if (!window) {
179+ return ;
180+ }
181+ CGPoint translation = [gesture translationInView: window->viewController.view];
182+ CGFloat progress = translation.x / window->viewController .view .bounds .size .width ;
180183 progress = fmin (fmax (progress, 0.0 ), 1.0 );
181184 if (
182185 gesture.state == UIGestureRecognizerStateEnded ||
183186 gesture.state == UIGestureRecognizerStateCancelled
184187 ) {
185188 if (progress > 0.3 ) {
186189 if (window && window->webview .canGoBack ) {
187- [window->webview. goBack];
190+ [window->webview goBack ];
188191 } else {
189- window->close ();
190- // [self.navigationController popViewControllerAnimated:YES];
192+ const auto app = App::sharedApplication ();
193+ const auto index = window->index ;
194+ app->dispatch ([index, app](){
195+ app->runtime .windowManager .destroyWindow (index);
196+ });
191197 }
192198 }
193199 }
@@ -452,14 +458,15 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
452458
453459 #if SOCKET_RUNTIME_PLATFORM_IOS
454460 this ->webview .allowsBackForwardNavigationGestures = NO ;
455- if (userConfig[" webview_navigator_enable_navigation_gestures" ] == " true" ) {
461+ if (! this -> options . headless && userConfig[" webview_navigator_enable_navigation_gestures" ] == " true" ) {
456462 auto edgePanGesture = [[UIScreenEdgePanGestureRecognizer alloc ]
457463 initWithTarget: this ->windowDelegate
458- action: @selector (handleEdgePanGesture: )
464+ action: @selector (handleEdgePanGesture: )
459465 ];
460466 edgePanGesture.edges = UIRectEdgeLeft;
461- edgePanGesture.delegate = self ;
467+ edgePanGesture.delegate = this -> viewController ;
462468 [this->viewController.view addGestureRecognizer: edgePanGesture];
469+ [this->webview addGestureRecognizer: edgePanGesture];
463470 }
464471 #else
465472 this ->webview .allowsBackForwardNavigationGestures = userConfig[" webview_navigator_enable_navigation_gestures" ] == " true" ;
@@ -798,6 +805,17 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
798805 }
799806
800807 if (this ->webview != nullptr ) {
808+ #if SOCKET_RUNTIME_PLATFORM_IOS
809+ const auto managedWindow = app->runtime .windowManager .getWindow (this ->index );
810+ if (managedWindow) {
811+ const auto json = managedWindow->json ();
812+ for (auto window : app->runtime .windowManager .windows ) {
813+ if (window != nullptr && window->index != this ->index ) {
814+ window->eval (getEmitToRenderProcessJavaScript (" windowclosed" , json.str ()));
815+ }
816+ }
817+ }
818+ #endif
801819 objc_removeAssociatedObjects (this ->webview );
802820 [this->webview stopLoading ];
803821 [this->webview.configuration.userContentController removeAllScriptMessageHandlers ];
@@ -833,9 +851,13 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
833851 }
834852
835853 this ->window .titleBarView = nullptr ;
836- this ->window = nullptr ;
837854 #endif
855+ this ->window = nullptr ;
838856 }
857+
858+ #if SOCKET_RUNTIME_PLATFORM_IOS
859+ this ->viewController = nullptr ;
860+ #endif
839861 }
840862
841863 void Window::maximize () {
0 commit comments