ios/Mobile/AppDelegate.mm | 5 ++++ ios/Mobile/DocumentViewController.h | 3 ++ ios/Mobile/DocumentViewController.mm | 42 +++++++++++++++++++++++------------ ios/ios.mm | 2 - kit/Kit.cpp | 3 ++ 5 files changed, 40 insertions(+), 15 deletions(-)
New commits: commit 9d6c1744624639df75b29bc3b2b72b915b064ed3 Author: Tor Lillqvist <[email protected]> AuthorDate: Mon Nov 4 14:07:16 2019 +0200 Commit: Tor Lillqvist <[email protected]> CommitDate: Mon Nov 4 15:25:54 2019 +0100 tdf#128577: Close an already open document when asked to open a new one Add a "singleton" class method to DocumentViewController to return the (as for now) singleton DocumentViewController. Change-Id: I0b8a8def558cfe7f9469b6062a86311dfa63f549 Reviewed-on: https://gerrit.libreoffice.org/82007 Reviewed-by: Tor Lillqvist <[email protected]> Tested-by: Tor Lillqvist <[email protected]> (cherry picked from commit 2807f907d947549a17c5bae586b85d412d552a09) Reviewed-on: https://gerrit.libreoffice.org/82021 diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm index dbc02e66e..40e47a64b 100644 --- a/ios/Mobile/AppDelegate.mm +++ b/ios/Mobile/AppDelegate.mm @@ -291,6 +291,11 @@ static void updateTemplates(NSData *data, NSURLResponse *response) return NO; } + // If we already have a document open, close it + if (lok_document != nullptr && [DocumentViewController singleton] != nil) { + [[DocumentViewController singleton] bye]; + } + // Reveal / import the document at the URL DocumentBrowserViewController *documentBrowserViewController = (DocumentBrowserViewController *)self.window.rootViewController; [documentBrowserViewController revealDocumentAtURL:inputURL importIfNeeded:YES completion:^(NSURL * _Nullable revealedDocumentURL, NSError * _Nullable error) { diff --git a/ios/Mobile/DocumentViewController.h b/ios/Mobile/DocumentViewController.h index 8f4d97b43..1f443b206 100644 --- a/ios/Mobile/DocumentViewController.h +++ b/ios/Mobile/DocumentViewController.h @@ -19,6 +19,9 @@ @property std::string slideshowFile; @property (strong) NSURL *slideshowURL; +- (void)bye; ++ (DocumentViewController*)singleton; + @end // vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/ios/Mobile/DocumentViewController.mm b/ios/Mobile/DocumentViewController.mm index c9d8c5cac..47d096553 100644 --- a/ios/Mobile/DocumentViewController.mm +++ b/ios/Mobile/DocumentViewController.mm @@ -22,6 +22,8 @@ #import "DocumentViewController.h" +static DocumentViewController* theSingleton = nil; + @interface DocumentViewController() <WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler, UIScrollViewDelegate> { int closeNotificationPipeForForwardingThread[2]; } @@ -33,6 +35,8 @@ - (void)viewDidLoad { [super viewDidLoad]; + theSingleton = self; + WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; WKUserContentController *userContentController = [[WKUserContentController alloc] init]; @@ -256,20 +260,7 @@ } else if ([message.body isEqualToString:@"BYE"]) { LOG_TRC("Document window terminating on JavaScript side. Closing our end of the socket."); - // Close one end of the socket pair, that will wake up the forwarding thread above - fakeSocketClose(closeNotificationPipeForForwardingThread[0]); - - [self.document saveToURL:[self.document fileURL] - forSaveOperation:UIDocumentSaveForOverwriting - completionHandler:^(BOOL success) { - LOG_TRC("save completion handler gets " << (success?"YES":"NO")); - }]; - - // Wait for lokit_main thread to exit - std::lock_guard<std::mutex> lock(lokit_main_mutex); - - // And only then let the document browsing view show up again - [self dismissDocumentViewController]; + [self bye]; return; } else if ([message.body isEqualToString:@"SLIDESHOW"]) { @@ -368,6 +359,29 @@ scrollView.pinchGestureRecognizer.enabled = NO; } +- (void)bye { + // Close one end of the socket pair, that will wake up the forwarding thread above + fakeSocketClose(closeNotificationPipeForForwardingThread[0]); + + [self.document saveToURL:[self.document fileURL] + forSaveOperation:UIDocumentSaveForOverwriting + completionHandler:^(BOOL success) { + LOG_TRC("save completion handler gets " << (success?"YES":"NO")); + }]; + + // Wait for lokit_main thread to exit + std::lock_guard<std::mutex> lock(lokit_main_mutex); + + theSingleton = nil; + + // And only then let the document browsing view show up again + [self dismissDocumentViewController]; +} + ++ (DocumentViewController*)singleton { + return theSingleton; +} + @end // vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/ios/ios.mm b/ios/ios.mm index 1416d31e0..8f3ccc3ca 100644 --- a/ios/ios.mm +++ b/ios/ios.mm @@ -18,7 +18,7 @@ extern "C" { } int loolwsd_server_socket_fd = -1; -lok::Document *lok_document; +lok::Document *lok_document = nullptr; LibreOfficeKit *lo_kit; std::mutex lokit_main_mutex; diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 9eac5dc7e..5dede6dd9 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -1391,6 +1391,9 @@ private: #endif LOG_INF("Document [" << anonymizeUrl(_url) << "] has no more views, but has " << _sessions.size() << " sessions still. Destroying the document."); +#ifdef IOS + lok_document = nullptr; +#endif _loKitDocument.reset(); LOG_INF("Document [" << anonymizeUrl(_url) << "] session [" << sessionId << "] unloaded Document."); return; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
