2018-09-11 01:30:55 -05:00
|
|
|
// -*- Mode: objc; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*-
|
|
|
|
//
|
|
|
|
// 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/.
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#import "LOOLWSD.hpp"
|
2020-07-02 08:57:22 -05:00
|
|
|
#import "SetupKitEnvironment.hpp"
|
2018-09-13 11:16:00 -05:00
|
|
|
#import "Util.hpp"
|
|
|
|
|
2018-12-10 11:46:52 -06:00
|
|
|
NSString *app_locale;
|
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
|
|
|
|
|
|
|
static void download(NSURL *source, NSURL *destination) {
|
|
|
|
[[[NSURLSession sharedSession] downloadTaskWithURL:source
|
|
|
|
completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
|
2018-12-19 05:36:44 -06:00
|
|
|
if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
|
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
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *resultingItem = nil;
|
|
|
|
if ([[NSFileManager defaultManager] replaceItemAtURL:destination
|
|
|
|
withItemAtURL:location
|
|
|
|
backupItemName:nil
|
|
|
|
options:NSFileManagerItemReplacementUsingNewMetadataOnly
|
|
|
|
resultingItemURL:&resultingItem
|
|
|
|
error:&error]) {
|
|
|
|
LOG_INF("Downloaded " <<
|
|
|
|
[[source absoluteString] UTF8String] <<
|
|
|
|
" as " << [[destination absoluteString] UTF8String]);
|
|
|
|
} else {
|
|
|
|
LOG_ERR("Failed to replace " <<
|
|
|
|
[[destination absoluteString] UTF8String] <<
|
|
|
|
" with " << [[location absoluteString] UTF8String] <<
|
|
|
|
": " << [[error description] UTF8String]);
|
|
|
|
}
|
2019-04-26 03:28:39 -05:00
|
|
|
} else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[source absoluteString] UTF8String] <<
|
|
|
|
": response code " << [(NSHTTPURLResponse*)response statusCode]);
|
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
|
|
|
} else if (error != nil) {
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[source absoluteString] UTF8String] <<
|
|
|
|
": " << [[error description] UTF8String]);
|
|
|
|
} else {
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[source absoluteString] UTF8String]);
|
|
|
|
}
|
|
|
|
}] resume];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void downloadTemplate(NSURL *source, NSURL *destination) {
|
|
|
|
download(source, destination);
|
|
|
|
// Download also a thumbnail
|
|
|
|
download([NSURL URLWithString:[[source absoluteString] stringByAppendingString:@".png"]],
|
|
|
|
[NSURL URLWithString:[[destination absoluteString] stringByAppendingString:@".png"]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void updateTemplates(NSData *data, NSURLResponse *response)
|
|
|
|
{
|
|
|
|
static NSString *downloadedTemplates = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/downloadedTemplates/"];
|
|
|
|
|
|
|
|
// The data downloaded is a template list file, and should have one URL per line, corresponding
|
|
|
|
// to a template document. For each URL, we check whether we have the corresponding template
|
|
|
|
// document, and whether it is the same version (timestamp is older or the same). If not, we
|
|
|
|
// download the new version. Finally we remove any earlier downloaded templates not mentioned in the list
|
|
|
|
// file.
|
|
|
|
|
|
|
|
NSMutableSet<NSString *> *urlHashes = [NSMutableSet setWithCapacity:10];
|
|
|
|
|
|
|
|
const char *p = static_cast<const char*>([data bytes]);
|
|
|
|
const char *endOfData = p + [data length];
|
|
|
|
while (p < endOfData) {
|
|
|
|
const char *endOfLine = static_cast<const char*>(std::memchr(p, '\n', [data length]));
|
|
|
|
if (endOfLine == NULL)
|
|
|
|
endOfLine = endOfData;
|
|
|
|
|
|
|
|
// Allow comment lines staring with a hash sign.
|
|
|
|
if (*p != '#') {
|
|
|
|
const int length = endOfLine - p;
|
2019-04-26 02:46:12 -05:00
|
|
|
// Allow empty lines
|
|
|
|
if (length > 0) {
|
|
|
|
std::vector<char> buf(length+1);
|
|
|
|
std::memcpy(buf.data(), p, length);
|
|
|
|
buf[length] = 0;
|
|
|
|
|
|
|
|
NSString *line = [NSString stringWithUTF8String:buf.data()];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:line];
|
2019-04-26 03:44:28 -05:00
|
|
|
if (url == nil)
|
|
|
|
LOG_ERR("Invalid URL in template file: " << [line UTF8String]);
|
|
|
|
else {
|
|
|
|
NSString *baseName = [url lastPathComponent];
|
|
|
|
|
|
|
|
NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0];
|
|
|
|
[urlHashes addObject:hash];
|
|
|
|
|
|
|
|
NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash];
|
|
|
|
|
|
|
|
NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]];
|
|
|
|
|
|
|
|
// If we have that template, check whether it is up-to-date
|
|
|
|
BOOL isDirectory;
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] &&
|
|
|
|
isDirectory) {
|
|
|
|
NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy];
|
|
|
|
[req setHTTPMethod:@"HEAD"];
|
|
|
|
[[[NSURLSession sharedSession] dataTaskWithRequest:req
|
|
|
|
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
|
|
if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
|
|
|
|
NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"];
|
|
|
|
NSDateFormatter *df = [[NSDateFormatter alloc] init];
|
|
|
|
df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
|
|
|
|
NSDate *templateDate = [df dateFromString:lastModified];
|
|
|
|
|
|
|
|
NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate];
|
|
|
|
|
2019-04-26 04:01:25 -05:00
|
|
|
LOG_INF("Template at " << [[url absoluteString] UTF8String] << " timestamp: "
|
|
|
|
<< [[templateDate descriptionWithLocale:nil] UTF8String] << ", cached template timestamp: "
|
|
|
|
<< [[cachedTemplateDate descriptionWithLocale:nil] UTF8String]);
|
|
|
|
|
2019-04-26 03:44:28 -05:00
|
|
|
if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) {
|
|
|
|
downloadTemplate(url, fileForTemplate);
|
|
|
|
}
|
|
|
|
} else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
|
|
LOG_ERR("Failed to get HEAD of " <<
|
|
|
|
[[url absoluteString] UTF8String] <<
|
|
|
|
": response code " << [(NSHTTPURLResponse*)response statusCode]);
|
|
|
|
} else if (error != nil) {
|
|
|
|
LOG_ERR("Failed to get HEAD of " <<
|
|
|
|
[[url absoluteString] UTF8String] <<
|
|
|
|
": " << [[error description] UTF8String]);
|
|
|
|
} else {
|
|
|
|
LOG_ERR("Failed to get HEAD of " <<
|
|
|
|
[[url absoluteString] UTF8String]);
|
2019-04-26 02:46:12 -05:00
|
|
|
}
|
2019-04-26 03:44:28 -05:00
|
|
|
}] resume];
|
|
|
|
} else {
|
|
|
|
// Else download it.
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil];
|
|
|
|
downloadTemplate(url, fileForTemplate);
|
|
|
|
}
|
2019-04-26 02:46:12 -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
|
|
|
}
|
|
|
|
}
|
|
|
|
if (endOfLine < endOfData)
|
|
|
|
p = endOfLine + 1;
|
|
|
|
else
|
|
|
|
p = endOfData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove templates that are no longer mentioned in the list file.
|
|
|
|
NSArray<NSString *> *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:downloadedTemplates error:nil];
|
|
|
|
for (int i = 0; i < [dirContents count]; i++) {
|
|
|
|
if (![urlHashes containsObject:[dirContents objectAtIndex:i]]) {
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[downloadedTemplates stringByAppendingString:[@"/" stringByAppendingString:[dirContents objectAtIndex:i]]]
|
|
|
|
error:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-11 01:30:55 -05: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 {
|
2018-11-06 09:19:46 -06:00
|
|
|
auto trace = std::getenv("LOOL_LOGLEVEL");
|
|
|
|
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"];
|
|
|
|
NSString *loolwsdVersionHashFile = [cacheDirectory stringByAppendingPathComponent:@"loolwsd_version_hash"];
|
|
|
|
|
|
|
|
NSData *oldCoreVersionHash = [NSData dataWithContentsOfFile:coreVersionHashFile];
|
|
|
|
NSData *oldLoolwsdVersionHash = [NSData dataWithContentsOfFile:loolwsdVersionHashFile];
|
|
|
|
|
|
|
|
NSData *coreVersionHash = [NSData dataWithBytes:CORE_VERSION_HASH length:strlen(CORE_VERSION_HASH)];
|
|
|
|
NSData *loolwsdVersionHash = [NSData dataWithBytes:LOOLWSD_VERSION_HASH length:strlen(LOOLWSD_VERSION_HASH)];
|
|
|
|
|
|
|
|
if (oldCoreVersionHash == nil
|
|
|
|
|| ![oldCoreVersionHash isEqualToData:coreVersionHash]
|
|
|
|
|| oldLoolwsdVersionHash == nil
|
|
|
|
|| ![oldLoolwsdVersionHash isEqualToData:loolwsdVersionHash]) {
|
|
|
|
|
|
|
|
[[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);
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] createFileAtPath:loolwsdVersionHashFile contents:loolwsdVersionHash attributes:nil])
|
|
|
|
NSLog(@"Could not create %@", loolwsdVersionHashFile);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
if (lang != nullptr)
|
|
|
|
app_locale = [NSString stringWithUTF8String:lang];
|
|
|
|
else
|
|
|
|
app_locale = [[NSLocale preferredLanguages] firstObject];
|
|
|
|
|
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
|
|
|
|
|
|
|
NSString *templateListURL = nil;
|
|
|
|
|
|
|
|
// First check managed configuration, if present
|
|
|
|
NSDictionary *managedConfig = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"com.apple.configuration.managed"];
|
|
|
|
if (managedConfig != nil) {
|
|
|
|
templateListURL = managedConfig[@"templateListURL"];
|
|
|
|
if (templateListURL != nil && ![templateListURL isKindOfClass:[NSString class]])
|
|
|
|
templateListURL = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (templateListURL == nil)
|
|
|
|
templateListURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"templateListURL"];
|
|
|
|
|
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
|
|
|
if (templateListURL != nil) {
|
|
|
|
NSURL *url = [NSURL URLWithString:templateListURL];
|
|
|
|
if (url != nil) {
|
|
|
|
[[[NSURLSession sharedSession] dataTaskWithURL:url
|
|
|
|
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
2018-12-19 05:36:44 -06:00
|
|
|
if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200)
|
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
|
|
|
updateTemplates(data, response);
|
2019-04-26 03:28:39 -05:00
|
|
|
else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]])
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[url absoluteString] UTF8String] <<
|
|
|
|
": response code " << [(NSHTTPURLResponse*)response statusCode]);
|
|
|
|
else if (error != nil)
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[url absoluteString] UTF8String] <<
|
|
|
|
": " << [[error description] UTF8String]);
|
|
|
|
else
|
|
|
|
LOG_ERR("Failed to download " <<
|
|
|
|
[[url absoluteString] UTF8String]);
|
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
|
|
|
}] resume];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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");
|
2020-04-24 02:46:54 -05:00
|
|
|
auto loolwsd = new LOOLWSD();
|
|
|
|
loolwsd->run(1, argv);
|
|
|
|
|
|
|
|
// 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:
|