tdf#123742: Fix lifecycle issues for the "Office" object
Because of the use of std::shared_ptr in lokit_main(), the (singleton)
lok::Office (or LibLibreOffice_Impl) object gets destroyed when
lokit_main() exits. We shouldn't keep our own copy of a raw pointer to
it around. Just call lok_init_2() to get the pointer where we need it.
We don't need to call lok_init_2() already in -[AppDelegate
application:didFinishLaunchingWithOptions:].
diff --git a/ios/Mobile/AppDelegate.h b/ios/Mobile/AppDelegate.h
index d9c6c00..58c09bf 100644
--- a/ios/Mobile/AppDelegate.h
+++ b/ios/Mobile/AppDelegate.h
@@ -17,7 +17,6 @@
@end
extern NSString *app_locale;
extern LibreOfficeKit *lo_kit;
// vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm
index 001f0f5..b67caf1 100644
--- a/ios/Mobile/AppDelegate.mm
+++ b/ios/Mobile/AppDelegate.mm
@@ -27,7 +27,6 @@
static LOOLWSD *loolwsd = nullptr;
NSString *app_locale;
LibreOfficeKit *lo_kit;
static void download(NSURL *source, NSURL *destination) {
[[[NSURLSession sharedSession] downloadTaskWithURL:source
@@ -184,11 +183,6 @@
}
}
// Initialize LibreOfficeKit.
lo_kit = lok_init_2(nullptr, nullptr);
lo_kit->pClass->registerCallback(lo_kit, [](int, const char *, void*){}, nullptr);
fakeSocketSetLoggingCallback([](const std::string& line)
{
LOG_TRC_NOFILE(line);
diff --git a/ios/Mobile/TemplateCollectionViewController.mm b/ios/Mobile/TemplateCollectionViewController.mm
index c5da8ef..a31f3a6 100644
--- a/ios/Mobile/TemplateCollectionViewController.mm
+++ b/ios/Mobile/TemplateCollectionViewController.mm
@@ -8,6 +8,8 @@
#import "svtools/strings.hrc"
#import <LibreOfficeKit/LibreOfficeKitInit.h>
#import "AppDelegate.h"
#import "L10n.h"
#import "TemplateCollectionViewController.h"
@@ -136,8 +138,11 @@
NSURL *newURL = [cacheDirectory URLByAppendingPathComponent:mapTemplateExtensionToActual(selectedTemplate.lastPathComponent)
isDirectory:NO];
LibreOfficeKit *lo_kit = lok_init_2(nullptr, nullptr);
// Load the template into LibreOffice core, save as the corresponding document type (with the
// same basename), and then proceed to edit that.
LibreOfficeKitDocument *doc = lo_kit->pClass->documentLoad(lo_kit, [[selectedTemplate absoluteString] UTF8String]);
doc->pClass->saveAs(doc, [[newURL absoluteString] UTF8String], nullptr, nullptr);
doc->pClass->destroy(doc);