summaryrefslogtreecommitdiff
path: root/macui
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-16 16:23:56 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-16 16:23:56 -0800
commitb4bacd50a1ae70d53d16aef6880aa1fc6870bd8c (patch)
tree21fd07022eff4a5debd4cc37da02f22660348237 /macui
parent6445337a32f5470e84bb9b139c25697e22d492f6 (diff)
parent3c248ec61a732f539dcf0c9ea3d92ae8f42b62fe (diff)
downloadinfinitytier-b4bacd50a1ae70d53d16aef6880aa1fc6870bd8c.tar.gz
infinitytier-b4bacd50a1ae70d53d16aef6880aa1fc6870bd8c.zip
Merge branch 'dev' into systemtray
Diffstat (limited to 'macui')
-rw-r--r--macui/ZeroTier One/Network.h6
-rw-r--r--macui/ZeroTier One/Network.m59
-rw-r--r--macui/ZeroTier One/ShowNetworksViewController.h2
-rw-r--r--macui/ZeroTier One/ShowNetworksViewController.m40
-rw-r--r--macui/ZeroTier One/ShowNetworksViewController.xib15
5 files changed, 111 insertions, 11 deletions
diff --git a/macui/ZeroTier One/Network.h b/macui/ZeroTier One/Network.h
index 0f3c4964..957ff8d5 100644
--- a/macui/ZeroTier One/Network.h
+++ b/macui/ZeroTier One/Network.h
@@ -59,4 +59,10 @@ enum NetworkType {
- (NSString*)statusString;
- (NSString*)typeString;
+- (BOOL)hasSameNetworkId:(UInt64)networkId;
+
+- (BOOL)isEqualToNetwork:(Network*)network;
+- (BOOL)isEqual:(id)object;
+- (NSUInteger)hash;
+
@end
diff --git a/macui/ZeroTier One/Network.m b/macui/ZeroTier One/Network.m
index 16efc6e3..8474acaa 100644
--- a/macui/ZeroTier One/Network.m
+++ b/macui/ZeroTier One/Network.m
@@ -275,4 +275,63 @@ NSString *NetworkAllowDefaultKey = @"allowDefault";
}
}
+- (BOOL)hasSameNetworkId:(UInt64)networkId
+{
+ return self.nwid == networkId;
+}
+
+- (BOOL)isEqualToNetwork:(Network*)network
+{
+ return [self.assignedAddresses isEqualToArray:network.assignedAddresses] &&
+ self.bridge == network.bridge &&
+ self.broadcastEnabled == network.broadcastEnabled &&
+ self.dhcp == network.dhcp &&
+ [self.mac isEqualToString:network.mac] &&
+ self.mtu == network.mtu &&
+ self.netconfRevision == network.netconfRevision &&
+ [self.name isEqualToString:network.name] &&
+ self.nwid == network.nwid &&
+ [self.portDeviceName isEqualToString:network.portDeviceName] &&
+ self.status == network.status &&
+ self.type == network.type &&
+ self.allowManaged == network.allowManaged &&
+ self.allowGlobal == network.allowGlobal &&
+ self.allowDefault == network.allowDefault &&
+ self.connected == network.connected;
+}
+
+- (BOOL)isEqual:(id)object
+{
+ if (self == object) {
+ return YES;
+ }
+
+ if (![object isKindOfClass:[Network class]]) {
+ return NO;
+ }
+
+ return [self isEqualToNetwork:object];
+}
+
+- (NSUInteger)hash
+{
+ return [self.assignedAddresses hash] ^
+ self.bridge ^
+ self.broadcastEnabled ^
+ self.dhcp ^
+ [self.mac hash] ^
+ self.mtu ^
+ self.netconfRevision ^
+ [self.name hash] ^
+ self.nwid ^
+ [self.portDeviceName hash] ^
+ self.portError ^
+ self.status ^
+ self.type ^
+ self.allowManaged ^
+ self.allowGlobal ^
+ self.allowDefault ^
+ self.connected;
+}
+
@end
diff --git a/macui/ZeroTier One/ShowNetworksViewController.h b/macui/ZeroTier One/ShowNetworksViewController.h
index 5c251674..6138958d 100644
--- a/macui/ZeroTier One/ShowNetworksViewController.h
+++ b/macui/ZeroTier One/ShowNetworksViewController.h
@@ -23,7 +23,7 @@
@interface ShowNetworksViewController : NSViewController<NSTableViewDelegate, NSTableViewDataSource>
-@property (nonatomic) NSArray<Network*> *networkList;
+@property (nonatomic) NSMutableArray<Network*> *networkList;
@property (nonatomic) NetworkMonitor *netMonitor;
@property (nonatomic) BOOL visible;
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];
+ }
+ }
}
}
diff --git a/macui/ZeroTier One/ShowNetworksViewController.xib b/macui/ZeroTier One/ShowNetworksViewController.xib
index f26cb446..f210d721 100644
--- a/macui/ZeroTier One/ShowNetworksViewController.xib
+++ b/macui/ZeroTier One/ShowNetworksViewController.xib
@@ -1,8 +1,9 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ShowNetworksViewController" customModule="ZeroTier_One" customModuleProvider="target">
@@ -24,7 +25,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView focusRingType="none" verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="386" rowSizeStyle="automatic" viewBased="YES" id="w5O-vn-cYB">
- <rect key="frame" x="0.0" y="0.0" width="530" height="0.0"/>
+ <rect key="frame" x="0.0" y="0.0" width="530" height="481"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.59999999999999998" colorSpace="calibratedRGB"/>
@@ -50,7 +51,7 @@
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="EUT-1A-lgY">
<rect key="frame" x="480" y="364" width="44" height="19"/>
- <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="bf8-gi-tpp">
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" title="Label" id="bf8-gi-tpp">
<font key="font" size="13" name="AndaleMono"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -242,7 +243,7 @@
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="GEJ-6D-gWU">
<rect key="frame" x="102" y="86" width="424" height="19"/>
- <textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Multiline Label" id="A3M-ZZ-6h7">
+ <textFieldCell key="cell" selectable="YES" sendsActionOnEndEditing="YES" alignment="right" title="Multiline Label" id="A3M-ZZ-6h7">
<font key="font" size="13" name="AndaleMono"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -250,7 +251,7 @@
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lO9-Jg-9f8">
<rect key="frame" x="1" y="364" width="44" height="19"/>
- <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="p7O-rs-RvR">
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" sendsActionOnEndEditing="YES" title="Label" id="p7O-rs-RvR">
<font key="font" size="13" name="AndaleMono"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>