-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAVCWidgetServer.m
92 lines (73 loc) · 2.22 KB
/
AVCWidgetServer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by Kritanta on 1/12/21.
//
#import <objc/runtime.h>
#import "AVCWidgetServer.h"
#import "Hooks/SBHWidgetStackViewController.h"
@implementation AVCWidgetServer
{
@private
NSUserDefaults *_store;
NSMutableDictionary *_activeWidgets;
NSMutableArray *_updateQueue;
}
static NSString *desc;
@synthesize store = _store;
@synthesize activeWidgets = _activeWidgets;
@synthesize updateQueue = _updateQueue;
+ (instancetype)sharedInstance
{
static id _sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
{
_sharedInstance = [[self alloc] initWithDomain:@"me.kritanta.avacado"];
});
return _sharedInstance;
}
- (instancetype)initWithDomain:(NSString *)domain
{
self = [super init];
if (self)
{
desc = @"";
_activeWidgets = [NSMutableDictionary new];
_updateQueue = [NSMutableArray new];
_store = [[NSUserDefaults alloc] initWithSuiteName:domain];
}
return self;
}
- (AVCWidget *)widgetForSpringboardWidget:(SBHWidget *)widget
{
// Springboard generates a unique ID for each widget instance
// We use this to keep duplicate widgets seperated.
// it works well.
NSString *uid = widget.uniqueIdentifier;
if (!_activeWidgets[uid])
_activeWidgets[uid] = [self buildWidgetForIdentifier:widget.extensionBundleIdentifier];
return _activeWidgets[uid];
}
- (AVCWidget *)buildWidgetForIdentifier:(NSString *)identifier
{
NSString *className = [_store stringForKey:identifier];
if (className)
{
return [NSClassFromString(className) build];
}
return nil;
}
- (void)registerWidget:(AVCWidget *)widget forUpdatesEvery:(float)seconds
{
// I am going to eventually add a much smarter update timer here
// for now, this method will use some less efficient code.
[NSTimer scheduledTimerWithTimeInterval:seconds target:widget selector:@selector(update) userInfo:nil repeats:YES];
}
@end
/*
* Now, we set up our own widgets
* external tweaks adding their own do this exact same thing.
* */
static __attribute__((constructor)) void AvocadoWidgetServerContsructor (int __unused argc, char __unused **argv, char __unused **envp)
{
[AVCWidgetServer sharedInstance];
}