Skip to content

Commit

Permalink
update to v1.2
Browse files Browse the repository at this point in the history
improve stability.
now has dropdown menu showing speed of multiple apps.
  • Loading branch information
Liu, Tao committed Sep 12, 2020
1 parent 9909445 commit 3211169
Show file tree
Hide file tree
Showing 8 changed files with 666 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.DS_Store
NeTool.xcodeproj/project.xcworkspace/xcuserdata/

NeTool.xcodeproj/xcuserdata/
12 changes: 12 additions & 0 deletions NeTool.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
7A431F392508E1D20050327A /* SpeedInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A431F382508E1D20050327A /* SpeedInfoView.swift */; };
7A431F3B2509BDFA0050327A /* SpeedInfoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7A431F3A2509BDFA0050327A /* SpeedInfoView.xib */; };
7A6E0090214CBD690020ED6D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A6E008F214CBD690020ED6D /* AppDelegate.swift */; };
7A6E0092214CBD690020ED6D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A6E0091214CBD690020ED6D /* ViewController.swift */; };
7A6E0094214CBD6A0020ED6D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7A6E0093214CBD6A0020ED6D /* Assets.xcassets */; };
Expand Down Expand Up @@ -35,6 +37,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
7A431F382508E1D20050327A /* SpeedInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeedInfoView.swift; sourceTree = "<group>"; };
7A431F3A2509BDFA0050327A /* SpeedInfoView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SpeedInfoView.xib; sourceTree = "<group>"; };
7A6E008C214CBD690020ED6D /* NeTool.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NeTool.app; sourceTree = BUILT_PRODUCTS_DIR; };
7A6E008F214CBD690020ED6D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7A6E0091214CBD690020ED6D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,6 +112,8 @@
7A6E0099214CBD6A0020ED6D /* NeTool.entitlements */,
7A6E00BB214CBD9B0020ED6D /* StatusBarView.swift */,
7A6E00BD214CDDA30020ED6D /* NetSpeedMonitor.swift */,
7A431F382508E1D20050327A /* SpeedInfoView.swift */,
7A431F3A2509BDFA0050327A /* SpeedInfoView.xib */,
);
path = NeTool;
sourceTree = "<group>";
Expand Down Expand Up @@ -240,6 +246,7 @@
buildActionMask = 2147483647;
files = (
7A6E0094214CBD6A0020ED6D /* Assets.xcassets in Resources */,
7A431F3B2509BDFA0050327A /* SpeedInfoView.xib in Resources */,
7A6E0097214CBD6A0020ED6D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -267,6 +274,7 @@
files = (
7A6E00BC214CBD9B0020ED6D /* StatusBarView.swift in Sources */,
7A6E0092214CBD690020ED6D /* ViewController.swift in Sources */,
7A431F392508E1D20050327A /* SpeedInfoView.swift in Sources */,
7A6E0090214CBD690020ED6D /* AppDelegate.swift in Sources */,
7A6E00BE214CDDA30020ED6D /* NetSpeedMonitor.swift in Sources */,
);
Expand Down Expand Up @@ -434,12 +442,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
INFOPLIST_FILE = NeTool/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = MicroStrategy.NeTool;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -452,12 +462,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
INFOPLIST_FILE = NeTool/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = MicroStrategy.NeTool;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
41 changes: 35 additions & 6 deletions NeTool/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,54 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

let view: StatusBarView
let speedMonitor: NetSpeedMonitor

override init() {
let statusItem = NSStatusBar.system.statusItem(withLength: 72)
let menu = NSMenu()

// the menu item to show apps with top net speed (sum of upload and download)
let menuItem = NSMenuItem()
menuItem.view = SpeedInfoView()
menu.addItem(menuItem)

// the menu item to quit app.
menu.addItem(withTitle: "Quit NeTool", action: #selector(menuItemQuitClick), keyEquivalent: "q")

view = StatusBarView(statusItem: statusItem, menu: menu)
statusItem.view = view
// the view for menuBar icon
let menuBarIconView = StatusBarView(statusItem: statusItem, menu: menu)
statusItem.view = menuBarIconView

// logic class to monitor net speed.
speedMonitor = NetSpeedMonitor(statusBarView: menuBarIconView, speedInfoView: menuItem.view as! SpeedInfoView)
menuBarIconView.speedMonitor = speedMonitor
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
NetSpeedMonitor(statusBarView: view).startMonitor()
//
speedMonitor.start()

// observer event of system sleep and wake.
// we would pause monitoring on sleep, and resume monitoring on wake.
NSWorkspace.shared.notificationCenter.addObserver(
self, selector: #selector(onWake(notification:)),
name: NSWorkspace.didWakeNotification, object: nil)

NSWorkspace.shared.notificationCenter.addObserver(
self, selector: #selector(onSleep(notification:)),
name: NSWorkspace.willSleepNotification, object: nil)
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application

}

@objc func onSleep(notification: NSNotification) {
speedMonitor.stop()
}

@objc func onWake(notification: NSNotification) {
speedMonitor.start()
}
}

Expand Down
4 changes: 2 additions & 2 deletions NeTool/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
Loading

0 comments on commit 3211169

Please sign in to comment.