forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AboutViewController.m
118 lines (99 loc) · 4.92 KB
/
AboutViewController.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// AboutViewController.m
// iSH
//
// Created by Theodore Dubois on 9/23/18.
//
#import "UIApplication+OpenURL.h"
#import "AboutViewController.h"
#import "UserPreferences.h"
#import "AppGroup.h"
#import "NSObject+SaneKVO.h"
@interface AboutViewController ()
@property (weak, nonatomic) IBOutlet UITableViewCell *capsLockMappingCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *themeCell;
@property (weak, nonatomic) IBOutlet UISwitch *disableDimmingSwitch;
@property (weak, nonatomic) IBOutlet UITextField *launchCommandField;
@property (weak, nonatomic) IBOutlet UITextField *bootCommandField;
@property (weak, nonatomic) IBOutlet UITableViewCell *sendFeedback;
@property (weak, nonatomic) IBOutlet UITableViewCell *openGithub;
@property (weak, nonatomic) IBOutlet UITableViewCell *openTwitter;
@property (weak, nonatomic) IBOutlet UITableViewCell *openDiscord;
@property (weak, nonatomic) IBOutlet UITableViewCell *exportContainerCell;
@property (weak, nonatomic) IBOutlet UILabel *versionLabel;
@end
@implementation AboutViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self _updatePreferenceUI];
if (self.recoveryMode) {
self.includeDebugPanel = YES;
self.navigationItem.title = @"Recovery Mode";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Exit"
style:UIBarButtonItemStyleDone
target:self
action:@selector(exitRecovery:)];
self.navigationItem.leftBarButtonItem = nil;
}
_versionLabel.text = [NSString stringWithFormat:@"iSH %@ (Build %@)",
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
[UserPreferences.shared observe:@[@"capsLockMapping", @"fontSize", @"launchCommand", @"bootCommand"]
options:0 owner:self usingBlock:^(typeof(self) self) {
[self _updatePreferenceUI];
}];
}
- (IBAction)dismiss:(id)sender {
[self dismissViewControllerAnimated:self completion:nil];
}
- (void)exitRecovery:(id)sender {
[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"recovery"];
exit(0);
}
- (void)_updatePreferenceUI {
UserPreferences *prefs = UserPreferences.shared;
self.themeCell.detailTextLabel.text = prefs.theme.presetName;
self.disableDimmingSwitch.on = UserPreferences.shared.shouldDisableDimming;
self.launchCommandField.text = [UserPreferences.shared.launchCommand componentsJoinedByString:@" "];
self.bootCommandField.text = [UserPreferences.shared.bootCommand componentsJoinedByString:@" "];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell == self.sendFeedback) {
[UIApplication openURL:@"mailto:tblodt@icloud.com?subject=Feedback%20for%20iSH"];
} else if (cell == self.openGithub) {
[UIApplication openURL:@"https://github.com/ish-app/ish"];
} else if (cell == self.openTwitter) {
[UIApplication openURL:@"https://twitter.com/tblodt"];
} else if (cell == self.openDiscord) {
[UIApplication openURL:@"https://discord.gg/HFAXj44"];
} else if (cell == self.exportContainerCell) {
// copy the files to the app container so they can be extracted from iTunes file sharing
NSURL *container = ContainerURL();
NSURL *documents = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
[NSFileManager.defaultManager removeItemAtURL:[documents URLByAppendingPathComponent:@"roots copy"] error:nil];
[NSFileManager.defaultManager copyItemAtURL:[container URLByAppendingPathComponent:@"roots"]
toURL:[documents URLByAppendingPathComponent:@"roots copy"]
error:nil];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSInteger sections = [super numberOfSectionsInTableView:tableView];
if (!self.includeDebugPanel)
sections--;
return sections;
}
- (IBAction)disableDimmingChanged:(id)sender {
UserPreferences.shared.shouldDisableDimming = self.disableDimmingSwitch.on;
}
- (IBAction)textBoxSubmit:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)launchCommandChanged:(id)sender {
UserPreferences.shared.launchCommand = [self.launchCommandField.text componentsSeparatedByString:@" "];
}
- (IBAction)bootCommandChanged:(id)sender {
UserPreferences.shared.bootCommand = [self.bootCommandField.text componentsSeparatedByString:@" "];
}
@end