Repository navigation
Expand file tree
/
Copy pathKBDefines.h
More file actions
105 lines (71 loc) · 3.33 KB
/
Copy pathKBDefines.h
File metadata and controls
105 lines (71 loc) · 3.33 KB
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
//
// KBDefines.h
// Keybase
//
// Created by Gabriel on 5/13/15.
// Copyright (c) 2015 Gabriel Handford. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <GHKit/GHKit.h>
#import <ObjectiveSugar/ObjectiveSugar.h>
#import <CocoaLumberjack/CocoaLumberjack.h>
static const int ddLogLevel = DDLogLevelDebug;
typedef void (^KBCompletion)(NSError *error);
typedef void (^KBOnCompletion)(NSError *error, id value);
typedef void (^KBOnExtension)(id sender, NSExtensionItem *outputItem);
typedef void (^KBOnTarget)(id sender);
typedef NS_ENUM (NSInteger, KBErrorCode) {
KBErrorCodeWarning = 0,
KBErrorCodeGeneric = -1,
KBErrorCodeUnsupported = -10,
KBErrorCodePermissionDenied = -11,
KBErrorCodeInstallError = -101,
KBErrorCodePathNotFound = -102,
KBErrorCodePathInaccessible = -103,
KBErrorCodeAlreadyOpening = -201,
KBErrorCodeAlreadyOpen = -202,
KBErrorCodeTimeout = -210,
KBErrorCodeFuseKext = -300,
KBErrorCodeFuseKextPermission = -301,
KBErrorCodeFuseKextMountsPresent = -302,
KBErrorCodeFuseCriticalUpdate = -303,
};
typedef NS_ENUM (NSInteger, KBErrorResponse) {
KBErrorResponseNone,
KBErrorResponseRetry,
// The error is ignored if it is was a cancelation error, or
// an error is already showing.
KBErrorResponseIgnored,
};
#define KBMakeError(CODE, MSG, ...) [NSError errorWithDomain:@"Keybase" code:CODE userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:MSG, ##__VA_ARGS__], NSLocalizedRecoveryOptionsErrorKey: @[@"OK"]}]
#define KBMakeErrorWithRecovery(CODE, MSG, RECOVERY, ...) [NSError errorWithDomain:@"Keybase" code:CODE userInfo:@{NSLocalizedDescriptionKey: MSG, NSLocalizedRecoveryOptionsErrorKey: @[@"OK"], NSLocalizedRecoverySuggestionErrorKey:[NSString stringWithFormat:RECOVERY, ##__VA_ARGS__]}]
#define KBMakeWarning(MSG, ...) KBMakeError(KBErrorCodeWarning, MSG, ##__VA_ARGS__)
#define KBIsWarning(ERR) ((ERR.code == KBErrorCodeWarning))
#define KBOrNull(obj) (obj ? obj : NSNull.null)
#define KBOr(obj, dv) (obj ? obj : dv)
#define KBIfNull(obj, val) ([obj isEqual:NSNull.null] ? val : obj)
#define KBIfBlank(s, dv) ((!s || [s isEqualToString:@""]) ? dv : s)
#define KBErrorAlert(fmt, ...) [NSError errorWithDomain:@"Keybase" code:-1 userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:fmt, ##__VA_ARGS__], NSLocalizedRecoveryOptionsErrorKey:@[@"OK"]}]
#define KBMap(ARRAY, PROPERTY) [ARRAY map:^(id obj) { return [obj PROPERTY]; }]
#define KBAppGroupId (@"keybase")
NSNumber *KBNumberFromString(NSString *s);
NSString *KBNSStringWithFormat(NSString *formatString, ...);
NSString *KBNSStringByStrippingHTML(NSString *str);
BOOL KBIsErrorName(NSError *error, NSString *name);
NSString *KBDisplayURLStringForUsername(NSString *username);
NSString *KBURLStringForUsername(NSString *username);
NSString *KBPGPKeyIdFromFingerprint(NSString *fingerprint);
NSString *KBDescriptionForKID(NSData *kid);
NSString *KBDescriptionForFingerprint(NSString *fingerprint, NSInteger indexForLineBreak);
typedef NS_ENUM (NSInteger, KBProofAction) {
KBProofActionCancel = 0,
KBProofActionRetry,
KBProofActionReplace,
KBProofActionRevoke,
KBProofActionOpen,
KBProofActionView,
KBProofActionRepair,
};
NSString *KBImageNameForServiceName(NSString *serviceName);
NSString *KBShortNameForServiceName(NSString *serviceName);
NSString *KBNameForServiceName(NSString *serviceName);