Skip to content

Commit

Permalink
Merge pull request #13 from duanefields/client-support
Browse files Browse the repository at this point in the history
Add client support, run on your Macbook to toggle bluetooth on during a connection
  • Loading branch information
duanefields committed Sep 23, 2015
2 parents 9801faa + 5a78f60 commit 1a10702
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
7 changes: 6 additions & 1 deletion VirtualKVM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = KVM;
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Fast Wombat";
TargetAttributes = {
47672962191BBD7200726705 = {
Expand Down Expand Up @@ -412,6 +412,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand Down Expand Up @@ -474,6 +475,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "VirtualKVM/VirtualKVM-Prefix.pch";
INFOPLIST_FILE = "VirtualKVM/VirtualKVM-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.fastwombat.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -488,6 +490,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "VirtualKVM/VirtualKVM-Prefix.pch";
INFOPLIST_FILE = "VirtualKVM/VirtualKVM-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.fastwombat.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -509,6 +512,7 @@
"$(inherited)",
);
INFOPLIST_FILE = "VirtualKVMTests/VirtualKVMTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.fastwombat.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -527,6 +531,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "VirtualKVM/VirtualKVM-Prefix.pch";
INFOPLIST_FILE = "VirtualKVMTests/VirtualKVMTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.fastwombat.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
1 change: 0 additions & 1 deletion VirtualKVM/KVMAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ @interface KVMAppDelegate ()
@implementation KVMAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//
}

@end
33 changes: 30 additions & 3 deletions VirtualKVM/KVMController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#import "GVUserDefaults+KVMApp.h"
#import "KVMStatusItem.h"
#import <IOKit/pwr_mgt/IOPMLib.h>
#include <sys/types.h>
#include <sys/sysctl.h>

@interface KVMController ()
@property (nonatomic) KVMThunderboltObserver *thunderboltObserver;
@property (nonatomic) NSStatusItem *statusItem;
@property (nonatomic) IOPMAssertionID sleepAssertion;
@property (nonatomic) BOOL isClient;

@property (nonatomic) IBOutlet NSMenu *menu;
@property (weak) IBOutlet NSMenuItem *toggleBluetoothMenuItem;
Expand All @@ -18,8 +21,25 @@ @interface KVMController ()

@implementation KVMController

+(NSString *)machineModel {
size_t len = 0;
sysctlbyname("hw.model", NULL, &len, NULL, 0);

if (len) {
char *model = malloc(len*sizeof(char));
sysctlbyname("hw.model", model, &len, NULL, 0);
NSString *model_ns = [NSString stringWithUTF8String:model];
free(model);
NSLog(@"Running on %@", model_ns);
return model_ns;
}

return @"Unknown";
}

- (id)init {
self = [super init];
self.isClient = ! [[KVMController machineModel] containsString:@"iMac"];
self.thunderboltObserver = [[KVMThunderboltObserver alloc] initWithDelegate:self];
[self.thunderboltObserver startObserving];

Expand All @@ -30,6 +50,11 @@ - (void)awakeFromNib {
self.toggleBluetoothMenuItem.state = [GVUserDefaults standardUserDefaults].toggleBluetooth ? NSOnState : NSOffState;
self.toggleDisplayMenuItem.state = [GVUserDefaults standardUserDefaults].toggleTargetDisplayMode ? NSOnState : NSOffState;
self.connectionStatusMenuItem.title = @"Status: Unknown";
self.connectionStatusMenuItem.title = [NSString stringWithFormat:@"%@ Mode: Initializing", self.isClient ? @"Client" : @"Host"];
if (self.isClient) {
self.toggleDisplayMenuItem.enabled = NO;
NSLog(@"Running in client mode");
}

self.statusItem = [KVMStatusItem statusItemWithMenu:self.menu];
}
Expand Down Expand Up @@ -73,7 +98,8 @@ - (void)thunderboltObserverDeviceConnected:(KVMThunderboltObserver *)observer {
}

if ([GVUserDefaults standardUserDefaults].toggleBluetooth) {
[[KVMBluetoothController sharedController] setBluetoothEnabled:NO];
BOOL state = self.isClient ? YES : NO;
[[KVMBluetoothController sharedController] setBluetoothEnabled:state];
}
}

Expand All @@ -86,7 +112,8 @@ - (void)thunderboltObserverDeviceDisconnected:(KVMThunderboltObserver *)observer
}

if ([GVUserDefaults standardUserDefaults].toggleBluetooth) {
[[KVMBluetoothController sharedController] setBluetoothEnabled:YES];
BOOL state = self.isClient ? NO : YES;
[[KVMBluetoothController sharedController] setBluetoothEnabled:state];
}
}

Expand All @@ -95,7 +122,7 @@ - (void)thunderboltObserver:(KVMThunderboltObserver *)observer isInitiallyConnec
}

- (void)updateConnectionState:(BOOL)connected {
self.connectionStatusMenuItem.title = [NSString stringWithFormat:@"Status: %@", connected ? @"Connected" : @"Not Connected"];
self.connectionStatusMenuItem.title = [NSString stringWithFormat:@"%@ Mode: %@", self.isClient ? @"Client" : @"Host", connected ? @"Connected" : @"Not Connected"];
}

#pragma mark - Helpers
Expand Down
2 changes: 1 addition & 1 deletion VirtualKVM/VirtualKVM-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.fastwombat.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion VirtualKVMTests/VirtualKVMTests-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.fastwombat.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down

0 comments on commit 1a10702

Please sign in to comment.