diff --git a/dominos.psd b/dominos.psd new file mode 100644 index 0000000..47449de Binary files /dev/null and b/dominos.psd differ diff --git a/iconping/iconping-Info.plist b/iconping/iconping-Info.plist index 5e9c3f4..62d8abb 100644 --- a/iconping/iconping-Info.plist +++ b/iconping/iconping-Info.plist @@ -11,7 +11,7 @@ CFBundleIconFile world_icon.icns CFBundleIdentifier - com.antirez.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/iconping/iconpingAppDelegate.h b/iconping/iconpingAppDelegate.h index 912608e..8be179b 100644 --- a/iconping/iconpingAppDelegate.h +++ b/iconping/iconpingAppDelegate.h @@ -11,7 +11,7 @@ @interface iconpingAppDelegate : NSObject { NSWindow *window; NSStatusItem *myStatusItem; - NSImage *myStatusImageOK, *myStatusImageSLOW, *myStatusImageKO; + NSImage *ping1, *ping2, *ping3, *ping4, *ping5, *ping6, *ping7, *ping8, *ping9, *pingError; NSMenu *myMenu; NSMenuItem *statusMenuItem, *openAtStartupMenuItem; uint16_t icmp_id; diff --git a/iconping/iconpingAppDelegate.m b/iconping/iconpingAppDelegate.m index 62f67ce..c1ebb99 100644 --- a/iconping/iconpingAppDelegate.m +++ b/iconping/iconpingAppDelegate.m @@ -33,9 +33,7 @@ @implementation iconpingAppDelegate #define ICMP_TYPE_ECHO_REPLY 0 #define ICMP_TYPE_ECHO_REQUEST 8 -#define CONN_STATE_KO 0 -#define CONN_STATE_SLOW 1 -#define CONN_STATE_OK 2 +#define CONN_STATE_KO -1 /* This is the standard BSD checksum code, modified to use modern types. */ static uint16_t in_cksum(const void *buffer, size_t bufferLen) @@ -150,7 +148,7 @@ - (void) receivePing { return; } - NSLog(@"OK received an ICMP packet that matches!\n"); + NSLog(@"OK received an ICMP packet that matches.\n"); if (reply->sentTime > last_received_time) { last_rtt = (int)(ustime()-reply->sentTime)/1000; last_received_time = reply->sentTime; @@ -168,7 +166,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification [self methodSignatureForSelector:@selector(timerHandler:)]]; [invocation setTarget:self]; [invocation setSelector:@selector(timerHandler:)]; - [[NSRunLoop mainRunLoop] addTimer:[NSTimer timerWithTimeInterval:0.1 invocation:invocation repeats:YES] forMode:NSRunLoopCommonModes]; + [[NSRunLoop mainRunLoop] addTimer:[NSTimer timerWithTimeInterval:0.05 invocation:invocation repeats:YES] forMode:NSRunLoopCommonModes]; myMenu = [[NSMenu alloc] initWithTitle:@"Menu Title"]; NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Quit Icon Ping" action:@selector(exitAction) keyEquivalent:@"q"]; @@ -187,10 +185,18 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; - myStatusImageOK = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"iconok" ofType:@"png"]]; - myStatusImageSLOW = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"iconslow" ofType:@"png"]]; - myStatusImageKO = [[NSImage alloc] initWithContentsOfFile: [bundle pathForResource:@"iconko" ofType:@"png"]]; - [myStatusItem setImage:myStatusImageKO]; + ping1 = [NSImage imageNamed:@"ping_1"]; + ping2 = [NSImage imageNamed:@"ping_2"]; + ping3 = [NSImage imageNamed:@"ping_3"]; + ping4 = [NSImage imageNamed:@"ping_4"]; + ping5 = [NSImage imageNamed:@"ping_5"]; + ping6 = [NSImage imageNamed:@"ping_6"]; + ping7 = [NSImage imageNamed:@"ping_7"]; + ping8 = [NSImage imageNamed:@"ping_8"]; + ping9 = [NSImage imageNamed:@"ping_9"]; + pingError = [NSImage imageNamed:@"ping_error"]; + + [myStatusItem setImage:pingError]; [myStatusItem setMenu: myMenu]; [self changeConnectionState: CONN_STATE_KO]; @@ -217,12 +223,11 @@ - (void) timerHandler: (NSTimer *) t /* Update the current state accordingly */ elapsed = (ustime() - last_received_time)/1000; /* in milliseconds */ + //NSLog(@"Ping took %d\n", (int)last_rtt); if (elapsed > 3000) { state = CONN_STATE_KO; - } else if (last_rtt < 300) { - state = CONN_STATE_OK; } else { - state = CONN_STATE_SLOW; + state = (int)((last_rtt + 10) / 100); } if (state != connection_state) { [self changeConnectionState: state]; @@ -231,15 +236,37 @@ - (void) timerHandler: (NSTimer *) t - (void) changeConnectionState: (int) state { + //NSLog(@"State change to %d\n", state); if (state == CONN_STATE_KO) { - [myStatusItem setImage:myStatusImageKO]; + [myStatusItem setImage:pingError]; [statusMenuItem setTitle:@"No Connection!"]; - } else if (state == CONN_STATE_OK) { - [myStatusItem setImage:myStatusImageOK]; + } else if (state <= 1) { + [myStatusItem setImage:ping1]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 2) { + [myStatusItem setImage:ping2]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 3) { + [myStatusItem setImage:ping3]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 4) { + [myStatusItem setImage:ping4]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 5) { + [myStatusItem setImage:ping5]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 6) { + [myStatusItem setImage:ping6]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 7) { + [myStatusItem setImage:ping7]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 8) { + [myStatusItem setImage:ping8]; + [statusMenuItem setTitle:@"Connection OK"]; + } else if (state == 9) { + [myStatusItem setImage:ping9]; [statusMenuItem setTitle:@"Connection OK"]; - } else if (state == CONN_STATE_SLOW) { - [myStatusItem setImage:myStatusImageSLOW]; - [statusMenuItem setTitle:@"Connection is slow"]; } connection_state = state; } diff --git a/iconping/ping_1.png b/iconping/ping_1.png new file mode 100644 index 0000000..806e1e6 Binary files /dev/null and b/iconping/ping_1.png differ diff --git a/iconping/ping_1@2x.png b/iconping/ping_1@2x.png new file mode 100644 index 0000000..68d2cb3 Binary files /dev/null and b/iconping/ping_1@2x.png differ diff --git a/iconping/ping_2.png b/iconping/ping_2.png new file mode 100644 index 0000000..6e30930 Binary files /dev/null and b/iconping/ping_2.png differ diff --git a/iconping/ping_2@2x.png b/iconping/ping_2@2x.png new file mode 100644 index 0000000..fb787d0 Binary files /dev/null and b/iconping/ping_2@2x.png differ diff --git a/iconping/ping_3.png b/iconping/ping_3.png new file mode 100644 index 0000000..10f18c5 Binary files /dev/null and b/iconping/ping_3.png differ diff --git a/iconping/ping_3@2x.png b/iconping/ping_3@2x.png new file mode 100644 index 0000000..8cfe5b9 Binary files /dev/null and b/iconping/ping_3@2x.png differ diff --git a/iconping/ping_4.png b/iconping/ping_4.png new file mode 100644 index 0000000..6aa0e79 Binary files /dev/null and b/iconping/ping_4.png differ diff --git a/iconping/ping_4@2x.png b/iconping/ping_4@2x.png new file mode 100644 index 0000000..fee02de Binary files /dev/null and b/iconping/ping_4@2x.png differ diff --git a/iconping/ping_5.png b/iconping/ping_5.png new file mode 100644 index 0000000..761a4ab Binary files /dev/null and b/iconping/ping_5.png differ diff --git a/iconping/ping_5@2x.png b/iconping/ping_5@2x.png new file mode 100644 index 0000000..ddb4619 Binary files /dev/null and b/iconping/ping_5@2x.png differ diff --git a/iconping/ping_6.png b/iconping/ping_6.png new file mode 100644 index 0000000..4086737 Binary files /dev/null and b/iconping/ping_6.png differ diff --git a/iconping/ping_6@2x.png b/iconping/ping_6@2x.png new file mode 100644 index 0000000..bfd47ab Binary files /dev/null and b/iconping/ping_6@2x.png differ diff --git a/iconping/ping_7.png b/iconping/ping_7.png new file mode 100644 index 0000000..59cf981 Binary files /dev/null and b/iconping/ping_7.png differ diff --git a/iconping/ping_7@2x.png b/iconping/ping_7@2x.png new file mode 100644 index 0000000..e59f849 Binary files /dev/null and b/iconping/ping_7@2x.png differ diff --git a/iconping/ping_8.png b/iconping/ping_8.png new file mode 100644 index 0000000..c2c64f2 Binary files /dev/null and b/iconping/ping_8.png differ diff --git a/iconping/ping_8@2x.png b/iconping/ping_8@2x.png new file mode 100644 index 0000000..cad5ce4 Binary files /dev/null and b/iconping/ping_8@2x.png differ diff --git a/iconping/ping_9.png b/iconping/ping_9.png new file mode 100644 index 0000000..b0f3b06 Binary files /dev/null and b/iconping/ping_9.png differ diff --git a/iconping/ping_9@2x.png b/iconping/ping_9@2x.png new file mode 100644 index 0000000..f977a5f Binary files /dev/null and b/iconping/ping_9@2x.png differ diff --git a/iconping/ping_error.png b/iconping/ping_error.png new file mode 100644 index 0000000..1ebd084 Binary files /dev/null and b/iconping/ping_error.png differ diff --git a/iconping/ping_error@2x.png b/iconping/ping_error@2x.png new file mode 100644 index 0000000..e55442d Binary files /dev/null and b/iconping/ping_error@2x.png differ diff --git a/iconping@2x.psd b/iconping@2x.psd new file mode 100644 index 0000000..5ecb6e6 Binary files /dev/null and b/iconping@2x.psd differ