Skip to content

Commit

Permalink
improve menu bar icon (#5), minor UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepistrol committed Nov 28, 2023
1 parent 020913d commit c1e334d
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 9 deletions.
32 changes: 32 additions & 0 deletions TimeMachineStatus/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,22 @@
}
}
},
"settings_item_boldicon" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Fettes Symbol"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Bold Icon"
}
}
}
},
"settings_item_cornerradius" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -933,6 +949,22 @@
}
}
},
"settings_item_showpercentage" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Prozent anzeigen"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Show Percentage"
}
}
}
},
"settings_item_showstatus" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Copying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ extension BackupState {
override var statusString: String {
"Copying Data"
}

override var shortStatusString: String {
"Copying"
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/FindingBackupVolume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ extension BackupState {
override var statusString: String {
"Finding Backup Volume"
}

override var shortStatusString: String {
"Finding"
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/FindingChanges.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ extension BackupState {
override var statusString: String {
"Finding Changes"
}

override var shortStatusString: String {
"Changes"
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Finishing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Finishing"
}

override var shortStatusString: String {
statusString
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Idle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ extension BackupState {
override var statusString: String {
"Idle"
}

override var shortStatusString: String {
"Idle"
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Internal/_State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ extension BackupState {
fatalError("Implement!")
}

var shortStatusString: String {
fatalError("Implement!")
}

var state: _BState {
if let phase, running {
switch phase {
Expand Down
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Mounting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Mounting Disk Image"
}

override var shortStatusString: String {
"Mounting"
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Preparing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Preparing"
}

override var shortStatusString: String {
statusString
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Starting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Starting"
}

override var shortStatusString: String {
statusString
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Stopping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Stopping"
}

override var shortStatusString: String {
statusString
}
}
}
4 changes: 4 additions & 0 deletions TimeMachineStatus/Model/BackupState/Thinning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ extension BackupState {
override var statusString: String {
"Thinning Backup Image"
}

override var shortStatusString: String {
"Thinning"
}
}
}
1 change: 1 addition & 0 deletions TimeMachineStatus/Symbols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import SwiftUI

enum Symbols: String {
case arrowTriangleCirclepath = "arrow.triangle.2.circlepath"
case checkmarkCircleFill = "checkmark.circle.fill"
case exclamationMarkTriangleFill = "exclamationmark.triangle.fill"
case externalDrive = "externaldrive.fill.badge.timemachine"
Expand Down
13 changes: 11 additions & 2 deletions TimeMachineStatus/Views/DestinationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@ struct DestinationCell: View {
utility.startBackup(id: dest.destinationID)
}
} label: {
utility.status.activeDestinationID == dest.destinationID ? Symbols.stopFill.image : Symbols.playFill.image
if utility.status.activeDestinationID == dest.destinationID {
Symbols.stopFill.image
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 13)
} else {
Symbols.playFill.image
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 13)
}
}
.imageScale(.large)
.buttonStyle(.custom)
.focusable(false)
}
Expand Down
24 changes: 21 additions & 3 deletions TimeMachineStatus/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ enum StorageKeys {
static let horizontalPadding = Key(id: "horizontalPadding", default: 0.0)
static let verticalPadding = Key(id: "verticalPadding", default: 0.0)
static let boldFont = Key(id: "boldFont", default: false)
static let showStatus = Key(id: "showStatus", default: false)
static let boldIcon = Key(id: "boldIcon", default: false)
static let showStatus = Key(id: "showStatus", default: true)
static let spacing = Key(id: "spacing", default: 4.0)
static let backgroundColor = Key(id: "backgroundColor", default: Color.clear)
static let cornerRadius = Key(id: "cornerRadius", default: 5.0)
static let showPercentage = Key(id: "showPercentage", default: true)
}

struct SettingsView: View {
Expand All @@ -39,9 +41,15 @@ struct SettingsView: View {
@AppStorage(StorageKeys.boldFont.id)
private var boldFont: Bool = StorageKeys.boldFont.default

@AppStorage(StorageKeys.boldIcon.id)
private var boldIcon: Bool = StorageKeys.boldIcon.default

@AppStorage(StorageKeys.showStatus.id)
private var showStatus: Bool = StorageKeys.showStatus.default

@AppStorage(StorageKeys.showPercentage.id)
private var showPercentage: Bool = StorageKeys.showPercentage.default

@AppStorage(StorageKeys.spacing.id)
private var spacing: Double = StorageKeys.spacing.default

Expand Down Expand Up @@ -73,7 +81,7 @@ struct SettingsView: View {
appearandeTab
aboutTab
}
.frame(width: 375, height: 420)
.frame(width: 375, height: 350)
}

private var generalTab: some View {
Expand Down Expand Up @@ -127,6 +135,8 @@ struct SettingsView: View {
} label: {
Text("settings_item_horizontalpadding")
}
}
Section {
HStack {
ColorPicker("settings_item_backgroundcolor", selection: $bgColor)
Button("settings_button_default") {
Expand All @@ -153,9 +163,15 @@ struct SettingsView: View {
Text("settings_item_cornerradius")
}
}
}
Section {
Toggle("settings_item_boldfont", isOn: $boldFont)
Toggle("settings_item_boldicon", isOn: $boldIcon)
}
Section {
Toggle("settings_item_showstatus", isOn: $showStatus)
if showStatus {
Toggle("settings_item_showpercentage", isOn: $showPercentage)
if showStatus || showPercentage {
LabeledContent {
HStack {
Text(spacing.formatted(.number) + " pt")
Expand All @@ -174,7 +190,9 @@ struct SettingsView: View {
horizontalPadding = StorageKeys.horizontalPadding.default
verticalPadding = StorageKeys.verticalPadding.default
boldFont = StorageKeys.boldFont.default
boldIcon = StorageKeys.boldIcon.default
showStatus = StorageKeys.showStatus.default
showPercentage = StorageKeys.showPercentage.default
spacing = StorageKeys.spacing.default
bgColor = StorageKeys.backgroundColor.default
cornerRadius = StorageKeys.cornerRadius.default
Expand Down
43 changes: 39 additions & 4 deletions TimeMachineStatus/Views/StatusBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ struct StatusBarItem: View {
@AppStorage(StorageKeys.boldFont.id)
private var boldFont: Bool = StorageKeys.boldFont.default

@AppStorage(StorageKeys.boldIcon.id)
private var boldIcon: Bool = StorageKeys.boldIcon.default

@AppStorage(StorageKeys.showStatus.id)
private var showStatus: Bool = StorageKeys.showStatus.default

@AppStorage(StorageKeys.showPercentage.id)
private var showPercentage: Bool = StorageKeys.showPercentage.default

@AppStorage(StorageKeys.spacing.id)
private var spacing: Double = StorageKeys.spacing.default

Expand All @@ -48,13 +54,24 @@ struct StatusBarItem: View {
var sizePassthrough: PassthroughSubject<CGSize, Never>
@ObservedObject var utility: TMUtility


private var mainContent: some View {
HStack(spacing: spacing) {
Symbols.timeMachine.image
.font(.body.weight(boldFont ? .bold : .medium))
if showStatus {
Text(utility.status.statusString)
if utility.isIdle {
Symbols.timeMachine.image
.font(.body.weight(boldIcon ? .bold : .medium))
} else {
AnimatedIcon()
.font(.body.weight(boldIcon ? .bold : .medium))
}
if showStatus, !utility.isIdle {
Text(utility.status.shortStatusString)
.font(.caption2.weight(boldFont ? .bold : .medium))
}
if let percentage = utility.status.progessPercentage, showPercentage {
Text(percentage, format: .percent.precision(.fractionLength(0)))
.font(.caption2.weight(boldFont ? .bold : .medium))
.monospacedDigit()
}
}
.foregroundStyle(.primary)
Expand All @@ -78,6 +95,24 @@ struct StatusBarItem: View {
}
.offset(y: -1)
}

struct AnimatedIcon: View {
@State private var isAnimating = false

private var rotationAnimation: Animation { .linear(duration: 2).repeatForever(autoreverses: false) }

var body: some View {
Symbols.arrowTriangleCirclepath.image
.rotationEffect(Angle(degrees: isAnimating ? 360 : 0), anchor: .center)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
withAnimation(rotationAnimation) {
isAnimating = true
}
}
}
}
}
}

#Preview {
Expand Down

0 comments on commit c1e334d

Please sign in to comment.