diff --git a/Mac/Application.xib b/Mac/Application.xib old mode 100644 new mode 100755 index 8d6f282..69850e6 --- a/Mac/Application.xib +++ b/Mac/Application.xib @@ -1,8 +1,8 @@ - + - + @@ -154,19 +154,20 @@ + - + - - - + + + - + - + @@ -194,7 +195,7 @@ - + @@ -216,7 +217,7 @@ - + @@ -233,7 +234,7 @@ - + @@ -266,43 +267,67 @@ + - - - + + + - - + + - - + + + + - - - NSAllRomanInputSourcesLocaleIdentifier - + - - @@ -313,38 +338,12 @@ - + - - + @@ -365,9 +364,50 @@ + + + + + + + + + + + + + + + + + @@ -375,33 +415,40 @@ - + + + + - - + + - + - + + + + - + - + + @@ -409,6 +456,7 @@ + @@ -416,6 +464,8 @@ + + diff --git a/Mac/NWAppDelegate.m b/Mac/NWAppDelegate.m old mode 100644 new mode 100755 index d014e0c..82f9dab --- a/Mac/NWAppDelegate.m +++ b/Mac/NWAppDelegate.m @@ -23,6 +23,13 @@ @implementation NWAppDelegate { IBOutlet NSPopUpButton *_priorityPopup; IBOutlet NSScrollView *_logScroll; IBOutlet NSButton *_sanboxCheckBox; + + IBOutlet NSComboBox *_savedPayloadsCombo; + IBOutlet NSButton *_savePayloadButton; + IBOutlet NSButton *_loadPayloadButton; + + BOOL _isPayloadValidJSON; + NSDictionary *_savedPayloads; NWHub *_hub; NSDictionary *_config; @@ -48,6 +55,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification [self migrateOldConfigurationIfNeeded]; [self loadConfig]; [self updateCertificatePopup]; + [self updateSavedPayloads]; NSString *payload = [_config valueForKey:@"payload"]; _payloadField.string = payload.length ? payload : @""; @@ -91,6 +99,8 @@ - (void)textDidChange:(NSNotification *)notification - (void)controlTextDidChange:(NSNotification *)notification { // if (notification.object == _tokenCombo) [self something]; + + if (notification.object == _savedPayloadsCombo) [self updateSavedPayloadButtons]; } - (IBAction)push:(NSButton *)sender @@ -122,6 +132,8 @@ - (void)notification:(NWNotification *)notification didFailWithError:(NSError *) } - (IBAction)selectOutput:(NSSegmentedControl *)sender { + _payloadField.hidden = sender.selectedSegment != 0; + _countField.hidden = sender.selectedSegment != 0; _logScroll.hidden = sender.selectedSegment != 1; } @@ -129,6 +141,63 @@ - (IBAction)readFeedback:(id)sender { [self feedback]; } + +#pragma mark - Saved Payloads + +- (void)updateSavedPayloads +{ + NSLog(@"Update Saved Payloads Combo"); + + [_savedPayloadsCombo removeAllItems]; + _savedPayloads = [_config valueForKey:@"savedPayloads"]; + + if (!_savedPayloads) _savedPayloads = @{}; + + if (_savedPayloads.count) [_savedPayloadsCombo addItemsWithObjectValues:_savedPayloads.allKeys]; + [self updateSavedPayloadButtons]; +} + +- (void)updateSavedPayloadButtons +{ + BOOL hasPayloadKey = _savedPayloadsCombo.stringValue.length > 0; + BOOL isSavedPayload = [_savedPayloads valueForKey:_savedPayloadsCombo.stringValue] != nil; + + [_savePayloadButton setTitle: isSavedPayload ? @"Update" : @"Save"]; + _savePayloadButton.enabled = _isPayloadValidJSON && hasPayloadKey; + _loadPayloadButton.enabled = isSavedPayload && hasPayloadKey; +} + +- (IBAction)savedPayloadsComboDidChange:(NSComboBoxCell *)sender +{ + [self updateSavedPayloadButtons]; +} + +- (IBAction)loadPayload:(NSButton *)sender +{ + NSString *key = _savedPayloadsCombo.stringValue; + if (!_savedPayloads || key.length <= 0) { return; } + + NSString *value = [_savedPayloads valueForKey: key]; + _payloadField.string = value.mutableCopy; + + [self updatePayloadCounter]; +} + +- (IBAction)savePayload:(NSButton *)sender +{ + NSString *key = _savedPayloadsCombo.stringValue.mutableCopy; + NSString *value = _payloadField.string.mutableCopy; + + NSMutableDictionary *updatedPayloads = _savedPayloads.mutableCopy; + + [updatedPayloads setValue:value forKey:key]; + [_config setValue: updatedPayloads.mutableCopy forKey: @"savedPayloads"]; + + [self updateSavedPayloads]; +} + + + #pragma mark - Certificate and Identity - (void)loadCertificatesFromKeychain @@ -267,9 +336,11 @@ - (NSUInteger)selectedPriority - (void)updatePayloadCounter { NSString *payload = _payloadField.string; - BOOL isJSON = !![NSJSONSerialization JSONObjectWithData:[payload dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; - _countField.stringValue = [NSString stringWithFormat:@"%@ %lu", isJSON ? @"" : @"malformed", payload.length]; - _countField.textColor = payload.length > 256 || !isJSON ? NSColor.redColor : NSColor.darkGrayColor; + _isPayloadValidJSON = !![NSJSONSerialization JSONObjectWithData:[payload dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; + _countField.stringValue = [NSString stringWithFormat:@"%@ %lu", _isPayloadValidJSON ? @"" : @"malformed", payload.length]; + _countField.textColor = payload.length > 256 || !_isPayloadValidJSON ? NSColor.redColor : NSColor.controlTextColor; + + [self updateSavedPayloadButtons]; } - (void)upPayloadTextIndex @@ -601,7 +672,7 @@ - (void)migrateOldConfigurationIfNeeded - (void)log:(NSString *)message warning:(BOOL)warning { dispatch_async(dispatch_get_main_queue(), ^{ - _infoField.textColor = warning ? NSColor.redColor : NSColor.blackColor; + _infoField.textColor = warning ? NSColor.redColor : NSColor.controlTextColor; _infoField.stringValue = message; if (message.length) { NSDictionary *attributes = @{NSForegroundColorAttributeName: _infoField.textColor, NSFontAttributeName: [NSFont fontWithName:@"Monaco" size:10]}; diff --git a/Mac/PusherMac-Info.plist b/Mac/PusherMac-Info.plist index 9ec5853..bbe7541 100644 --- a/Mac/PusherMac-Info.plist +++ b/Mac/PusherMac-Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.7.5 + 0.7.6 CFBundleSignature ???? CFBundleVersion - 19 + 1 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/Mac/config.plist b/Mac/config.plist old mode 100644 new mode 100755 index 2e6c494..d6569b8 --- a/Mac/config.plist +++ b/Mac/config.plist @@ -15,5 +15,7 @@ ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789 my-iphone + savedPayloads +