Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.

Commit b06ccfa

Browse files
committed
Non-functional Apple ID manager
1 parent 538fa60 commit b06ccfa

4 files changed

Lines changed: 121 additions & 51 deletions

File tree

AltDeploy/ALTMainViewController.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import <libimobiledevice/libimobiledevice.h>
1515
#import <libimobiledevice/lockdown.h>
1616
#import <AltServer/ALTDeviceManager.h>
17+
#import "ALTPreferencesViewController.h"
1718
#import <AltDeploy-Swift.h>
1819
@class ALTDeviceManager;
1920
@protocol Installation;
@@ -48,6 +49,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(NSProgress *)object
4849
}];
4950
}
5051

52+
- (void)didClickPreferences:(id)sender {
53+
ALTPreferencesViewController *vc = (ALTPreferencesViewController *)[[NSStoryboard storyboardWithName:@"Main" bundle:NSBundle.mainBundle] instantiateControllerWithIdentifier:@"prefs"];
54+
[self presentViewControllerAsModalWindow:vc];
55+
}
56+
5157
#pragma mark - Life Cycle
5258

5359
- (void)viewDidLoad {
@@ -56,7 +62,11 @@ - (void)viewDidLoad {
5662
@"RegisterDeviceAutomatically": @(YES)
5763
}];
5864

59-
NSMenuItem *item = NSApp.mainMenu.itemArray[0].submenu.itemArray[3];
65+
NSMenuItem *item = NSApp.mainMenu.itemArray[0].submenu.itemArray[2];
66+
item.action = @selector(didClickPreferences:);
67+
item.target = self;
68+
69+
item = NSApp.mainMenu.itemArray[0].submenu.itemArray[3];
6070
item.action = @selector(didClickAddAppleID:);
6171
item.target = self;
6272

AltDeploy/ALTPreferencesViewController.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13-
@interface ALTPreferencesViewController : NSViewController
13+
@interface ALTPreferencesViewController : NSViewController<NSTableViewDelegate, NSTableViewDataSource> {
14+
NSArray<NSDictionary<NSString *, id> *> *accounts;
15+
NSArray<NSArray<NSTextFieldCell *> *> *cells;
16+
NSDateFormatter *dateFormatter;
17+
}
18+
@property (weak) IBOutlet NSButton *modifyButton;
19+
@property (weak) IBOutlet NSButton *removeButton;
20+
@property (weak) IBOutlet NSButton *setAsDefaultButton;
1421
@property (weak) IBOutlet NSTableView *tableView;
15-
22+
@property (weak) IBOutlet NSScrollView *scrollView;
1623
@end
1724

1825
NS_ASSUME_NONNULL_END

AltDeploy/ALTPreferencesViewController.m

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,56 @@
77
//
88

99
#import "ALTPreferencesViewController.h"
10+
#import <SAMKeychain/SAMKeychain.h>
11+
#import "ALTMainViewController.h"
1012

1113
@implementation ALTPreferencesViewController
1214

1315
- (void)viewDidLoad {
1416
[super viewDidLoad];
15-
17+
dateFormatter = [NSDateFormatter new];
18+
[dateFormatter setLocalizedDateFormatFromTemplate:@"E, d MMM yyyy HH:mm:ss"];
19+
_tableView.usesStaticContents = NO;
20+
_tableView.delegate = self;
21+
_tableView.dataSource = self;
22+
_tableView.translatesAutoresizingMaskIntoConstraints = NO;
23+
[_tableView.widthAnchor constraintEqualToAnchor:_scrollView.widthAnchor multiplier:1.0].active =
24+
[_tableView.centerYAnchor constraintEqualToAnchor:_scrollView.centerYAnchor].active =
25+
[_tableView.centerXAnchor constraintEqualToAnchor:_scrollView.centerXAnchor].active =
26+
[_tableView.heightAnchor constraintEqualToAnchor:_scrollView.heightAnchor multiplier:1.0].active = YES;
27+
[self refreshAccounts];
1628
// Do view setup here.
1729
}
1830

31+
- (void)refreshAccounts {
32+
accounts = [SAMKeychain accountsForService:NSBundle.mainBundle.bundleIdentifier];
33+
[_tableView reloadData];
34+
}
35+
36+
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
37+
return accounts.count;
38+
}
39+
40+
- (id _Nullable)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row {
41+
if ([tableColumn.identifier isEqualToString:@"appleIDColumn"]) {
42+
// Apple ID
43+
return accounts[row][kSAMKeychainAccountKey];
44+
}
45+
else {
46+
// Last modified
47+
return [dateFormatter stringFromDate:accounts[row][kSAMKeychainLastModifiedKey]];
48+
}
49+
}
50+
51+
- (BOOL)tableView:(NSTableView *)tableView shouldSelectTableColumn:(NSTableColumn *)tableColumn {
52+
return NO;
53+
}
54+
55+
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
56+
BOOL enableButtons = (_tableView.selectedRow != -1);
57+
_modifyButton.enabled = enableButtons;
58+
_removeButton.enabled = enableButtons;
59+
_setAsDefaultButton.enabled = enableButtons;
60+
}
61+
1962
@end

0 commit comments

Comments
 (0)