forked from khanhduytran0/FrontBoardAppLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecoratedAppSceneView.m
93 lines (80 loc) · 4.89 KB
/
DecoratedAppSceneView.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
93
#import "DecoratedAppSceneView.h"
@implementation DecoratedAppSceneView
- (instancetype)initWithBundleID:(NSString *)bundleID {
self = [super initWithFrame:CGRectMake(0, 100, 400, 400)];
self.transitionContext = [UIApplicationSceneTransitionContext new];
self.navigationBar.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
[self.navigationBar.standardAppearance configureWithTransparentBackground];
self.navigationBar.standardAppearance.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemClose target:self action:@selector(closeWindow)];
RBSProcessIdentity* identity = [RBSProcessIdentity identityForEmbeddedApplicationIdentifier:bundleID];
RBSProcessPredicate* predicate = [RBSProcessPredicate predicateMatchingIdentity:identity];
FBProcessManager *manager = FBProcessManager.sharedInstance;
FBApplicationProcessLaunchTransaction *transaction = [[FBApplicationProcessLaunchTransaction alloc] initWithProcessIdentity:identity executionContextProvider:^id(void){
FBMutableProcessExecutionContext *context = [FBMutableProcessExecutionContext new];
context.identity = identity;
context.environment = @{}; // environment variables
//context.waitForDebugger = NO;
//context.disableASLR = NO;
context.launchIntent = 4;
//context.watchdogProvider = SBSceneWatchdogProvider
return [manager launchProcessWithContext:context];
}];
[transaction setCompletionBlock:^{
// At this point, the process is spawned and we're ready to create a scene to render in our app
RBSProcessHandle* processHandle = [RBSProcessHandle handleForPredicate:predicate error:nil];
[manager registerProcessForAuditToken:processHandle.auditToken];
NSString *identifier = [NSString stringWithFormat:@"sceneID:%@-%@", bundleID, @"default"];
FBSMutableSceneDefinition *definition = [FBSMutableSceneDefinition definition];
definition.identity = [FBSSceneIdentity identityForIdentifier:identifier];
definition.clientIdentity = [FBSSceneClientIdentity identityForProcessIdentity:identity];
definition.specification = [UIApplicationSceneSpecification specification];
FBSMutableSceneParameters *parameters = [FBSMutableSceneParameters parametersForSpecification:definition.specification];
UIMutableApplicationSceneSettings *settings = [UIMutableApplicationSceneSettings new];
settings.canShowAlerts = YES;
settings.cornerRadiusConfiguration = [[BSCornerRadiusConfiguration alloc] initWithTopLeft:self.layer.cornerRadius bottomLeft:self.layer.cornerRadius bottomRight:self.layer.cornerRadius topRight:self.layer.cornerRadius];
settings.displayConfiguration = UIScreen.mainScreen.displayConfiguration;
settings.foreground = YES;
settings.frame = self.bounds;
settings.interfaceOrientation = UIInterfaceOrientationPortrait;
//settings.interruptionPolicy = 2; // reconnect
settings.level = 1;
settings.peripheryInsets = UIEdgeInsetsMake(self.navigationBar.frame.size.height, 0, 0, 0);
settings.persistenceIdentifier = NSUUID.UUID.UUIDString;
settings.safeAreaInsetsPortrait = UIEdgeInsetsMake(self.navigationBar.frame.size.height, 0, 0, 0);
//settings.statusBarDisabled = 1;
//settings.previewMaximumSize =
//settings.deviceOrientationEventsEnabled = YES;
self.settings = settings;
parameters.settings = settings;
UIMutableApplicationSceneClientSettings *clientSettings = [UIMutableApplicationSceneClientSettings new];
clientSettings.interfaceOrientation = UIInterfaceOrientationPortrait;
clientSettings.statusBarStyle = 0;
parameters.clientSettings = clientSettings;
FBScene *scene = [[FBSceneManager sharedInstance] createSceneWithDefinition:definition initialParameters:parameters];
// TODO: get app display name
self.navigationItem.title = scene.clientProcess.name;
self.presenter = [scene.uiPresentationManager createPresenterWithIdentifier:identifier];
[self.presenter activate];
[self insertSubview:self.presenter.presentationView atIndex:0];
}];
[transaction begin];
return self;
}
- (void)closeWindow {
self.layer.masksToBounds = NO;
[UIView transitionWithView:self duration:0.4 options:UIViewAnimationOptionTransitionCurlUp //CrossDissolve
animations:^{
self.hidden = YES;
} completion:^(BOOL b){
[self.presenter deactivate];
[self.presenter invalidate];
[self removeFromSuperview];
}];
}
- (void)resizeWindow:(UIPanGestureRecognizer*)sender {
[super resizeWindow:sender];
self.settings.frame = self.bounds;
[self.presenter.scene updateSettings:self.settings withTransitionContext:self.transitionContext completion:nil];
}
@end