1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 10:27:46 +01:00
Telegram/Watch/Extension/TGExtensionDelegate.m

117 lines
3.0 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
#import "TGExtensionDelegate.h"
#import "TGFileCache.h"
#import "TGBridgeClient.h"
2016-02-25 01:03:51 +01:00
#import "TGDateUtils.h"
#import "TGNeoChatsController.h"
@interface TGExtensionDelegate ()
{
NSString *_cachedContentSize;
TGContentSizeCategory _sizeCategory;
}
@end
2015-10-01 18:19:52 +02:00
@implementation TGExtensionDelegate
- (instancetype)init
{
self = [super init];
if (self != nil)
{
TGLog(@"Extension initialization start");
[TGBridgeClient instance];
_audioCache = [[TGFileCache alloc] initWithName:@"audio" useMemoryCache:false useApplicationGroup:true];
_audioCache.defaultFileExtension = @"m4a";
_imageCache = [[TGFileCache alloc] initWithName:@"images" useMemoryCache:true];
}
return self;
}
- (TGNeoChatsController *)chatsController
{
return (TGNeoChatsController *)[WKExtension sharedExtension].rootInterfaceController;
}
- (void)applicationDidBecomeActive
{
[[TGBridgeClient instance] handleDidBecomeActive];
}
- (void)applicationWillResignActive
{
[[TGBridgeClient instance] handleWillResignActive];
}
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo
{
}
- (void)didReceiveLocalNotification:(UILocalNotification *)notification
{
}
2016-02-25 01:03:51 +01:00
- (void)setCustomLocalizationFile:(NSURL *)fileUrl
{
if (fileUrl == nil)
TGResetLocalization();
else
TGSetLocalizationFromFile(fileUrl);
[TGDateUtils reset];
[[self chatsController] resetLocalization];
}
- (TGContentSizeCategory)contentSizeCategory
{
NSString *contentSize = [WKInterfaceDevice currentDevice].preferredContentSizeCategory;
if (![_cachedContentSize isEqualToString:contentSize])
{
_cachedContentSize = contentSize;
_sizeCategory = [TGExtensionDelegate contentSizeCategoryForString:contentSize];
}
return _sizeCategory;
}
+ (TGContentSizeCategory)contentSizeCategoryForString:(NSString *)string
{
if ([string isEqualToString:@"UICTContentSizeCategoryXS"])
return TGContentSizeCategoryXS;
else if ([string isEqualToString:@"UICTContentSizeCategoryS"])
return TGContentSizeCategoryS;
else if ([string isEqualToString:@"UICTContentSizeCategoryM"])
return TGContentSizeCategoryM;
else if ([string isEqualToString:@"UICTContentSizeCategoryL"])
return TGContentSizeCategoryL;
else if ([string isEqualToString:@"UICTContentSizeCategoryXL"])
return TGContentSizeCategoryXL;
else if ([string isEqualToString:@"UICTContentSizeCategoryXXL"])
return TGContentSizeCategoryXXL;
else if ([string isEqualToString:@"UICTContentSizeCategoryXXXL"])
return TGContentSizeCategoryXXXL;
return TGContentSizeCategoryL;
}
+ (NSString *)documentsPath
{
static dispatch_once_t onceToken;
static NSString *path;
dispatch_once(&onceToken, ^
{
path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0];
});
return path;
}
2015-10-01 18:19:52 +02:00
+ (instancetype)instance
{
return (TGExtensionDelegate *)[[WKExtension sharedExtension] delegate];
}
@end