2018-09-11 01:30:55 -05:00
|
|
|
// -*- Mode: objc; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*-
|
2023-11-18 08:13:14 -06:00
|
|
|
/*
|
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2018-09-11 01:30:55 -05:00
|
|
|
|
|
|
|
#import "config.h"
|
|
|
|
|
2018-09-13 11:16:00 -05:00
|
|
|
#import <cassert>
|
2018-11-06 09:19:46 -06:00
|
|
|
#import <cstdlib>
|
2018-09-13 11:16:00 -05:00
|
|
|
#import <cstring>
|
2018-09-11 01:30:55 -05:00
|
|
|
|
2019-10-11 04:18:27 -05:00
|
|
|
#import <LibreOfficeKit/LibreOfficeKit.hxx>
|
Add a way to have templates specific to a customer deployment
Add two settings: One setting "Template list URL" is a string that
should either be empty (the typical case for a random user of the
app), or contain a https: URL. If this setting is empty, only the
templates bundled in the app are provided.
If the "Template list URL" is non-empty, it should be a https: URL
pointing to a text file (or dynamically generated text resource). That
file is downloaded and read when the app starts. Each line in the file
should either be a comment (starting with a hash '#'), or a https: URL
pointing to a template document, that is of type .ott, .ots, or .otp.
That document is downloaded if it hasn't been downloaded already, or
if its time stamp is newer than that of the already downloaded copy.
Also a thumbnail image for the template, formed by appending ".png" to
its URL, is downloaded, if available.
Any previously downloaded templates that aren't mentioned in the list
file are removed.
The intent is that in some managed mass deployment environment, the
mobile device management software would set up this setting, so that
the end-user devices would see the same templates.
Obviously, this URL does not have to point to a static file on a web
server, but could point to some dynamically generated resource on a
web server, that enumerates the templates available on the server and
returns their URLs as a text document.
Another setting is "Empty tile cache next time". This is a toggle. If
toggled on, the next time a document is opened in the app, the tile
cache is emptied (and the toggle is reset off). This is mostly for
potential problem solving, and might be removd later.
Various refactoring to support the new functionality.
Change-Id: Ie2ebf032acb9e43bb1c6f7ae4d0c449ae66eaa05
2018-12-17 14:18:49 -06:00
|
|
|
|
2019-10-11 04:18:27 -05:00
|
|
|
#define LIBO_INTERNAL_ONLY
|
|
|
|
#include <comphelper/lok.hxx>
|
|
|
|
#include <i18nlangtag/languagetag.hxx>
|
|
|
|
|
|
|
|
#import "ios.h"
|
2018-09-11 01:30:55 -05:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "DocumentBrowserViewController.h"
|
2020-04-03 16:04:20 -05:00
|
|
|
#import "CODocument.h"
|
2018-09-11 01:30:55 -05:00
|
|
|
#import "DocumentViewController.h"
|
|
|
|
|
2018-09-13 11:16:00 -05:00
|
|
|
#import "FakeSocket.hpp"
|
2020-02-15 13:32:57 -06:00
|
|
|
#import "Kit.hpp"
|
2018-09-13 11:16:00 -05:00
|
|
|
#import "Log.hpp"
|
2021-11-18 06:08:14 -06:00
|
|
|
#import "COOLWSD.hpp"
|
2020-07-02 08:57:22 -05:00
|
|
|
#import "SetupKitEnvironment.hpp"
|
2018-09-13 11:16:00 -05:00
|
|
|
#import "Util.hpp"
|
|
|
|
|
2023-03-11 16:40:07 -06:00
|
|
|
#import <common/LangUtil.hpp>
|
|
|
|
|
2018-12-10 11:46:52 -06:00
|
|
|
NSString *app_locale;
|
2023-03-11 16:40:07 -06:00
|
|
|
NSString *app_text_direction;
|
Add a way to have templates specific to a customer deployment
Add two settings: One setting "Template list URL" is a string that
should either be empty (the typical case for a random user of the
app), or contain a https: URL. If this setting is empty, only the
templates bundled in the app are provided.
If the "Template list URL" is non-empty, it should be a https: URL
pointing to a text file (or dynamically generated text resource). That
file is downloaded and read when the app starts. Each line in the file
should either be a comment (starting with a hash '#'), or a https: URL
pointing to a template document, that is of type .ott, .ots, or .otp.
That document is downloaded if it hasn't been downloaded already, or
if its time stamp is newer than that of the already downloaded copy.
Also a thumbnail image for the template, formed by appending ".png" to
its URL, is downloaded, if available.
Any previously downloaded templates that aren't mentioned in the list
file are removed.
The intent is that in some managed mass deployment environment, the
mobile device management software would set up this setting, so that
the end-user devices would see the same templates.
Obviously, this URL does not have to point to a static file on a web
server, but could point to some dynamically generated resource on a
web server, that enumerates the templates available on the server and
returns their URLs as a text document.
Another setting is "Empty tile cache next time". This is a toggle. If
toggled on, the next time a document is opened in the app, the tile
cache is emptied (and the toggle is reset off). This is mostly for
potential problem solving, and might be removd later.
Various refactoring to support the new functionality.
Change-Id: Ie2ebf032acb9e43bb1c6f7ae4d0c449ae66eaa05
2018-12-17 14:18:49 -06:00
|
|
|
|
2018-11-09 08:29:24 -06:00
|
|
|
@implementation AppDelegate
|
2018-09-11 01:30:55 -05:00
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2021-11-18 06:08:14 -06:00
|
|
|
auto trace = std::getenv("COOL_LOGLEVEL");
|
2018-11-06 09:19:46 -06:00
|
|
|
if (!trace)
|
|
|
|
trace = strdup("warning");
|
|
|
|
|
2020-10-20 07:00:03 -05:00
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
|
|
|
|
setupKitEnvironment("notebookbar");
|
|
|
|
else
|
|
|
|
setupKitEnvironment("");
|
2019-04-24 05:24:53 -05:00
|
|
|
|
Add a way to have templates specific to a customer deployment
Add two settings: One setting "Template list URL" is a string that
should either be empty (the typical case for a random user of the
app), or contain a https: URL. If this setting is empty, only the
templates bundled in the app are provided.
If the "Template list URL" is non-empty, it should be a https: URL
pointing to a text file (or dynamically generated text resource). That
file is downloaded and read when the app starts. Each line in the file
should either be a comment (starting with a hash '#'), or a https: URL
pointing to a template document, that is of type .ott, .ots, or .otp.
That document is downloaded if it hasn't been downloaded already, or
if its time stamp is newer than that of the already downloaded copy.
Also a thumbnail image for the template, formed by appending ".png" to
its URL, is downloaded, if available.
Any previously downloaded templates that aren't mentioned in the list
file are removed.
The intent is that in some managed mass deployment environment, the
mobile device management software would set up this setting, so that
the end-user devices would see the same templates.
Obviously, this URL does not have to point to a static file on a web
server, but could point to some dynamically generated resource on a
web server, that enumerates the templates available on the server and
returns their URLs as a text document.
Another setting is "Empty tile cache next time". This is a toggle. If
toggled on, the next time a document is opened in the app, the tile
cache is emptied (and the toggle is reset off). This is mostly for
potential problem solving, and might be removd later.
Various refactoring to support the new functionality.
Change-Id: Ie2ebf032acb9e43bb1c6f7ae4d0c449ae66eaa05
2018-12-17 14:18:49 -06:00
|
|
|
Log::initialize("Mobile", trace, false, false, {});
|
|
|
|
Util::setThreadName("main");
|
|
|
|
|
2020-07-23 11:11:29 -05:00
|
|
|
// Clear the cache directory if it is for another build of the app
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *userDirectory = [paths objectAtIndex:0];
|
|
|
|
NSString *cacheDirectory = [userDirectory stringByAppendingPathComponent:@"cache"];
|
|
|
|
|
|
|
|
NSString *coreVersionHashFile = [cacheDirectory stringByAppendingPathComponent:@"core_version_hash"];
|
2021-11-18 06:08:14 -06:00
|
|
|
NSString *coolwsdVersionHashFile = [cacheDirectory stringByAppendingPathComponent:@"coolwsd_version_hash"];
|
2020-07-23 11:11:29 -05:00
|
|
|
|
|
|
|
NSData *oldCoreVersionHash = [NSData dataWithContentsOfFile:coreVersionHashFile];
|
2021-11-18 06:08:14 -06:00
|
|
|
NSData *oldCoolwsdVersionHash = [NSData dataWithContentsOfFile:coolwsdVersionHashFile];
|
2020-07-23 11:11:29 -05:00
|
|
|
|
|
|
|
NSData *coreVersionHash = [NSData dataWithBytes:CORE_VERSION_HASH length:strlen(CORE_VERSION_HASH)];
|
2021-11-18 06:08:14 -06:00
|
|
|
NSData *coolwsdVersionHash = [NSData dataWithBytes:COOLWSD_VERSION_HASH length:strlen(COOLWSD_VERSION_HASH)];
|
2020-07-23 11:11:29 -05:00
|
|
|
|
|
|
|
if (oldCoreVersionHash == nil
|
|
|
|
|| ![oldCoreVersionHash isEqualToData:coreVersionHash]
|
2021-11-18 06:08:14 -06:00
|
|
|
|| oldCoolwsdVersionHash == nil
|
|
|
|
|| ![oldCoolwsdVersionHash isEqualToData:coolwsdVersionHash]) {
|
2020-07-23 11:11:29 -05:00
|
|
|
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:cacheDirectory error:nil];
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] createDirectoryAtPath:cacheDirectory withIntermediateDirectories:NO attributes:nil error:nil])
|
|
|
|
NSLog(@"Could not create %@", cacheDirectory);
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] createFileAtPath:coreVersionHashFile contents:coreVersionHash attributes:nil])
|
|
|
|
NSLog(@"Could not create %@", coreVersionHashFile);
|
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
if (![[NSFileManager defaultManager] createFileAtPath:coolwsdVersionHashFile contents:coolwsdVersionHash attributes:nil])
|
|
|
|
NSLog(@"Could not create %@", coolwsdVersionHashFile);
|
2020-07-23 11:11:29 -05:00
|
|
|
}
|
|
|
|
|
2018-12-10 11:46:52 -06:00
|
|
|
// Having LANG in the environment is expected to happen only when debugging from Xcode. When
|
|
|
|
// testing some language one doesn't know it might be risky to simply set one's iPad to that
|
|
|
|
// language, as it might be hard to find the way to set it back to a known language.
|
|
|
|
|
|
|
|
char *lang = std::getenv("LANG");
|
2023-05-15 13:05:19 -05:00
|
|
|
// Fix assert failure when running "My Mac (Designed for iPad)" in Xcode
|
|
|
|
// LANG values such as en_US.UTF-8 trigger an assert in the LibreOffice
|
|
|
|
// code so replace all "_" characters with "-" characters.
|
2023-09-08 18:03:54 -05:00
|
|
|
if (lang != nullptr) {
|
2023-05-15 13:05:19 -05:00
|
|
|
app_locale = [[NSString stringWithUTF8String:lang] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
|
2023-09-08 18:03:54 -05:00
|
|
|
// Eliminate invalid language tag exceptions in JavaScript by
|
|
|
|
// trimming any text encoding from LANG
|
|
|
|
NSRange range = [app_locale rangeOfString:@"."];
|
|
|
|
if (range.location != NSNotFound)
|
|
|
|
app_locale = [app_locale substringToIndex:range.location];
|
|
|
|
}
|
|
|
|
if (!app_locale || ![app_locale length])
|
2018-12-10 11:46:52 -06:00
|
|
|
app_locale = [[NSLocale preferredLanguages] firstObject];
|
|
|
|
|
2023-03-11 16:40:07 -06:00
|
|
|
if (LangUtil::isRtlLanguage(std::string([app_locale UTF8String])))
|
|
|
|
app_text_direction = @"rtl";
|
|
|
|
else
|
|
|
|
app_text_direction = @"";
|
|
|
|
|
2019-10-11 04:18:27 -05:00
|
|
|
lo_kit = lok_init_2(nullptr, nullptr);
|
|
|
|
|
|
|
|
comphelper::LibreOfficeKit::setLanguageTag(LanguageTag(OUString::fromUtf8(OString([app_locale UTF8String])), true));
|
|
|
|
|
2020-04-24 02:46:54 -05:00
|
|
|
// This fires off a thread running the LOKit runLoop()
|
|
|
|
runKitLoopInAThread();
|
|
|
|
|
Add a way to have templates specific to a customer deployment
Add two settings: One setting "Template list URL" is a string that
should either be empty (the typical case for a random user of the
app), or contain a https: URL. If this setting is empty, only the
templates bundled in the app are provided.
If the "Template list URL" is non-empty, it should be a https: URL
pointing to a text file (or dynamically generated text resource). That
file is downloaded and read when the app starts. Each line in the file
should either be a comment (starting with a hash '#'), or a https: URL
pointing to a template document, that is of type .ott, .ots, or .otp.
That document is downloaded if it hasn't been downloaded already, or
if its time stamp is newer than that of the already downloaded copy.
Also a thumbnail image for the template, formed by appending ".png" to
its URL, is downloaded, if available.
Any previously downloaded templates that aren't mentioned in the list
file are removed.
The intent is that in some managed mass deployment environment, the
mobile device management software would set up this setting, so that
the end-user devices would see the same templates.
Obviously, this URL does not have to point to a static file on a web
server, but could point to some dynamically generated resource on a
web server, that enumerates the templates available on the server and
returns their URLs as a text document.
Another setting is "Empty tile cache next time". This is a toggle. If
toggled on, the next time a document is opened in the app, the tile
cache is emptied (and the toggle is reset off). This is mostly for
potential problem solving, and might be removd later.
Various refactoring to support the new functionality.
Change-Id: Ie2ebf032acb9e43bb1c6f7ae4d0c449ae66eaa05
2018-12-17 14:18:49 -06:00
|
|
|
// Look for the setting indicating the URL for a file containing a list of URLs for template
|
|
|
|
// documents to download. If set, start a task to download it, and then to download the listed
|
|
|
|
// templates.
|
2019-05-30 03:29:28 -05:00
|
|
|
|
|
|
|
// First check managed configuration, if present
|
|
|
|
NSDictionary *managedConfig = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"com.apple.configuration.managed"];
|
Add a way to have templates specific to a customer deployment
Add two settings: One setting "Template list URL" is a string that
should either be empty (the typical case for a random user of the
app), or contain a https: URL. If this setting is empty, only the
templates bundled in the app are provided.
If the "Template list URL" is non-empty, it should be a https: URL
pointing to a text file (or dynamically generated text resource). That
file is downloaded and read when the app starts. Each line in the file
should either be a comment (starting with a hash '#'), or a https: URL
pointing to a template document, that is of type .ott, .ots, or .otp.
That document is downloaded if it hasn't been downloaded already, or
if its time stamp is newer than that of the already downloaded copy.
Also a thumbnail image for the template, formed by appending ".png" to
its URL, is downloaded, if available.
Any previously downloaded templates that aren't mentioned in the list
file are removed.
The intent is that in some managed mass deployment environment, the
mobile device management software would set up this setting, so that
the end-user devices would see the same templates.
Obviously, this URL does not have to point to a static file on a web
server, but could point to some dynamically generated resource on a
web server, that enumerates the templates available on the server and
returns their URLs as a text document.
Another setting is "Empty tile cache next time". This is a toggle. If
toggled on, the next time a document is opened in the app, the tile
cache is emptied (and the toggle is reset off). This is mostly for
potential problem solving, and might be removd later.
Various refactoring to support the new functionality.
Change-Id: Ie2ebf032acb9e43bb1c6f7ae4d0c449ae66eaa05
2018-12-17 14:18:49 -06:00
|
|
|
|
2023-02-23 10:46:54 -06:00
|
|
|
// Look for managed configuration setting of the user name.
|
2021-04-07 07:56:04 -05:00
|
|
|
|
|
|
|
if (managedConfig != nil) {
|
|
|
|
NSString *userName = managedConfig[@"userName"];
|
|
|
|
if (userName != nil && [userName isKindOfClass:[NSString class]])
|
|
|
|
user_name = [userName UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_name == nullptr)
|
|
|
|
user_name = [[[NSUserDefaults standardUserDefaults] stringForKey:@"userName"] UTF8String];
|
|
|
|
|
2021-09-07 05:08:25 -05:00
|
|
|
// Remove any leftover allegedly temporary folders with copies of documents left behind from
|
|
|
|
// previous instances of the app that were killed while editing, various random files that for
|
|
|
|
// instance NSS seems to love to create, etc, by removing the whole tmp folder.
|
|
|
|
NSURL *tempFolderURL = [[NSFileManager defaultManager] temporaryDirectory];
|
|
|
|
if (![[NSFileManager defaultManager] removeItemAtURL:tempFolderURL error:nil]) {
|
|
|
|
NSLog(@"Could not remove tmp folder %@", tempFolderURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] createDirectoryAtURL:tempFolderURL withIntermediateDirectories:YES attributes:nil error:nil]) {
|
2021-09-07 07:05:29 -05:00
|
|
|
NSLog(@"Could not create tmp folder %@", tempFolderURL);
|
2021-09-07 05:08:25 -05:00
|
|
|
}
|
|
|
|
|
2018-09-13 11:16:00 -05:00
|
|
|
fakeSocketSetLoggingCallback([](const std::string& line)
|
|
|
|
{
|
2020-07-14 08:46:40 -05:00
|
|
|
LOG_INF_NOFILE(line);
|
2018-09-13 11:16:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^{
|
|
|
|
char *argv[2];
|
|
|
|
argv[0] = strdup([[NSBundle mainBundle].executablePath UTF8String]);
|
|
|
|
argv[1] = nullptr;
|
2018-10-15 16:01:04 -05:00
|
|
|
Util::setThreadName("app");
|
2021-11-18 06:08:14 -06:00
|
|
|
auto coolwsd = new COOLWSD();
|
|
|
|
coolwsd->run(1, argv);
|
2020-04-24 02:46:54 -05:00
|
|
|
|
|
|
|
// Should never return
|
|
|
|
assert(false);
|
|
|
|
NSLog(@"lolwsd->run() unexpectedly returned");
|
|
|
|
std::abort();
|
2018-09-13 11:16:00 -05:00
|
|
|
});
|
2018-09-11 01:30:55 -05:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:46:54 -05:00
|
|
|
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
|
|
|
|
return [UISceneConfiguration configurationWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
|
|
|
|
}
|
|
|
|
|
2018-09-11 01:30:55 -05:00
|
|
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
2019-10-09 06:21:48 -05:00
|
|
|
// tdf#126974 We don't want any global object destructors to be called, the code
|
|
|
|
// is not prepared for that.
|
|
|
|
std::_Exit(1);
|
2018-09-11 01:30:55 -05:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:46:54 -05:00
|
|
|
// This method is called when you use the "Share > Open in Collabora Office" functionality in the
|
|
|
|
// Files app. Possibly also in other use cases.
|
2018-09-11 01:30:55 -05:00
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)inputURL options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
|
|
|
|
// Ensure the URL is a file URL
|
|
|
|
if (!inputURL.isFileURL) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
if (error) {
|
2018-11-06 09:39:38 -06:00
|
|
|
LOG_ERR("Failed to reveal the document at URL " << [[inputURL description] UTF8String] << " with error: " << [[error description] UTF8String]);
|
2018-09-11 01:30:55 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Present the Document View Controller for the revealed URL
|
|
|
|
[documentBrowserViewController presentDocumentAtURL:revealedDocumentURL];
|
|
|
|
}];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// vim:set shiftwidth=4 softtabstop=4 expandtab:
|