Skip to content

Commit

Permalink
fix(nettop): make the nettop-line more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
foamzou committed Jul 10, 2021
1 parent 51d415a commit a876f20
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions ITrafficMonitorForMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
CODE_SIGN_ENTITLEMENTS = ITrafficMonitorForMac/ITrafficMonitorForMac.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_ASSET_PATHS = "\"ITrafficMonitorForMac/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = ITrafficMonitorForMac/Info.plist;
Expand All @@ -364,7 +364,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.1.3;
MARKETING_VERSION = 0.1.4;
PRODUCT_BUNDLE_IDENTIFIER = com.foamzou.ITrafficMonitorForMac;
PRODUCT_NAME = ITraffic;
SWIFT_VERSION = 5.0;
Expand All @@ -379,7 +379,7 @@
CODE_SIGN_ENTITLEMENTS = ITrafficMonitorForMac/ITrafficMonitorForMac.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_ASSET_PATHS = "\"ITrafficMonitorForMac/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = ITrafficMonitorForMac/Info.plist;
Expand All @@ -388,7 +388,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.1.3;
MARKETING_VERSION = 0.1.4;
PRODUCT_BUNDLE_IDENTIFIER = com.foamzou.ITrafficMonitorForMac;
PRODUCT_NAME = ITraffic;
SWIFT_VERSION = 5.0;
Expand Down
10 changes: 2 additions & 8 deletions ITrafficMonitorForMac/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class Network {
task.executableURL = URL(fileURLWithPath: "/bin/bash")
task.arguments = ["-c"] + args

var firstLoad = true
var buffer = Data()
let outHandle = pipe.fileHandleForReading
var str = ""
Expand All @@ -112,14 +111,9 @@ class Network {
str = String(data: buffer, encoding: String.Encoding.utf8) ?? ""
if str.last?.isNewline == true {
buffer.removeAll()
// There is wrong info when first load, skip it
if (firstLoad) {
firstLoad = false
} else {
onData?(str)
}
onData?(str)
}
outHandle.waitForDataInBackgroundAndNotify() // todo memory leak here. Maybe should restart the sub-process in a while
outHandle.waitForDataInBackgroundAndNotify() // todo it seems that memory leak here. Not sure how to fix it now.
} else {
buffer.removeAll()
}
Expand Down
Binary file modified ITrafficMonitorForMac/dependence-resource/nettop-line
Binary file not shown.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
Monitor for displaying process traffic on Mac Status bar

## MacOS version required
The macOS version should >= 10.15, since the project use swiftui `View`
The macOS version should >= 10.15, since the project use swiftUI

## Feature
1. Show network speed by process
2. Adapt dark mode
3. Use nettop's delta mode to make statistics more accurate

## Install
One of the following way is fine

1. Download the zip file from [the latest page](https://github.com/foamzou/ITraffic-monitor-for-mac/releases/latest)
2. Use Homebrew: `brew install itraffic`

## Snapshot
<img src="./snapshot.png" width="600" />

## Thanks
- [eul](https://github.com/gao-sun/eul): Use some code of the project Coz I'm a newer of swift

0 comments on commit a876f20

Please sign in to comment.