Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
293 changes: 238 additions & 55 deletions English.lproj/MainMenu.xib

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>1.8</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
Expand All @@ -16,19 +18,17 @@
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.7</string>
<string>1.8</string>
<key>LSUIElement</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>LSUIElement</key>
<true/>
<key>CFBundleShortVersionString</key>
<string>1.7</string>
<key>CFBundleGetInfoString</key>
<string>1.7</string>
</dict>
</plist>
6 changes: 4 additions & 2 deletions Proximity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,14 @@
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = Proximity.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Proximity_Prefix.pch;
INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = Proximity;
};
name = Debug;
Expand All @@ -393,11 +394,12 @@
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = Proximity.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_IDENTITY = "";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Proximity_Prefix.pch;
INFOPLIST_FILE = Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = Proximity;
};
name = Release;
Expand Down
2 changes: 2 additions & 0 deletions ProximityAppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ typedef enum _BPStatus {
IBOutlet NSButton *runScriptsOnStartup;
IBOutlet NSTextField *timerInterval;
IBOutlet NSSlider *requiredSignalStrength;
IBOutlet NSTextField *inRangeDetectionsCountInput;
IBOutlet NSTextField *outOfRangeDetectionsCountInput;
}

// UI methods
Expand Down
20 changes: 20 additions & 0 deletions ProximityAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ - (void)windowWillClose:(NSNotification *)aNotification
if(monitoringEnabled.state == NSOnState && monitor.device) {
monitor.requiredSignalStrength = requiredSignalStrength.integerValue;
monitor.timeInterval = timerInterval.doubleValue;
monitor.inRangeDetectionCount = inRangeDetectionsCountInput.integerValue;
monitor.outOfRangeDetectionCount = outOfRangeDetectionsCountInput.integerValue;
[monitor refresh];
[monitor start];
} else {
Expand Down Expand Up @@ -174,6 +176,18 @@ - (void)userDefaultsLoad
monitor.timeInterval = timerInterval.doubleValue;
}

//minimum IN range detections to trigger script
if( [[defaults stringForKey:@"inRangeDetectionsCount"] length] > 0 ) {
[inRangeDetectionsCountInput setStringValue:[defaults stringForKey:@"inRangeDetectionsCount"]];
monitor.inRangeDetectionCount = inRangeDetectionsCountInput.integerValue;
}

//minimum OUT OF range detections to trigger script
if( [[defaults stringForKey:@"outOfRangeDetectionsCount"] length] > 0 ) {
[outOfRangeDetectionsCountInput setStringValue:[defaults stringForKey:@"outOfRangeDetectionsCount"]];
monitor.outOfRangeDetectionCount = outOfRangeDetectionsCountInput.integerValue;
}

//require StrongSignal
[requiredSignalStrength setIntegerValue:[defaults integerForKey:@"requiredSignalStrength"]];
monitor.requiredSignalStrength = requiredSignalStrength.integerValue;
Expand Down Expand Up @@ -255,7 +269,13 @@ - (void)userDefaultsSave

// Timer interval
[defaults setObject:[timerInterval stringValue] forKey:@"timerInterval"];

//minimum IN range detections to trigger script
[defaults setObject:[inRangeDetectionsCountInput stringValue] forKey:@"inRangeDetectionsCount"];

//minimum OUT OF range detections to trigger script
[defaults setObject:[outOfRangeDetectionsCountInput stringValue] forKey:@"outOfRangeDetectionsCount"];

// In range script
[defaults setURL:inRangeScriptURL forKey:@"inRangeScriptURL"];

Expand Down
5 changes: 5 additions & 0 deletions ProximityBluetoothMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ NS_ENUM(NSInteger, ProximityBluetoothStatus) {

- (void)proximityBluetoothMonitor:(ProximityBluetoothMonitor*)monitor foundDevice:(IOBluetoothDevice*)device;
- (void)proximityBluetoothMonitor:(ProximityBluetoothMonitor*)monitor lostDevice:(IOBluetoothDevice*)device;
- (void)setMenuIconInRange;
- (void)setMenuIconOutOfRange;

@end

@interface ProximityBluetoothMonitor : NSObject

@property(weak) id<ProximityBluetoothMonitorDelegate> delegate;
@property(nonatomic, assign) NSTimeInterval timeInterval;
@property(nonatomic, assign) NSInteger inRangeDetectionCount;
@property(nonatomic, assign) NSInteger outOfRangeDetectionCount;
@property(assign) BOOL requiredSignalStrength;
@property(retain) IOBluetoothDevice *device; // could be an array and statuses too

@property(readonly) enum ProximityBluetoothStatus priorStatus;
@property(readonly) enum ProximityBluetoothStatus status;
@property(readonly) enum ProximityBluetoothStatus iconStatus;

- (void)start;
- (void)stop;
Expand Down
53 changes: 45 additions & 8 deletions ProximityBluetoothMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

@implementation ProximityBluetoothMonitor {
NSTimer *_timer;
NSInteger _changedStatusCounter;
}

@synthesize inRangeDetectionCount, outOfRangeDetectionCount;

- (id)init {
self = [super init];
if(self) {
_priorStatus = _status = ProximityBluetoothStatusUndefined;
_iconStatus = _priorStatus = _status = ProximityBluetoothStatusUndefined;
_timeInterval = kDefaultPageTimeout;
_requiredSignalStrength = NO;
}
Expand All @@ -24,6 +27,7 @@ - (id)init {

- (void)start {
[_timer invalidate];
_changedStatusCounter = 0;
_timer = [NSTimer scheduledTimerWithTimeInterval:_timeInterval
target:self
selector:@selector(handleTimer:)
Expand All @@ -35,7 +39,7 @@ - (void)stop {
[_timer invalidate];
_timer = nil;

_priorStatus = _status;
_iconStatus = _priorStatus = _status;
_status = ProximityBluetoothStatusUndefined;
}

Expand All @@ -60,26 +64,59 @@ - (void)handleTimer:(NSTimer *)theTimer
BOOL inRange = [self isInRange];
#ifdef DEBUG
NSLog(@"BT device %@ inRange:%d",_device.name, inRange);
NSLog(@"Changed counter %ld", _changedStatusCounter);
#endif

_status = inRange ? ProximityBluetoothStatusInRange : ProximityBluetoothStatusOutOfRange;

if(_status != _iconStatus)
{
if(_status == ProximityBluetoothStatusInRange)
{
[_delegate setMenuIconInRange];
}
else
{
[_delegate setMenuIconOutOfRange];
}
_iconStatus = _status;
}

if( inRange ) {
if( _priorStatus != ProximityBluetoothStatusInRange ) {
_priorStatus = ProximityBluetoothStatusInRange;
[_delegate proximityBluetoothMonitor:self foundDevice:_device];
_changedStatusCounter++;
if(_changedStatusCounter >= inRangeDetectionCount)
{
_changedStatusCounter = 0;
_priorStatus = ProximityBluetoothStatusInRange;
[_delegate proximityBluetoothMonitor:self foundDevice:_device];
#ifdef DEBUG
NSLog(@"-- found");
NSLog(@"-- found");
#endif
}
}
else
{
_changedStatusCounter = 0;
}
}
else {
if( _priorStatus != ProximityBluetoothStatusOutOfRange ) {
_priorStatus = ProximityBluetoothStatusOutOfRange;
[_delegate proximityBluetoothMonitor:self lostDevice:_device];
_changedStatusCounter++;
if(_changedStatusCounter >= outOfRangeDetectionCount)
{
_changedStatusCounter = 0;
_priorStatus = ProximityBluetoothStatusOutOfRange;
[_delegate proximityBluetoothMonitor:self lostDevice:_device];
#ifdef DEBUG
NSLog(@"-- lost");
NSLog(@"-- lost");
#endif
}
}
else
{
_changedStatusCounter = 0;
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ Proximity monitors the proximity of your mobile phone or other bluetooth device
The intent of this project is for the source code to be critiqued by other developers in hopes of improving my Cocoa programming abilities, as well as my programming skills in general.

###Credits
This version is based on proximity 1.5 from reduxcomputing
This version is based on proximity 1.71 from [Daij-Djan](https://github.com/Daij-Djan/proximity) which in turn is based on proximity 1.5 from [reduxcomputing](https://github.com/revned/proximity/).
Including fixes from [fivemicro](https://github.com/fivemicro/proximity)

###Changes
-
#####1.8
* added the option to delay running the script for in/out of range only after a set number of detections have occured

#####1.71
added the option to require a good signal strength (defined as the Golden Cut in the BT4 Specification)
* added the option to require a good signal strength (defined as the Golden Cut in the BT4 Specification)

#####1.7
* Added sandboxing & mac appstore compatible way to open the app at login
Expand Down