This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WeightlifterKeyframes { | |
var verticalScale: Double = 1.0 | |
var verticalOffset: Double = 0.0 | |
} | |
private var weightlifterAnimation: some View { | |
Image(systemName: "figure.strengthtraining.traditional") | |
.resizable() | |
.foregroundStyle(.white) | |
.frame(width: 200, height: 200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Gets current memory usage information for the app's memory footprint | |
/// Returns tuple with bytes used, total bytes available, and usage in MB | |
/// Uses task_vm_info to get accurate app-specific memory usage | |
func getMemoryUsage() -> (used: UInt64, total: UInt64, usedMB: Double) { | |
var taskInfo = task_vm_info_data_t() | |
var count = mach_msg_type_number_t(MemoryLayout<task_vm_info>.size) | |
let result: kern_return_t = withUnsafeMutablePointer( | |
to: &taskInfo | |
) { | |
$0.withMemoryRebound(to: integer_t.self, capacity: 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Gets current CPU usage percentage for the current app's threads | |
/// Returns a value between 0.0 and 100.0 representing CPU utilization | |
/// Uses thread-specific CPU usage tracking for accurate app performance metrics | |
func getCPUUsage() -> Double { | |
var totalUsageOfCPU = 0.0 | |
var threadsList = UnsafeMutablePointer(mutating: [thread_act_t]()) | |
var threadsCount = mach_msg_type_number_t(0) | |
let threadsResult = withUnsafeMutablePointer(to: &threadsList) { | |
$0.withMemoryRebound(to: thread_act_array_t?.self, capacity: 1) { | |
task_threads(mach_task_self_, $0, &threadsCount) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let thermalRating = switch ProcessInfo.processInfo.thermalState { | |
case .nominal: | |
return 0 | |
case .fair: | |
return 1 | |
/// System performance may be impacted. | |
/// Reduce CPU, GPU, I/O, and visual effects if possible. | |
case .serious: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Mixpanel | |
final class MixpanelAnalyticsService: AnalyticsService { | |
func track(event: String, properties: [String: Any]? = nil) { | |
var enrichedProperties = performanceService.getAllMetrics() | |
if let customProperties = properties { | |
enrichedProperties.merge(customProperties) { (_, new) in new } | |
} | |
let mixpanelProperties = enrichedProperties.compactMapValues { $0 as? MixpanelType } | |
mixpanelInstance.track(event: event, properties: mixpanelProperties) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol AnalyticsService { | |
func track(event: String, properties: [String: Any]?) | |
func identifyUser(userId: String, properties: [String: Any]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let thermalRating = switch ProcessInfo.processInfo.thermalState { | |
case .nominal: | |
return 0 | |
case .fair: | |
return 1 | |
/// System performance may be impacted. | |
/// Reduce CPU, GPU, I/O, and visual effects if possible. | |
case .serious: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func scheduleCountdownAlarm() async throws { | |
let stopButton = AlarmButton( | |
text: "Mmm, Elvanse", | |
textColor: .white, | |
systemImageName: "checkmark.seal.fill" | |
) | |
let repeatButton = AlarmButton( | |
text: "I forgot", | |
textColor: .red, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func scheduleAlarm(at schedule: Alarm.Schedule) async throws { | |
// primary action button, that stops the alarm | |
let stopButton = AlarmButton( | |
text: "Mmm, Elvanse", | |
textColor: .white, | |
systemImageName: "checkmark.circle" | |
) | |
// what gets presented by the alarm - wraps the button | |
let alertPresentation = AlarmPresentation.Alert( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setStandupAlarm() async throws { | |
let schedule = Alarm.Schedule.relative(Alarm.Schedule.Relative( | |
time: Alarm.Schedule.Relative.Time(hour: 10, minute: 0), | |
repeats: Alarm.Schedule.Relative.Recurrence.weekly( | |
[.monday, .tuesday, .wednesday, .thursday, .friday] | |
)) | |
) | |
try await scheduleAlarm(at: schedule) | |
} |