Skip to content

Commit 0608c2d

Browse files
committed
OSX environments use run mode.
Will also query service first in case homebrew is installed.
1 parent 39b2d54 commit 0608c2d

30 files changed

Lines changed: 390 additions & 258 deletions

‎osx/KBKit/App/KBApp.m‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ - (void)open {
9494
KBEnvSelectView *envSelectView = [[KBEnvSelectView alloc] init];
9595
KBNavigationView *navigation = [[KBNavigationView alloc] initWithView:envSelectView title:@"Keybase"];
9696
KBWindow *window = [KBWindow windowWithContentView:navigation size:CGSizeMake(900, 600) retain:YES];
97-
envSelectView.onSelect = ^(KBEnvironment *environment) {
97+
envSelectView.onSelect = ^(KBEnvConfig *envConfig) {
9898
[window close];
99-
[self openWithEnvironment:environment];
99+
[KBEnvironment lookupForConfig:envConfig completion:^(KBEnvironment *environment) {
100+
[self openWithEnvironment:environment];
101+
}];
100102
};
101103
window.styleMask = NSFullSizeContentViewWindowMask | NSTitledWindowMask | NSResizableWindowMask;
102104
[window center];

‎osx/KBKit/App/KBAppExtension.m‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88

99
#import "KBAppExtension.h"
1010

11-
#import "KBService.h"
1211
#import "KBPGPEncryptActionView.h"
1312
#import "KBWorkspace.h"
1413
#import "KBPGPEncrypt.h"
1514
#import "KBWork.h"
15+
#import "KBRPClient.h"
1616

1717
#import <CocoaLumberjack/CocoaLumberjack.h>
1818

1919
@interface KBAppExtension ()
20-
@property (nonatomic) KBService *service;
20+
@property (nonatomic) KBRPClient *client;
2121
@end
2222

2323
@implementation KBAppExtension
2424

25-
- (KBService *)service {
26-
if (!_service) {
27-
KBEnvConfig *config = [KBEnvConfig loadFromUserDefaults:[KBWorkspace userDefaults]];
28-
_service = [[KBService alloc] initWithConfig:config];
25+
- (KBRPClient *)client {
26+
if (!_client) {
27+
KBEnvConfig *config = [KBEnvConfig envConfigFromUserDefaults:[KBWorkspace userDefaults]];
28+
_client = [[KBRPClient alloc] initWithConfig:config];
2929
}
30-
return _service;
30+
return _client;
3131
}
3232

3333
- (NSView *)encryptViewWithExtensionItem:(NSExtensionItem *)extensionItem completion:(KBOnExtension)completion {
3434
KBPGPEncryptActionView *encryptView = [[KBPGPEncryptActionView alloc] initWithFrame:CGRectMake(0, 0, 400, 300)];
3535
encryptView.extensionItem = extensionItem;
36-
encryptView.client = self.service.client;
36+
encryptView.client = self.client;
3737
encryptView.completion = completion;
3838
return encryptView;
3939
}
4040

4141
- (void)encryptExtensionItem:(NSExtensionItem *)extensionItem usernames:(NSArray *)usernames sender:(id)sender completion:(KBOnExtension)completion {
4242
KBPGPEncrypt *encrypt = [[KBPGPEncrypt alloc] init];
43-
KBRPClient *client = self.service.client;
43+
KBRPClient *client = self.client;
4444
NSString *text = extensionItem.attributedContentText.string;
4545
[encrypt encryptText:text usernames:usernames client:client sender:sender completion:^(KBWork *work) {
4646
//NSError *error = [work error];

‎osx/KBKit/Component/KBComponentStatus.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
typedef NS_ENUM (NSInteger, KBInstallStatus) {
1414
KBInstallStatusError = 1,
15+
KBInstallStatusUnknown,
1516
KBInstallStatusNotInstalled,
1617
KBInstallStatusNeedsUpgrade,
1718
KBInstallStatusInstalled,

‎osx/KBKit/Component/KBComponentStatus.m‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ - (BOOL)needsInstallOrUpgrade {
5353

5454
- (NSString *)actionLabel {
5555
switch (_installStatus) {
56+
case KBInstallStatusUnknown: return @"Unknown";
5657
case KBInstallStatusNeedsUpgrade: return @"Upgrade";
5758
case KBInstallStatusInstalled: return @"Uninstall";
5859
case KBInstallStatusNotInstalled: return @"Install";
@@ -83,6 +84,7 @@ - (NSString *)statusDescription {
8384
NSString *NSStringFromKBInstallStatus(KBInstallStatus status) {
8485
switch (status) {
8586
case KBInstallStatusError: return @"Error";
87+
case KBInstallStatusUnknown: return @"Unknown";
8688
case KBInstallStatusNotInstalled: return @"Not Installed";
8789
case KBInstallStatusNeedsUpgrade: return @"Needs Upgrade";
8890
case KBInstallStatusInstalled: return @"Installed";

‎osx/KBKit/Component/KBFSConfig.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
- (instancetype)initWithConfig:(KBEnvConfig *)config;
1919

20-
- (NSDictionary *)launchdPlistDictionary;
20+
- (NSDictionary *)launchdPlistDictionary:(NSString *)label;
2121

2222
- (NSString *)commandLineWithPathOptions:(KBPathOptions)pathOptions;
2323

‎osx/KBKit/Component/KBFSConfig.m‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ - (NSArray *)programArgumentsWithPathOptions:(KBPathOptions)pathOptions useBundl
6363
return pargs;
6464
}
6565

66-
- (NSDictionary *)launchdPlistDictionary {
67-
if (!_config.launchdLabelKBFS) return nil;
66+
- (NSDictionary *)launchdPlistDictionary:(NSString *)label {
67+
NSParameterAssert(label);
6868

6969
NSArray *args = [self programArgumentsWithPathOptions:0 useBundle:YES args:nil];
7070
NSDictionary *envs = [self envsWithPathOptions:0];
7171
return @{
72-
@"Label": _config.launchdLabelKBFS,
72+
@"Label": label,
7373
@"EnvironmentVariables": envs,
7474
@"ProgramArguments": args,
7575
@"RunAtLoad": @YES,
7676
@"KeepAlive": @YES,
7777
@"WorkingDirectory": [_config appPath:nil options:0],
78-
@"StandardOutPath": [_config logFile:_config.launchdLabelKBFS],
79-
@"StandardErrorPath": [_config logFile:_config.launchdLabelKBFS],
78+
@"StandardOutPath": [_config logFile:label],
79+
@"StandardErrorPath": [_config logFile:label],
8080
};
8181
}
8282

‎osx/KBKit/Component/KBFSService.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
@interface KBFSService : NSObject <KBComponent, KBInstallable>
1616

17-
- (instancetype)initWithConfig:(KBEnvConfig *)config;
17+
- (instancetype)initWithConfig:(KBEnvConfig *)config label:(NSString *)label;
1818

1919
@end

‎osx/KBKit/Component/KBFSService.m‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ @interface KBFSService ()
2323

2424
@implementation KBFSService
2525

26-
- (instancetype)initWithConfig:(KBEnvConfig *)config {
26+
- (instancetype)initWithConfig:(KBEnvConfig *)config label:(NSString *)label {
2727
if ((self = [self init])) {
2828
_config = config;
2929
_name = @"KBFS";
3030
_info = @"The filesystem";
31-
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
3231
_kbfsConfig = [[KBFSConfig alloc] initWithConfig:_config];
33-
NSDictionary *plist = [_kbfsConfig launchdPlistDictionary];
34-
KBSemVersion *bundleVersion = [KBSemVersion version:info[@"KBFSVersion"] build:info[@"KBFSBuild"]];
35-
_launchService = [[KBLaunchService alloc] initWithLabel:config.launchdLabelKBFS bundleVersion:bundleVersion versionPath:_kbfsConfig.versionPath plist:plist logFile:[config logFile:config.launchdLabelKBFS]];
32+
33+
if (label) {
34+
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
35+
NSDictionary *plist = [_kbfsConfig launchdPlistDictionary:label];
36+
KBSemVersion *bundleVersion = [KBSemVersion version:info[@"KBFSVersion"] build:info[@"KBFSBuild"]];
37+
_launchService = [[KBLaunchService alloc] initWithLabel:label bundleVersion:bundleVersion versionPath:_kbfsConfig.versionPath plist:plist logFile:[config logFile:label]];
38+
}
3639
}
3740
return self;
3841
}
@@ -54,7 +57,7 @@ - (void)componentDidUpdate {
5457
GHODictionary *statusInfo = [_launchService componentStatusInfo];
5558
if (statusInfo) [info addEntriesFromOrderedDictionary:statusInfo];
5659

57-
if (self.config.installEnabled) {
60+
if (_launchService) {
5861
info[@"Launchd Plist"] = [KBPath path:[_launchService plistDestination] options:KBPathOptionsTilde];
5962
}
6063

‎osx/KBKit/Component/KBFuseComponent.m‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ - (void)refreshComponent:(KBCompletion)completion {
6666
helper.timeout = 10;
6767
[helper sendRequest:@"version" params:nil completion:^(NSError *error, NSDictionary *versions) {
6868
if (error) {
69-
self.componentStatus = [KBComponentStatus componentStatusWithInstallStatus:KBInstallStatusNotInstalled runtimeStatus:KBRuntimeStatusNotRunning info:nil];
69+
self.componentStatus = [KBComponentStatus componentStatusWithInstallStatus:KBInstallStatusUnknown runtimeStatus:KBRuntimeStatusNone info:nil];
7070
completion(error);
7171
} else {
72-
KBSemVersion *runningVersion = [KBSemVersion version:KBIfNull(versions[@"fuseRunningVersion"], nil)];
73-
KBSemVersion *installedVersion = [KBSemVersion version:KBIfNull(versions[@"fuseInstalledVersion"], nil)];
72+
NSString *fuseRunningVersion = KBIfNull(versions[@"fuseRunningVersion"], nil);
73+
NSString *fuseInstalledVersion = KBIfNull(versions[@"fuseInstalledVersion"], nil);
74+
KBSemVersion *runningVersion = [KBSemVersion version:fuseRunningVersion];
75+
KBSemVersion *installedVersion = [KBSemVersion version:fuseInstalledVersion];
7476
self.version = runningVersion;
7577
if (runningVersion) info[@"Version"] = [runningVersion description];
7678
if (!runningVersion) {

‎osx/KBKit/Component/KBService.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
@property (readonly, nonatomic) KBRGetCurrentStatusRes *userStatus;
2121
@property (readonly, nonatomic) KBRConfig *userConfig;
2222

23-
- (instancetype)initWithConfig:(KBEnvConfig *)config;
23+
- (instancetype)initWithConfig:(KBEnvConfig *)config label:(NSString *)label;
2424

2525
- (void)checkStatus:(void (^)(NSError *error, KBRGetCurrentStatusRes *userStatus, KBRConfig *userConfig))completion;
2626

27+
+ (void)lookup:(KBEnvConfig *)config completion:(void (^)(NSError *error, NSString *label))completion;
28+
2729
@end

0 commit comments

Comments
 (0)