Просмотр исходного кода

Bug fixes

- Fix root view controller global not working
- Fix crash in keychain viewer when viewing NSData
renwei.chen лет назад: 6
Родитель
Сommit
ef8f866330

+ 29 - 10
Classes/GlobalStateExplorers/Keychain/FLEXKeychainTableViewController.m

@@ -10,6 +10,7 @@
 #import "FLEXKeychainQuery.h"
 #import "FLEXKeychainTableViewController.h"
 #import "FLEXUtility.h"
+#import "UIPasteboard+FLEX.h"
 
 @interface FLEXKeychainTableViewController ()
 
@@ -47,6 +48,17 @@
     self.headerTitle = [NSString stringWithFormat:@"%@ items", @(self.keychainItems.count)];
 }
 
+- (FLEXKeychainQuery *)queryForItemAtIndex:(NSInteger)idx
+{
+    NSDictionary *item = self.keychainItems[idx];
+
+    FLEXKeychainQuery *query = [FLEXKeychainQuery new];
+    query.service = item[kFLEXKeychainWhereKey];
+    query.account = item[kFLEXKeychainAccountKey];
+    [query fetch:nil];
+
+    return query;
+}
 
 #pragma mark Buttons
 
@@ -134,7 +146,16 @@
     }
     
     NSDictionary *item = self.keychainItems[indexPath.row];
-    cell.textLabel.text = item[kFLEXKeychainAccountKey];
+    id account = item[kFLEXKeychainAccountKey];
+    if ([account isKindOfClass:[NSString class]]) {
+        cell.textLabel.text = account;
+    } else {
+        cell.textLabel.text = [NSString stringWithFormat:
+            @"[%@]\n\n%@",
+            NSStringFromClass([account class]),
+            [account description]
+        ];
+    }
     
     return cell;
 }
@@ -149,13 +170,8 @@
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    NSDictionary *item = self.keychainItems[indexPath.row];
+    FLEXKeychainQuery *query = [self queryForItemAtIndex:indexPath.row];
     
-    FLEXKeychainQuery *query = [FLEXKeychainQuery new];
-    query.service = item[kFLEXKeychainWhereKey];
-    query.account = item[kFLEXKeychainAccountKey];
-    [query fetch:nil];
-
     [FLEXAlert makeAlert:^(FLEXAlert *make) {
         make.title(query.service);
         make.message(@"Service: ").message(query.service);
@@ -163,16 +179,19 @@
         make.message(@"\nPassword: ").message(query.password);
 
         make.button(@"Copy Service").handler(^(NSArray<NSString *> *strings) {
-            UIPasteboard.generalPasteboard.string = query.service;
+            [UIPasteboard.generalPasteboard flex_copy:query.service];
         });
         make.button(@"Copy Account").handler(^(NSArray<NSString *> *strings) {
-            UIPasteboard.generalPasteboard.string = query.account;
+            [UIPasteboard.generalPasteboard flex_copy:query.account];
         });
         make.button(@"Copy Password").handler(^(NSArray<NSString *> *strings) {
-            UIPasteboard.generalPasteboard.string = query.password;
+            [UIPasteboard.generalPasteboard flex_copy:query.password];
         });
         make.button(@"Dismiss").cancelStyle();
+        
     } showFrom:self];
+
+    [tableView deselectRowAtIndexPath:indexPath animated:YES];
 }
 
 @end

+ 2 - 0
Classes/ObjectExplorers/FLEXObjectExplorerFactory.m

@@ -115,6 +115,8 @@
             return [self explorerViewControllerForObject:UIDevice.currentDevice];
         case FLEXGlobalsRowPasteboard:
             return [self explorerViewControllerForObject:UIPasteboard.generalPasteboard];
+        case FLEXGlobalsRowRootViewController:
+            return [self explorerViewControllerForObject:UIApplication.sharedApplication.delegate.window.rootViewController];
         default: return nil;
     }
 }

+ 16 - 0
Classes/Utility/Categories/UIPasteboard+FLEX.h

@@ -0,0 +1,16 @@
+//
+//  UIPasteboard+FLEX.h
+//  FLEX
+//
+//  Created by Tanner Bennett on 12/9/19.
+//Copyright © 2019 Flipboard. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface UIPasteboard (FLEX)
+
+/// For copying an object which could be a string, data, or number
+- (void)flex_copy:(id)unknownType;
+
+@end

+ 26 - 0
Classes/Utility/Categories/UIPasteboard+FLEX.m

@@ -0,0 +1,26 @@
+//
+//  UIPasteboard+FLEX.m
+//  FLEX
+//
+//  Created by Tanner Bennett on 12/9/19.
+//Copyright © 2019 Flipboard. All rights reserved.
+//
+
+#import "UIPasteboard+FLEX.h"
+
+@implementation UIPasteboard (FLEX)
+
+- (void)flex_copy:(id)object {
+    if ([object isKindOfClass:[NSString class]]) {
+        UIPasteboard.generalPasteboard.string = object;
+    } else if([object isKindOfClass:[NSData class]]) {
+        [UIPasteboard.generalPasteboard setData:object forPasteboardType:@"public.data"];
+    } else if ([object isKindOfClass:[NSNumber class]]) {
+        UIPasteboard.generalPasteboard.string = [object stringValue];
+    }
+
+    [NSException raise:NSInternalInconsistencyException
+                format:@"Tried to copy unsupported type: %@", [object class]];
+}
+
+@end

+ 8 - 0
FLEX.xcodeproj/project.pbxproj

@@ -209,6 +209,8 @@
 		C3F31D422267D883003C991A /* FLEXTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C3F31D392267D883003C991A /* FLEXTableViewCell.m */; };
 		C3F31D432267D883003C991A /* FLEXTableView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3F31D3B2267D883003C991A /* FLEXTableView.h */; };
 		C3F31D442267D883003C991A /* FLEXTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3F31D3C2267D883003C991A /* FLEXTableView.m */; };
+		C3F646C1239EAA8F00D4A011 /* UIPasteboard+FLEX.h in Headers */ = {isa = PBXBuildFile; fileRef = C3F646BF239EAA8F00D4A011 /* UIPasteboard+FLEX.h */; };
+		C3F646C2239EAA8F00D4A011 /* UIPasteboard+FLEX.m in Sources */ = {isa = PBXBuildFile; fileRef = C3F646C0239EAA8F00D4A011 /* UIPasteboard+FLEX.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -429,6 +431,8 @@
 		C3F31D392267D883003C991A /* FLEXTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXTableViewCell.m; sourceTree = "<group>"; };
 		C3F31D3B2267D883003C991A /* FLEXTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXTableView.h; sourceTree = "<group>"; };
 		C3F31D3C2267D883003C991A /* FLEXTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXTableView.m; sourceTree = "<group>"; };
+		C3F646BF239EAA8F00D4A011 /* UIPasteboard+FLEX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIPasteboard+FLEX.h"; sourceTree = "<group>"; };
+		C3F646C0239EAA8F00D4A011 /* UIPasteboard+FLEX.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIPasteboard+FLEX.m"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -799,6 +803,8 @@
 			children = (
 				C387C88122E0D24A00750E58 /* UIView+FLEX_Layout.h */,
 				C387C88222E0D24A00750E58 /* UIView+FLEX_Layout.m */,
+				C3F646BF239EAA8F00D4A011 /* UIPasteboard+FLEX.h */,
+				C3F646C0239EAA8F00D4A011 /* UIPasteboard+FLEX.m */,
 			);
 			path = Categories;
 			sourceTree = "<group>";
@@ -885,6 +891,7 @@
 				3A4C951E1B5B21410088C3F2 /* FLEXClassesTableViewController.h in Headers */,
 				779B1ED21C0C4D7C001F5E49 /* FLEXTableColumnHeader.h in Headers */,
 				3A4C94FD1B5B21410088C3F2 /* FLEXArgumentInputStructView.h in Headers */,
+				C3F646C1239EAA8F00D4A011 /* UIPasteboard+FLEX.h in Headers */,
 				94A515141C4CA1C00063292F /* FLEXManager.h in Headers */,
 				C37A0C93218BAC9600848CA7 /* FLEXObjcInternal.h in Headers */,
 				3A4C953E1B5B21410088C3F2 /* FLEXNetworkTransactionDetailTableViewController.h in Headers */,
@@ -1096,6 +1103,7 @@
 				3A4C950E1B5B21410088C3F2 /* FLEXIvarEditorViewController.m in Sources */,
 				C3DC287C223ED5F200F48AA6 /* FLEXOSLogController.m in Sources */,
 				3A4C95101B5B21410088C3F2 /* FLEXMethodCallingViewController.m in Sources */,
+				C3F646C2239EAA8F00D4A011 /* UIPasteboard+FLEX.m in Sources */,
 				3A4C94F61B5B21410088C3F2 /* FLEXArgumentInputObjectView.m in Sources */,
 				3A4C94EC1B5B21410088C3F2 /* FLEXImagePreviewViewController.m in Sources */,
 				3A4C94F21B5B21410088C3F2 /* FLEXArgumentInputFontsPickerView.m in Sources */,