Skip to content

Commit

Permalink
Rule's UI improvements
Browse files Browse the repository at this point in the history
improved rule adding logic
improved sort / filter logic / UI
  • Loading branch information
objective-see committed Aug 31, 2024
1 parent 39c3352 commit c75f420
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 71 deletions.
9 changes: 1 addition & 8 deletions LuLu/App/AddRuleWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ -(IBAction)addButtonHandler:(id)sender
//(remote) endpoint addr
NSString* endpointPort = nil;

//type
NSNumber* type = nil;

//action
NSNumber* action = nil;

Expand Down Expand Up @@ -341,10 +338,6 @@ -(IBAction)addButtonHandler:(id)sender
goto bail;
}

//init type
// existing rule? use that type, otherwise default to 'user'
type = (nil != self.rule) ? self.rule.type : @RULE_TYPE_USER;

//set action
action = (self.blockButton.state == NSControlStateValueOn) ? @RULE_STATE_BLOCK : @RULE_STATE_ALLOW;

Expand All @@ -353,7 +346,7 @@ -(IBAction)addButtonHandler:(id)sender
KEY_ENDPOINT_ADDR:endpointAddr,
KEY_ENDPOINT_ADDR_IS_REGEX:endpointAddrRegex,
KEY_ENDPOINT_PORT:endpointPort,
KEY_TYPE:type,
KEY_TYPE:@RULE_TYPE_USER,
KEY_ACTION:action};

//ok happy
Expand Down
4 changes: 1 addition & 3 deletions LuLu/App/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="0od-m3-GN5"/>
<menuItem title="Settings..." tag="107" id="4Uv-rm-VzQ">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Settings..." tag="107" keyEquivalent="," id="4Uv-rm-VzQ"/>
<menuItem title="Network Monitor..." tag="108" id="VuY-Sy-392" userLabel="Network Monitor...">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
Expand Down
20 changes: 12 additions & 8 deletions LuLu/App/PrefsWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,18 @@ -(IBAction)check4Update:(id)sender
//init update obj
update = [[Update alloc] init];

//check for update
// 'updateResponse newVersion:' method will be called when check is done
[update checkForUpdate:^(NSUInteger result, NSString* newVersion) {

//process response
[self updateResponse:result newVersion:newVersion];

}];
//check
// but after a delay for UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.75 * NSEC_PER_SEC), dispatch_get_main_queue(),
^{
//check for update
[update checkForUpdate:^(NSUInteger result, NSString* newVersion) {

//process response
[self updateResponse:result newVersion:newVersion];

}];
});

return;
}
Expand Down
109 changes: 59 additions & 50 deletions LuLu/App/RulesWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#import "AddRuleWindowController.h"
#import "3rd-party/OrderedDictionary.h"

#define SORT_DESCRIPTOR_COLUMN_0 @"sort_0"

/* GLOBALS */

//log handle
Expand Down Expand Up @@ -67,8 +69,6 @@ -(void)configure
// get rules and listen for new ones
-(void)windowDidLoad
{
NSSortDescriptor* sortDescriptor = nil;

//set default rule's view
self.selectedRuleView = RULE_TYPE_ALL;

Expand All @@ -87,17 +87,14 @@ -(void)windowDidLoad
//set overlay's view material
self.loadingRules.material = NSVisualEffectMaterialHUDWindow;

//set table header
//set initial table header
self.outlineView.tableColumns.firstObject.headerCell.stringValue = NSLocalizedString(@"All Rules",@"All Rules");

//init sort descriptor
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sort" ascending:YES];

//set sort descriptor
[self.outlineView.tableColumns.firstObject setSortDescriptorPrototype:sortDescriptor];
//set sort descriptor for first column
[self.outlineView.tableColumns[0] setSortDescriptorPrototype:[[NSSortDescriptor alloc] initWithKey:SORT_DESCRIPTOR_COLUMN_0 ascending:YES]];

//set it to whole too...
[self.outlineView setSortDescriptors:@[sortDescriptor]];
[self.outlineView setSortDescriptors:@[self.outlineView.tableColumns[0].sortDescriptorPrototype]];

//set flag
self.isAscending = YES;
Expand Down Expand Up @@ -202,7 +199,6 @@ -(void)update
//selected row
__block NSInteger selectedRow = -1;

//TODO: (reselect)
//item's (new?) row
//__block NSInteger itemRow = -1;

Expand Down Expand Up @@ -267,9 +263,6 @@ -(void)update
// just default to select last row...
selectedRow = MIN(selectedRow, (self.outlineView.numberOfRows-1));

//TODO: rem
//os_log_debug(logHandle, "selected row: %ld", selectedRow);

//(re)select & scroll
dispatch_async(dispatch_get_main_queue(),
^{
Expand Down Expand Up @@ -333,7 +326,7 @@ -(IBAction)rulesViewSelectorHandler:(id)sender {

case RULE_TYPE_RECENT:

self.outlineView.tableColumns.firstObject.headerCell.stringValue = NSLocalizedString(@"Added in last 24 hours", @"Added in last 24 hours");
self.outlineView.tableColumns.firstObject.headerCell.stringValue = NSLocalizedString(@"Added in last 24 hours (sorted by creation time)", @"Added in last 24 hours (sorted by creation time)");
break;


Expand Down Expand Up @@ -538,19 +531,14 @@ -(IBAction)addRule:(id)sender
// save path, and toggle to user tab
if(nil == rule)
{
//TODO:
//user tab
//self.toolbar.selectedItemIdentifier = @"user";

//save into iVar
// allows table to select/scroll to this new rule
self.addedRule = self.addRuleWindowController.info[KEY_PATH];
}

//reload
[self loadRules];

} //NSModalResponseOK
[self loadRules];
}

//unset add rule window controller
self.addRuleWindowController = nil;
Expand All @@ -563,7 +551,7 @@ -(IBAction)addRule:(id)sender
}

//init array of filtered rules
// determines what toolbar item is selected, then sort based on that and also what's in search box
// determines what rule view is selected, then sort based on that and also what's in search box
-(OrderedDictionary*)filter
{
//filtered items
Expand Down Expand Up @@ -616,10 +604,16 @@ -(OrderedDictionary*)filter
// add any that match rule view and filter string
{[self.rules enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL* stop) {

//match
BOOL match = NO;

//item
// cs info, rules, etc
NSMutableDictionary* item = nil;

//item's rules
NSArray* itemRules = nil;

//(item') recent rules
NSMutableArray* recentRules = nil;

Expand All @@ -629,24 +623,47 @@ -(OrderedDictionary*)filter
//make copy
item = [value mutableCopy];

//not on 'all'/'recent' tab?
//item's rules
itemRules = item[KEY_RULES];

//init
matchedRules = [NSMutableArray array];

//not on 'all'/'recent' view?
// skip rules if they don't match selected toolbar type
if( (RULE_TYPE_ALL != self.selectedRuleView) &&
(RULE_TYPE_RECENT != self.selectedRuleView) )
{
//skip if mismatch between selected rule view/rule tpye
if(self.selectedRuleView != ((Rule*)[value[KEY_RULES] firstObject]).type.intValue)
//check all item's rule for match
for(Rule* itemRule in itemRules)
{
//match?
if(self.selectedRuleView == itemRule.type.intValue)
{
//add
[matchedRules addObject:itemRule];
}
}

//done if no item rules match
if(0 == matchedRules.count)
{
//skip
return;
}

//update
item[KEY_RULES] = [matchedRules mutableCopy];

//reset
// as we reuse this in filtering
[matchedRules removeAllObjects];
}

//recent?
if(RULE_TYPE_RECENT == self.selectedRuleView)
{
//get (item's) recent rules
recentRules = [self recentRules:value[KEY_RULES]];
recentRules = [self recentRules:itemRules];

//item doesn't have any recent rules
if(0 == recentRules.count)
Expand All @@ -673,10 +690,7 @@ -(OrderedDictionary*)filter
return;
}

/* now filter */

//init matched (process) rules
matchedRules = [NSMutableArray array];
/* NOW FILTER */

//check each rule(s) on filter string
for(Rule* rule in item[KEY_RULES])
Expand Down Expand Up @@ -1040,27 +1054,22 @@ -(void)outlineView:(NSOutlineView *)outlineView sortDescriptorsDidChange:(NSArra
//dbg msg
os_log_debug(logHandle, "method '%s' invoked", __PRETTY_FUNCTION__);

//only sort on first column
if(YES != [outlineView.sortDescriptors.firstObject.key isEqualToString:@"sort"])
//only sort first column: rule name
if(YES == [outlineView.sortDescriptors.firstObject.key isEqualToString:SORT_DESCRIPTOR_COLUMN_0])
{
//ignore
goto bail;
}

//reverse
[self.rules reverse];

//toggle
self.isAscending = !self.isAscending;

//unselect row
// want top row to be selected after reverse
[self.outlineView deselectAll:nil];
//reverse
[self.rules reverse];

//toggle
self.isAscending = !self.isAscending;

//unselect row
// want top row to be selected after reverse
[self.outlineView deselectAll:nil];

//refresh table
[self update];

bail:
//refresh table
[self update];
}

return;
}
Expand Down
4 changes: 2 additions & 2 deletions LuLu/Shared/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@
}
}
},
"Added in last 24 hours" : {
"comment" : "Added in last 24 hours"
"Added in last 24 hours (sorted by creation time)" : {
"comment" : "Added in last 24 hours (sorted by creation time)"
},
"All Rules" : {
"comment" : "All Rules",
Expand Down

0 comments on commit c75f420

Please sign in to comment.