Files
mobile/ios/StandardNotes/AppDelegate.m
Mo ce5e89ac1d feat/offline-editors (#517)
* feat: offline editors (#392)

* feat: add react-native-zip-archive dependency

* feat: download and extract offline editors

* feat: use offline editor path as webview source

* fix: change function name

* fix: move deactivate editor to compose unmount

* fix: add origin whitelist

* fix: add read access url

* fix: increase load end timeout to remove theme load flicker

* fix: set online url on getOfflineEditor error

* fix: set editor width and scale

* fix: add timeout to remove download message flicker

* fix: deactivate component when switching editors

* fix: use online url if process is terminated

* fix: check if component mounted before state update

* fix: decrease loading editor message timeout

* feat: remove editor loading message on ThemesActivated action (#415)

* chore(version-snjs): 2.0.76

* feat: remove loading editor message on ActivateThemes action

* fix: offline editors issues (#416)

* fix: read main from package.json

* fix: reload editor when switching after editor load failure

* fix: check offlineOnly before setting online url

* fix: prevent editor download if another download is in progress

* fix: live item deinit called more than once (#423)

* feat: check for and download editor updates

* fix: access denied webview errors on Android 10

* feat: serve offline editors from local static server (#472)

* feat: serve offline editors from local static server

* fix: use document directory for both OS

* fix: download error handling

* refactor: use forked repo for react-native-static-server

* chore: add logs and temporarily enable them for dev

* feat(wip): integrity verification

* refactor: component manager handling downloads

* feat(wip): functional component viewer

* feat: handle local themes

* chore: disable logging

* improve: use existing function

* fix: root url first load

* fix: types

* chore: cleanup
2021-12-30 15:25:39 -06:00

145 lines
5.7 KiB
Objective-C

#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Bugsnag/Bugsnag.h>
#import <WebKit/WKWebsiteDataStore.h>
#import <TrustKit/TrustKit.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *bugsnagOptOut = [defaults objectForKey:@"bugsnagoptout"] ?: @"true";
BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
config.enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeNavigation | BSGEnabledBreadcrumbTypeLog
| BSGEnabledBreadcrumbTypeUser | BSGEnabledBreadcrumbTypeState | BSGEnabledBreadcrumbTypeNavigation | BSGEnabledBreadcrumbTypeProcess;
if (![bugsnagOptOut isEqualToString:@"true"]) {
[Bugsnag startWithConfiguration:config];
}
[self configurePinning];
[self disableUrlCache];
[self clearWebEditorCache];
NSString *CFBundleIdentifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
NSDictionary * initialProperties = @{@"env" : [CFBundleIdentifier isEqualToString:@"com.standardnotes.standardnotes.dev"] ? @"dev" : @"prod", @"bugsnagOptOut": [bugsnagOptOut isEqualToString:@"true"] ? @YES : @NO};
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"StandardNotes"
initialProperties:initialProperties];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
if (@available(iOS 13.0, *)) {
[rootView setBackgroundColor:[UIColor systemBackgroundColor]];
} else {
[rootView setBackgroundColor:[UIColor blackColor]];
}
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)disableUrlCache {
// Disable NSURLCache for general network requests. Caches are not protected by NSFileProtectionComplete.
// Disabling, or implementing a custom subclass are only two solutions. https://stackoverflow.com/questions/27933387/nsurlcache-and-data-protection
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
}
- (void)clearWebEditorCache {
// Clear web editor cache after every app update
NSString *lastVersionClearKey = @"lastVersionClearKey";
NSString *lastVersionClear = [[NSUserDefaults standardUserDefaults] objectForKey:lastVersionClearKey];
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
if(![currentVersion isEqualToString:lastVersionClear]) {
// UIWebView
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// WebKit
NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{}];
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:lastVersionClearKey];
}
}
- (void)configurePinning {
if(@available(iOS 10, *)) {
NSDictionary *trustKitConfig =
@{
kTSKSwizzleNetworkDelegates: @YES,
// The list of domains we want to pin and their configuration
kTSKPinnedDomains: @{
@"standardnotes.org" : @{
kTSKIncludeSubdomains:@YES,
kTSKEnforcePinning:@YES,
// Send reports for pin validation failures so we can track them
kTSKReportUris: @[@"https://standard.report-uri.com/r/d/hpkp/reportOnly"],
// The pinned public keys' Subject Public Key Info hashes
kTSKPublicKeyHashes : @[
@"Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=",
@"C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=",
@"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=",
@"sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=",
@"++MBgDH5WGvL9Bcn5Be30cRcL0f5O+NyoXuWtQdX1aI=",
@"f0KW/FtqTjs108NpYj42SrGvOB2PpxIVM8nWxjPqJGE=",
@"NqvDJlas/GRcYbcWE8S/IceH9cq77kg0jVhZeAPXq8k=",
@"9+ze1cZgR9KO1kZrVDxA4HQ6voHRCSVNz4RdTCx4U8U="
],
},
@"standardnotes.com" : @{
kTSKIncludeSubdomains:@YES,
kTSKEnforcePinning:@YES,
// Send reports for pin validation failures so we can track them
kTSKReportUris: @[@"https://standard.report-uri.com/r/d/hpkp/reportOnly"],
// The pinned public keys' Subject Public Key Info hashes
kTSKPublicKeyHashes : @[
@"Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=",
@"C5+lpZ7tcVwmwQIMcRtPbsQtWLABXhQzejna0wHFr8M=",
@"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=",
@"sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=",
@"++MBgDH5WGvL9Bcn5Be30cRcL0f5O+NyoXuWtQdX1aI=",
@"f0KW/FtqTjs108NpYj42SrGvOB2PpxIVM8nWxjPqJGE=",
@"NqvDJlas/GRcYbcWE8S/IceH9cq77kg0jVhZeAPXq8k=",
@"9+ze1cZgR9KO1kZrVDxA4HQ6voHRCSVNz4RdTCx4U8U="
],
},
}
};
[TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
}
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end