forked from SniperGER/LockWatch2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomFaces.xm
87 lines (68 loc) · 2.43 KB
/
CustomFaces.xm
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
//
// CustomFaces.xm
// LockWatch2
//
// Created by janikschmidt on 1/23/2020
// Copyright © 2020 Team FESTIVAL. All rights reserved
//
#include <substrate.h>
#import <NanoTimeKitCompanion/NanoTimeKitCompanion.h>
#import "Core/LWCustomFaceInterface.h"
#import "Core/LWPreferences.h"
%group SpringBoard
%hook NTKFace
+ (instancetype)faceWithJSONObjectRepresentation:(NSDictionary*)arg1 forDevice:(CLKDevice*)arg2 {
if ([[arg1 objectForKeyedSubscript:@"face type"] isEqualToString:@"custom"]) {
NTKFace<LWCustomFaceInterface>* face = [[NSClassFromString([arg1 objectForKeyedSubscript:@"class"]) alloc] _initWithFaceStyle:0x100 forDevice:arg2];
if (face) {
NTKFaceConfiguration* faceConfiguration = [[NTKFaceConfiguration alloc] initWithJSONDictionary:arg1 editModeMapping:face forDevice:arg2];
[face _customizeWithJSONDescription:arg1];
[face _applyConfiguration:faceConfiguration allowFailure:NO];
}
return face;
}
return %orig;
}
- (NSMutableDictionary*)JSONObjectRepresentation {
NSMutableDictionary* r = %orig;
if (self.faceStyle == 0x100) {
[r setObject:@"custom" forKey:@"face type"];
[r setObject:NSStringFromClass(self.class) forKey:@"class"];
[r setObject:[[NSBundle bundleForClass:self.class] bundleIdentifier] forKey:@"bundle identifier"];
}
return r;
}
%end /// %hook NTKFace
%hook NTKFaceViewController
- (void)loadView {
if ([self.face.class conformsToProtocol:@protocol(LWCustomFaceInterface)]) {
CLKDevice* device = [CLKDevice currentDevice];
NTKFace<LWCustomFaceInterface>* face = (NTKFace<LWCustomFaceInterface>*)self.face;
UIView* view = [UIView new];
NTKFaceView* faceView = [[[face.class faceViewClass] alloc] initWithFaceStyle:[face faceStyle] forDevice:device clientIdentifier:nil];
[faceView setDelegate:self];
MSHookIvar<NTKFaceView*>(self, "_faceView") = faceView;
[self _setFaceViewResourceDirectoryFromFace];
[faceView populateFaceViewEditOptionsFromFace:face];
[self _loadInitialComplicationVisibilityFromFace];
[view setBounds:faceView.bounds];
[view addSubview:faceView];
[self setView:view];
} else {
%orig;
}
}
%end /// %hook NTKFaceViewController
%end // %group SpringBoard
%ctor {
@autoreleasepool {
LWPreferences* preferences = [LWPreferences sharedInstance];
NSString* bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
if (bundleIdentifier && preferences.enabled) {
%init();
if (IN_SPRINGBOARD) {
%init(SpringBoard);
}
}
}
}