summaryrefslogtreecommitdiff
path: root/macui/ZeroTier One/ShowNetworksViewController.m
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-15 16:55:24 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-15 16:55:24 -0800
commit456c7ca66117c55444631ebd706afc9f26ab2cd4 (patch)
tree0119e8ad819ff49ad925461aa51d4231f14bc3ad /macui/ZeroTier One/ShowNetworksViewController.m
parentbab75186f5538ab9a188569793d24fb393e2e078 (diff)
downloadinfinitytier-456c7ca66117c55444631ebd706afc9f26ab2cd4.tar.gz
infinitytier-456c7ca66117c55444631ebd706afc9f26ab2cd4.zip
only changed items in the full network list are updated now
Diffstat (limited to 'macui/ZeroTier One/ShowNetworksViewController.m')
-rw-r--r--macui/ZeroTier One/ShowNetworksViewController.m40
1 files changed, 37 insertions, 3 deletions
diff --git a/macui/ZeroTier One/ShowNetworksViewController.m b/macui/ZeroTier One/ShowNetworksViewController.m
index e3a1e52c..8ca32ed0 100644
--- a/macui/ZeroTier One/ShowNetworksViewController.m
+++ b/macui/ZeroTier One/ShowNetworksViewController.m
@@ -21,6 +21,17 @@
#import "NetworkInfoCell.h"
#import "Network.h"
+BOOL hasNetworkWithID(NSArray<Network*> *list, UInt64 nwid)
+{
+ for(Network *n in list) {
+ if(n.nwid == nwid) {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
@interface ShowNetworksViewController ()
@end
@@ -30,6 +41,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
+ self.networkList = [NSMutableArray array];
+
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
[self.tableView setBackgroundColor:[NSColor clearColor]];
@@ -50,9 +63,30 @@
}
- (void)setNetworks:(NSArray<Network *> *)list {
- _networkList = list;
- if(_visible) {
- [_tableView reloadData];
+ for (Network *n in list) {
+ if ([_networkList containsObject:n]) {
+ // don't need to do anything here. Already an identical object in the list
+ continue;
+ }
+ else {
+ // network not in the list based on equality. Did an object change? or is it a new item?
+ if (hasNetworkWithID(_networkList, n.nwid)) {
+
+ for (int i = 0; i < [_networkList count]; ++i) {
+ Network *n2 = [_networkList objectAtIndex:i];
+ if (n.nwid == n2.nwid)
+ {
+ [_networkList replaceObjectAtIndex:i withObject:n];
+ [_tableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:i]
+ columnIndexes:[NSIndexSet indexSetWithIndex:0]];
+ }
+ }
+ }
+ else {
+ [_networkList addObject:n];
+ [_tableView reloadData];
+ }
+ }
}
}