Skip to content

Commit

Permalink
refactoring usage manager to add function when storage is almost full
Browse files Browse the repository at this point in the history
  • Loading branch information
patricioxavier8 committed Sep 5, 2024
1 parent 5d1db27 commit 034e727
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
8 changes: 7 additions & 1 deletion InternxtDesktop/Services/UsageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UsageManager: ObservableObject {
@Published var limit: Int64 = 1
@Published var driveUsage: Int64 = 0
@Published var backupsUsage: Int64 = 0

let storageThresholdPercentage: Int64 = 99
public func getUsedPercentage() -> String {
let totalUsed = driveUsage + backupsUsage
let percentage = (totalUsed * 100) / limit
Expand Down Expand Up @@ -97,4 +97,10 @@ class UsageManager: ObservableObject {
let suffix = suffixes[Int(i)]
return (numberString, suffix)
}

public func isStorageAlmostFull() -> Bool {
let totalUsed = driveUsage + backupsUsage
let percentage = (totalUsed * 100) / limit
return percentage >= storageThresholdPercentage
}
}
14 changes: 1 addition & 13 deletions InternxtDesktop/Views/Settings/AccountUsageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct AccountUsageView: View {
UsageLegendItem(label: "Drive", color: .Primary)
UsageLegendItem(label: "Backups", color: .Indigo)
}
if isStorageAlmostFull(){
if UsageManager.shared.isStorageAlmostFull(){
VStack(alignment: .leading, spacing: 8) {
HStack {
VStack{
Expand Down Expand Up @@ -164,19 +164,7 @@ struct AccountUsageView: View {
func handleOpenUpgradePlan() {
URLDictionary.UPGRADE_PLAN.open()
}

func isStorageAlmostFull() -> Bool {
let usedPercentageString = usageManager.getUsedPercentage()

guard let percentageNumber = Int(usedPercentageString.trimmingCharacters(in: .punctuationCharacters).trimmingCharacters(in: .whitespaces)) else {

return false
}

return percentageNumber >= 99
}


}

struct AccountUsageView_Previews: PreviewProvider {
Expand Down

0 comments on commit 034e727

Please sign in to comment.