From 38fb2b73c24b48e9c160f4e1c675c7d0ee9682e3 Mon Sep 17 00:00:00 2001 From: Dominik H <36657497+D0miH@users.noreply.github.com> Date: Fri, 6 Dec 2019 18:39:32 +0100 Subject: [PATCH 1/5] added toggles to disable the lower and upper battery notification --- iGlance/iGlance/AppDelegate.swift | 16 +++- iGlance/iGlance/Base.lproj/Main.storyboard | 82 +++++++++---------- .../SettingsWindowViews/BatteryView.swift | 31 +++++-- 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/iGlance/iGlance/AppDelegate.swift b/iGlance/iGlance/AppDelegate.swift index e58ff03..178aba1 100644 --- a/iGlance/iGlance/AppDelegate.swift +++ b/iGlance/iGlance/AppDelegate.swift @@ -83,7 +83,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { static var userWantsCPUBorder = true static var userWantsMemBorder = true static var userWantsBatteryUtil = true - static var userWantsBatteryNotification = true + static var userWantsLowBatteryNotification = true + static var userWantsHighBatteryNotification = true static var lowerBatteryNotificationValue = 20 static var upperBatteryNotificationValue = 80 static var networkOrder = NetUsageComponent.NetworkOrder.uploadTop @@ -356,8 +357,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { if UserDefaults.standard.value(forKey: "userWantsBatteryUtil") != nil { UserSettings.userWantsBatteryUtil = UserDefaults.standard.value(forKey: "userWantsBatteryUtil") as! Bool } - if UserDefaults.standard.value(forKey: "userWantsBatteryNotification") != nil { - UserSettings.userWantsBatteryNotification = UserDefaults.standard.value(forKey: "userWantsBatteryNotification") as! Bool + if UserDefaults.standard.value(forKey: "userWantsLowBatteryNotification") != nil { + UserSettings.userWantsLowBatteryNotification = UserDefaults.standard.value(forKey: "userWantsLowBatteryNotification") as! Bool + } + if UserDefaults.standard.value(forKey: "userWantsHighBatteryNotification") != nil { + UserSettings.userWantsHighBatteryNotification = UserDefaults.standard.value(forKey: "userWantsHighBatteryNotification") as! Bool } if UserDefaults.standard.value(forKey: "lowerBatteryNotificationValue") != nil { UserSettings.lowerBatteryNotificationValue = UserDefaults.standard.value(forKey: "lowerBatteryNotificationValue") as! Int @@ -428,7 +432,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { } else { BatteryComponent.sItemBattery.isVisible = false } - if AppDelegate.UserSettings.userWantsBatteryNotification { + if AppDelegate.UserSettings.userWantsLowBatteryNotification { + // notify the user if needed + AppDelegate.myBattery.notifyUser() + } + if AppDelegate.UserSettings.userWantsHighBatteryNotification { // notify the user if needed AppDelegate.myBattery.notifyUser() } diff --git a/iGlance/iGlance/Base.lproj/Main.storyboard b/iGlance/iGlance/Base.lproj/Main.storyboard index 380ff8f..75e254e 100644 --- a/iGlance/iGlance/Base.lproj/Main.storyboard +++ b/iGlance/iGlance/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -721,19 +721,8 @@ - - + @@ -745,17 +734,28 @@ - - + + - + + - + @@ -767,26 +767,8 @@ - - - - - - - - - - - - - - - - - - - + @@ -794,11 +776,23 @@ + - + + @@ -848,7 +842,7 @@ - + @@ -905,7 +899,7 @@ - + @@ -982,7 +976,7 @@ - + @@ -1026,7 +1020,7 @@ - + @@ -1198,7 +1192,7 @@ - + @@ -1312,7 +1306,7 @@ - + diff --git a/iGlance/iGlance/SettingsWindowViews/BatteryView.swift b/iGlance/iGlance/SettingsWindowViews/BatteryView.swift index e1193b4..e20cd18 100644 --- a/iGlance/iGlance/SettingsWindowViews/BatteryView.swift +++ b/iGlance/iGlance/SettingsWindowViews/BatteryView.swift @@ -42,19 +42,32 @@ class BatteryView: NSViewController { checked ? MyStatusItems.insertItem(item: MyStatusItems.StatusItems.battery) : MyStatusItems.removeItem(item: MyStatusItems.StatusItems.battery) } - // define the outlet and the action of the checkbox to enable and disable the battery notifications - @IBOutlet var cbBatteryNotification: NSButton! { + // define the outlet and the action of the checbox to enable and disable the low battery notifications + @IBOutlet weak var cbShowLowBatteryNotification: NSButton! { didSet { - cbBatteryNotification.state = AppDelegate.UserSettings.userWantsBatteryNotification ? NSButton.StateValue.on : NSButton.StateValue.off + cbShowLowBatteryNotification.state = AppDelegate.UserSettings.userWantsLowBatteryNotification ? NSButton.StateValue.on : NSButton.StateValue.off } } - - @IBAction func cbBatterNotification_clicked(_: NSButton) { - let checked = (cbBatteryNotification.state == NSButton.StateValue.on) - AppDelegate.UserSettings.userWantsBatteryNotification = checked - UserDefaults.standard.set(checked, forKey: "userWantsBatteryNotification") + + @IBAction func cbShowLowBatteryNotification(_ sender: Any) { + let checked = (cbShowLowBatteryNotification.state == NSButton.StateValue.on) + AppDelegate.UserSettings.userWantsLowBatteryNotification = checked + UserDefaults.standard.set(checked, forKey: "userWantsLowBatteryNotification") } - + + // define the outlet and the action of the checbox to enable and disable the high battery notifications + @IBOutlet weak var cbShowHighBatteryNotification: NSButton! { + didSet { + cbShowHighBatteryNotification.state = AppDelegate.UserSettings.userWantsHighBatteryNotification ? NSButton.StateValue.on : NSButton.StateValue.off + } + } + + @IBAction func cbShowHighBatteryNotification(_ sender: Any) { + let checked = (cbShowHighBatteryNotification.state == NSButton.StateValue.on) + AppDelegate.UserSettings.userWantsHighBatteryNotification = checked + UserDefaults.standard.set(checked, forKey: "userWantsHighBatteryNotification") + } + // define the outlet and the action of the textfield which sets the lower battery notification value @IBOutlet var tfLowerBatteryValue: NSTextField! { didSet { From 79c653e8ac5545f491cfa32748d1949ba160681c Mon Sep 17 00:00:00 2001 From: Dominik H <36657497+D0miH@users.noreply.github.com> Date: Fri, 27 Dec 2019 16:55:32 +0100 Subject: [PATCH 2/5] fixes #60 and #47 --- .../Components/NetUsageComponent.swift | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/iGlance/iGlance/Components/NetUsageComponent.swift b/iGlance/iGlance/Components/NetUsageComponent.swift index 94ea7ab..c6ebadc 100644 --- a/iGlance/iGlance/Components/NetUsageComponent.swift +++ b/iGlance/iGlance/Components/NetUsageComponent.swift @@ -100,10 +100,10 @@ class NetUsageComponent { * Returns a tuple with the upload and download speed in bytes. * (DownSpeed, UpSpeed) */ - func readNetUsage() -> (UInt64, UInt64) { + func readNetUsage(interface: String) -> (UInt64, UInt64) { let process = Process() process.launchPath = "/usr/bin/env" - process.arguments = ["netstat", "-bdI", "en0"] + process.arguments = ["netstat", "-bdnI", interface] let pipe = Pipe() process.standardOutput = pipe @@ -134,6 +134,24 @@ class NetUsageComponent { return (downSpeed, upSpeed) } + + /** + * Returns the name of the currently used network interface as a string. + */ + func getCurrentlyUsedNetInterface() -> String { + let process = Process() + process.launchPath = "/bin/bash" + process.arguments = ["-c", "route get 0.0.0.0 2>/dev/null | grep interface: | awk '{print $2}'"] + + let pipe = Pipe() + process.standardOutput = pipe + process.launch() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let interface = String(data: data, encoding: String.Encoding.utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) + print(interface) + return interface ?? "en0" + } /** * Returns the total amount of downloaded bytes. @@ -160,7 +178,8 @@ class NetUsageComponent { } func updateNetUsage() { - let netUsage = readNetUsage() + let currentInterface = getCurrentlyUsedNetInterface() + let netUsage = readNetUsage(interface: currentInterface) dSpeed = netUsage.0 uSpeed = netUsage.1 From 41070ca257419d314dd2f4d345850509788f9a01 Mon Sep 17 00:00:00 2001 From: Dominik H <36657497+D0miH@users.noreply.github.com> Date: Fri, 27 Dec 2019 17:01:15 +0100 Subject: [PATCH 3/5] bumped version --- Version.txt | 2 +- iGlance/iGlance.xcodeproj/project.pbxproj | 4 ++-- iGlance/iGlance/AppDelegate.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Version.txt b/Version.txt index a4ff96a..4f0c940 100644 --- a/Version.txt +++ b/Version.txt @@ -1 +1 @@ -[version]1.4.1[/version] +[version]1.4.2[/version] diff --git a/iGlance/iGlance.xcodeproj/project.pbxproj b/iGlance/iGlance.xcodeproj/project.pbxproj index 5591452..02f8bee 100644 --- a/iGlance/iGlance.xcodeproj/project.pbxproj +++ b/iGlance/iGlance.xcodeproj/project.pbxproj @@ -557,7 +557,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = io.iglance.iglance; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -582,7 +582,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = io.iglance.iglance; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/iGlance/iGlance/AppDelegate.swift b/iGlance/iGlance/AppDelegate.swift index 178aba1..9aa8655 100644 --- a/iGlance/iGlance/AppDelegate.swift +++ b/iGlance/iGlance/AppDelegate.swift @@ -53,7 +53,7 @@ extension NSColor { @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - public static var VERSION = "1.4.1" + public static var VERSION = "1.4.2" var myWindowController: MyMainWindow? From 14a624ccb2144c6d015c09346e4907b5f534d1b9 Mon Sep 17 00:00:00 2001 From: Dominik H <36657497+D0miH@users.noreply.github.com> Date: Fri, 27 Dec 2019 17:25:21 +0100 Subject: [PATCH 4/5] added option to disable "check for update on wake up" --- iGlance/iGlance/AppDelegate.swift | 8 +++++++- iGlance/iGlance/Base.lproj/Main.storyboard | 24 ++++++++++++++++------ iGlance/iGlance/ViewController.swift | 24 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/iGlance/iGlance/AppDelegate.swift b/iGlance/iGlance/AppDelegate.swift index 9aa8655..b0d9f9d 100644 --- a/iGlance/iGlance/AppDelegate.swift +++ b/iGlance/iGlance/AppDelegate.swift @@ -70,6 +70,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { static var userWantsCPUUtil = false static var userWantsCPUTemp = false static var userWantsAutostart = false + static var userWantsCheckForUpdateOnWake = true static var cpuColor = NSColor.green static var cpuColor2 = NSColor.red static var cpuUsageVisualization = VisualizationType.Bar @@ -192,7 +193,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { @objc func wakeUpListener(note: NSNotification) { - checkForUpdate() + if UserSettings.userWantsCheckForUpdateOnWake { + checkForUpdate() + } } func matches(for regex: String, in text: String) -> [String] { @@ -334,6 +337,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { if UserDefaults.standard.value(forKey: "userWantsAutostart") != nil { UserSettings.userWantsAutostart = UserDefaults.standard.value(forKey: "userWantsAutostart") as! Bool } + if UserDefaults.standard.value(forKey: "userWantsCheckForUpdateOnWake") != nil { + UserSettings.userWantsCheckForUpdateOnWake = UserDefaults.standard.value(forKey: "userWantsCheckForUpdateOnWake") as! Bool + } if UserDefaults.standard.value(forKey: "updateInterval") != nil { UserSettings.updateInterval = UserDefaults.standard.value(forKey: "updateInterval") as! Double } diff --git a/iGlance/iGlance/Base.lproj/Main.storyboard b/iGlance/iGlance/Base.lproj/Main.storyboard index 75e254e..232a287 100644 --- a/iGlance/iGlance/Base.lproj/Main.storyboard +++ b/iGlance/iGlance/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -874,15 +874,15 @@ - @@ -928,11 +928,23 @@ + + diff --git a/iGlance/iGlance/ViewController.swift b/iGlance/iGlance/ViewController.swift index 81c94b6..9fd6142 100644 --- a/iGlance/iGlance/ViewController.swift +++ b/iGlance/iGlance/ViewController.swift @@ -85,6 +85,30 @@ class ViewController: NSViewController { } } } + + @IBOutlet var cbCheckForUpdatesOnWake: NSButton! { + didSet { + cbCheckForUpdatesOnWake.state = (AppDelegate.UserSettings.userWantsCheckForUpdateOnWake) ? NSButton.StateValue.on : NSButton.StateValue.off + } + } + + @IBAction func cbCheckForUpdatesOnWake_clicked(_ sender: Any) { + AppDelegate.UserSettings.userWantsCheckForUpdateOnWake = (cbCheckForUpdatesOnWake.state == NSButton.StateValue.on) + if cbCheckForUpdatesOnWake.state == NSButton.StateValue.on { + if !SMLoginItemSetEnabled(NCConstants.launcherApplicationIdentifier as CFString, true) { + _ = AppDelegate.dialogOK(question: "Error", text: "Something went wrong, sorry") + cbCheckForUpdatesOnWake.state = NSButton.StateValue.off + } else { + UserDefaults.standard.set(true, forKey: "userWantsCheckForUpdateOnWake") + } + } else { + if !SMLoginItemSetEnabled(NCConstants.launcherApplicationIdentifier as CFString, false) { + _ = AppDelegate.dialogOK(question: "Error", text: "Something went wrong, sorry") + } else { + UserDefaults.standard.set(false, forKey: "userWantsCheckForUpdateOnWake") + } + } + } // define the outlet to the logo @IBOutlet var imgLogo: NSImageView! { From 4830dca9fa18a12a75fb287425d8687a6b66b9c9 Mon Sep 17 00:00:00 2001 From: Dominik H <36657497+D0miH@users.noreply.github.com> Date: Fri, 27 Dec 2019 17:34:17 +0100 Subject: [PATCH 5/5] removed print statement --- iGlance/iGlance/Components/NetUsageComponent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iGlance/iGlance/Components/NetUsageComponent.swift b/iGlance/iGlance/Components/NetUsageComponent.swift index c6ebadc..e568ae3 100644 --- a/iGlance/iGlance/Components/NetUsageComponent.swift +++ b/iGlance/iGlance/Components/NetUsageComponent.swift @@ -149,7 +149,7 @@ class NetUsageComponent { let data = pipe.fileHandleForReading.readDataToEndOfFile() let interface = String(data: data, encoding: String.Encoding.utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) - print(interface) + return interface ?? "en0" }