forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneDelegate.m
68 lines (54 loc) · 2.31 KB
/
SceneDelegate.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
//
// SceneDelegate.m
// iSH
//
// Created by Theodore Dubois on 10/26/19.
//
#import "SceneDelegate.h"
#import "AboutViewController.h"
TerminalViewController *currentTerminalViewController = NULL;
@interface SceneDelegate ()
@property NSString *terminalUUID;
@end
static NSString *const TerminalUUID = @"TerminalUUID";
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"recovery"]) {
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"About" bundle:nil] instantiateInitialViewController];
AboutViewController *avc = (AboutViewController *) vc.topViewController;
avc.recoveryMode = YES;
self.window.rootViewController = vc;
return;
}
TerminalViewController *vc = (TerminalViewController *) self.window.rootViewController;
vc.sceneSession = session;
if (session.stateRestorationActivity == nil) {
[vc startNewSession];
} else {
self.terminalUUID = session.stateRestorationActivity.userInfo[TerminalUUID];
[vc reconnectSessionFromTerminalUUID:
[[NSUUID alloc] initWithUUIDString:self.terminalUUID]];
}
}
- (NSUserActivity *)stateRestorationActivityForScene:(UIScene *)scene {
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"app.ish.scene"];
TerminalViewController *vc = (TerminalViewController *) self.window.rootViewController;
if ([vc isKindOfClass:TerminalViewController.class]) {
self.terminalUUID = vc.sessionTerminalUUID.UUIDString;
if (self.terminalUUID != nil) {
[activity addUserInfoEntriesFromDictionary:@{TerminalUUID: self.terminalUUID}];
}
}
return activity;
}
- (void)sceneDidBecomeActive:(UIScene *)scene {
TerminalViewController *terminalViewController = (TerminalViewController *) self.window.rootViewController;;
currentTerminalViewController = terminalViewController;
}
- (void)sceneWillResignActive:(UIScene *)scene {
TerminalViewController *terminalViewController = (TerminalViewController *) self.window.rootViewController;
if (currentTerminalViewController == terminalViewController) {
currentTerminalViewController = NULL;
}
}
@end