Skip to content

Commit

Permalink
Add an option for inverse percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianValente committed Apr 29, 2019
1 parent a650728 commit a230ed9
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 204 deletions.
8 changes: 4 additions & 4 deletions Time Progress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
38EFF300D3A93D86029E27A1 /* Pods_Time_Progress.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0350F8373A666A8FFF9E65B2 /* Pods_Time_Progress.framework */; };
4A21BFFB21A3D38000BDC4F9 /* NSButtonLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A21BFFA21A3D38000BDC4F9 /* NSButtonLabel.swift */; };
4A6E5A1521A4EEF9000FFA44 /* DateExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A6E5A1421A4EEF9000FFA44 /* DateExtensions.swift */; };
4AE37AE621ADFB0400FFF909 /* CustomDeadline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE37AE521ADFB0400FFF909 /* CustomDeadline.swift */; };
4AE37AE621ADFB0400FFF909 /* Deadline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE37AE521ADFB0400FFF909 /* Deadline.swift */; };
4AF1127321A2B515005619FB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AF1127221A2B515005619FB /* AppDelegate.swift */; };
4AF1127521A2B515005619FB /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AF1127421A2B515005619FB /* Preferences.swift */; };
4AF1127721A2B516005619FB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4AF1127621A2B516005619FB /* Assets.xcassets */; };
Expand All @@ -27,7 +27,7 @@
4A8B4B6B21A64E21001DDC41 /* LaunchAtLogin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LaunchAtLogin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4A8B4B6D21A64EAF001DDC41 /* LaunchAtLogin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LaunchAtLogin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4ACCB55D21A6500E002F3D90 /* LaunchAtLogin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LaunchAtLogin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4AE37AE521ADFB0400FFF909 /* CustomDeadline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomDeadline.swift; sourceTree = "<group>"; };
4AE37AE521ADFB0400FFF909 /* Deadline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deadline.swift; sourceTree = "<group>"; };
4AF1126F21A2B515005619FB /* Time Progress.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Time Progress.app"; sourceTree = BUILT_PRODUCTS_DIR; };
4AF1127221A2B515005619FB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4AF1127421A2B515005619FB /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -79,7 +79,7 @@
4A6E5A1421A4EEF9000FFA44 /* DateExtensions.swift */,
4AF1127621A2B516005619FB /* Assets.xcassets */,
4AF1127821A2B517005619FB /* Main.storyboard */,
4AE37AE521ADFB0400FFF909 /* CustomDeadline.swift */,
4AE37AE521ADFB0400FFF909 /* Deadline.swift */,
4AF1127B21A2B517005619FB /* Info.plist */,
4A21BFFA21A3D38000BDC4F9 /* NSButtonLabel.swift */,
);
Expand Down Expand Up @@ -230,7 +230,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4AE37AE621ADFB0400FFF909 /* CustomDeadline.swift in Sources */,
4AE37AE621ADFB0400FFF909 /* Deadline.swift in Sources */,
4AF1127521A2B515005619FB /* Preferences.swift in Sources */,
4A6E5A1521A4EEF9000FFA44 /* DateExtensions.swift in Sources */,
4A21BFFB21A3D38000BDC4F9 /* NSButtonLabel.swift in Sources */,
Expand Down
Binary file not shown.
71 changes: 45 additions & 26 deletions Time Progress/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,56 @@ class AppDelegate: NSObject, NSApplicationDelegate {
case "year":
return "Year"
case "custom":
return CustomDeadline.name
return Deadline.name
default:
return ""
}
}

func getCurrentModeStringValue() -> String {
switch getCurrentMode() {
case "day":
return String(getDayProgressPercentage()) + "%"
case "week":
return String(getWeekProgressPercentage()) + "%"
case "month":
return String(getMonthProgressPercentage()) + "%"
case "year":
return String(getYearProgressPercentage()) + "%"
case "custom":
return CustomDeadline.stringValue
default:
return "-1%"
}
// switch getCurrentMode() {
// case "day":
// return String(getDayProgressPercentage()) + "%"
// case "week":
// return String(getWeekProgressPercentage()) + "%"
// case "month":
// return String(getMonthProgressPercentage()) + "%"
// case "year":
// return String(getYearProgressPercentage()) + "%"
// case "custom":
// return Deadline.stringValue
// default:
// return "-1%"
// }

return String(getCurrentModeValue()) + "%"
}

func getCurrentModeValue() -> Int {
var value = 69
switch getCurrentMode() {
case "day":
return getDayProgressPercentage()
value = getDayProgressPercentage()
case "week":
return getWeekProgressPercentage()
value = getWeekProgressPercentage()
case "month":
return getMonthProgressPercentage()
value = getMonthProgressPercentage()
case "year":
return getYearProgressPercentage()
case "custom":
return CustomDeadline.percentage
value = getYearProgressPercentage()
case "custom",
"deadline":
value = Deadline.percentage
default:
return 69
value = 69
}

let invert = UserDefaults.standard.bool(forKey: "settings.inversepercentage");

if (invert) {
value = 100 - value
}

return value
}

func getCurrentMode() -> String {
Expand Down Expand Up @@ -143,7 +155,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func getProgressBarVisibility() -> Bool {
return (UserDefaults.standard.object(forKey: "progressbar.visible") as? Bool) ?? true
//return (UserDefaults.standard.object(forKey: "progressbar.visible") as? Bool) ?? true
return progressBar != nil
}

func setProgressBarVisibility(bool: Bool) {
Expand All @@ -152,7 +165,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func loadProgressBarVisibility() {
if getProgressBarVisibility() && progressBar == nil {
if UserDefaults.standard.bool(forKey: "progressbar.visible") && progressBar == nil {
progressBar = ProgressBar(frame: NSRect(x: 0, y: 0, width: statusBarButton.frame.height * 1.5, height: statusBarButton.frame.height * 0.6))

progressBar!.progress = CGFloat(getYearProgressPercentage()) / 100
Expand Down Expand Up @@ -184,7 +197,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
weekMenuItem = NSMenuItem(title: "Week", action: #selector(setMode), keyEquivalent: "");
monthMenuItem = NSMenuItem(title: "Month", action: #selector(setMode), keyEquivalent: "");
yearMenuItem = NSMenuItem(title: "Year", action: #selector(setMode), keyEquivalent: "");
customMenuItem = NSMenuItem(title: CustomDeadline.name, action: #selector(setMode), keyEquivalent: "");
customMenuItem = NSMenuItem(title: Deadline.name, action: #selector(setMode), keyEquivalent: "");

dayMenuItem.identifier = NSUserInterfaceItemIdentifier("day")
weekMenuItem.identifier = NSUserInterfaceItemIdentifier("week")
Expand Down Expand Up @@ -297,7 +310,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func getWeekProgressPercentage() -> Int {
let date = Date()
let thisWeek = date.previous(.monday).midnight.timeIntervalSince1970
var thisWeek = date.previous(.monday).midnight.timeIntervalSince1970

// if today's monday
if (Calendar(identifier: .gregorian).dateComponents([.weekday], from: date).weekday == 2) {
thisWeek = date.midnight.timeIntervalSince1970
}

let nextWeek = date.next(.monday).midnight.timeIntervalSince1970
let now = date.timeIntervalSince1970

Expand Down
Loading

0 comments on commit a230ed9

Please sign in to comment.