Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Monitor9// File : App/Sources/Features/SettingsView.swift10// Description : Settings window: general, sampling, history and retention,11// menu bar, privacy and about.12// Module : Features13// Repository : https://git.spboucher.ai/orix-monitor14// Created : 2026-11-2115// Last Modified : 2026-11-2116//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : Proprietary, all rights reserved (see license file)82// License File : LICENSE83// Maintainer : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import ORIXMonitorCore91import SwiftUI9293struct SettingsView: View {94 var body: some View {95 TabView {96 GeneralSettings().tabItem { Label("General", systemImage: "gearshape") }97 SamplingSettings().tabItem { Label("Sampling", systemImage: "waveform.path.ecg") }98 HistorySettings().tabItem { Label("History", systemImage: "clock.arrow.circlepath") }99 MenuBarSettings().tabItem { Label("Menu Bar", systemImage: "menubar.rectangle") }100 PrivacySettings().tabItem { Label("Privacy", systemImage: "hand.raised") }101 AboutSettings().tabItem { Label("About", systemImage: "info.circle") }102 }103 .frame(width: 600, height: 520)104 .accessibilityIdentifier("settings")105 }106}107108private struct GeneralSettings: View {109 @Environment(MonitorModel.self) private var model110 @Environment(AppSettings.self) private var settings111112 var body: some View {113 @Bindable var settings = settings114 Form {115 Section("Appearance") {116 Picker("Appearance", selection: $settings.appearance) {117 Text("Match System").tag(AppearanceChoice.system)118 Text("Light").tag(AppearanceChoice.light)119 Text("Dark").tag(AppearanceChoice.dark)120 }121 Picker("Density", selection: $settings.density) {122 Text("Compact").tag(DensityChoice.compact)123 Text("Regular").tag(DensityChoice.regular)124 Text("Comfortable").tag(DensityChoice.comfortable)125 }126 Toggle("Colour-blind-safe chart colours", isOn: $settings.colorBlindSafe)127 Text("Uses the Okabe–Ito palette. Charts always carry labels and legends as well, so colour is never the only cue.").font(.caption).foregroundStyle(.secondary)128 }129 Section("Startup") {130 Toggle("Open ORIX Monitor at login", isOn: Binding(get: { model.launchAtLogin }, set: { model.launchAtLogin = $0 }))131 Text("History is only recorded while ORIX Monitor is running.").font(.caption).foregroundStyle(.secondary)132 }133 }134 .formStyle(.grouped)135 }136}137138private struct SamplingSettings: View {139 @Environment(MonitorModel.self) private var model140 @Environment(AppSettings.self) private var settings141142 var body: some View {143 @Bindable var settings = settings144 Form {145 Section("Intervals") {146 slider("While a window is visible", value: $settings.telemetry.interval, range: 1...10)147 slider("Menu bar only", value: $settings.telemetry.backgroundInterval, range: 2...30)148 slider("Process list", value: $settings.telemetry.processInterval, range: 2...30)149 slider("Volumes and battery", value: $settings.telemetry.slowInterval, range: 10...120)150 Toggle("Halve the sampling rate on battery and in Low Power Mode", isOn: $settings.telemetry.batterySaver)151 if let s = model.snapshot {152 LabeledContent("Interval in force now", value: "\(model.format.number(s.interval, digits: 1)) s")153 }154 }155 Section("Best-effort readings") {156 Toggle("Read undocumented system properties", isOn: $settings.telemetry.bestEffortMetrics)157 Text("GPU utilization and battery detail (cycle count, capacity, power flow) are read through a public API from properties whose names Apple does not document. They are always labelled “Best effort”. Turn this off to show only documented values.")158 .font(.caption).foregroundStyle(.secondary)159 }160 }161 .formStyle(.grouped)162 .onChange(of: settings.telemetry) { _, _ in model.applySettings() }163 }164165 private func slider(_ title: LocalizedStringKey, value: Binding<Double>, range: ClosedRange<Double>) -> some View {166 LabeledContent(title) {167 HStack {168 Slider(value: value, in: range, step: 1).frame(width: 190)169 Text("\(Int(value.wrappedValue)) s").monospacedDigit().frame(width: 44, alignment: .trailing)170 }171 }172 }173}174175private struct HistorySettings: View {176 @Environment(MonitorModel.self) private var model177 @Environment(AppSettings.self) private var settings178 @State private var confirmErase = false179180 var body: some View {181 @Bindable var settings = settings182 Form {183 Section("Recording") {184 Toggle("Record history", isOn: $settings.telemetry.historyEnabled)185 Text("When off, live charts keep working but nothing is written to disk, and Insights, History and Reports have no new data.").font(.caption).foregroundStyle(.secondary)186 }187 Section("Retention") {188 Picker("Every sample", selection: $settings.retention.raw) {189 Text("1 hour").tag(3600.0)190 Text("6 hours").tag(6 * 3600.0)191 Text("24 hours").tag(86400.0)192 Text("3 days").tag(3 * 86400.0)193 }194 Picker("One-minute summaries", selection: $settings.retention.minute) {195 Text("7 days").tag(7 * 86400.0)196 Text("14 days").tag(14 * 86400.0)197 Text("30 days").tag(30 * 86400.0)198 Text("90 days").tag(90 * 86400.0)199 }200 Picker("One-hour summaries", selection: $settings.retention.hour) {201 Text("90 days").tag(90 * 86400.0)202 Text("1 year").tag(365 * 86400.0)203 Text("2 years").tag(730 * 86400.0)204 Text("5 years").tag(1825 * 86400.0)205 }206 }207 Section("Storage") {208 if let s = model.storeStatistics {209 LabeledContent("Database size", value: model.format.bytes(s.fileBytes))210 LabeledContent("Stored samples", value: "\(s.rawRows.formatted()) · \(s.minuteRows.formatted()) · \(s.hourRows.formatted())")211 Text("Raw samples · one-minute summaries · one-hour summaries.").font(.caption).foregroundStyle(.secondary)212 if let earliest = s.earliest { LabeledContent("Oldest data", value: model.format.date(earliest)) }213 } else if let error = model.storeError {214 Label("The history database could not be opened: \(error)", systemImage: "exclamationmark.triangle").foregroundStyle(.red)215 }216 Button("Erase All History…", role: .destructive) { confirmErase = true }217 }218 }219 .formStyle(.grouped)220 .onChange(of: settings.retention) { _, _ in model.applySettings() }221 .onChange(of: settings.telemetry.historyEnabled) { _, _ in model.applySettings() }222 .onAppear { model.refreshFindings() }223 .confirmationDialog("Erase all recorded history?", isPresented: $confirmErase, titleVisibility: .visible) {224 Button("Erase", role: .destructive) { model.eraseHistory() }225 Button("Cancel", role: .cancel) {}226 } message: {227 Text("Samples, summaries, alert history and bookmarks are deleted from this Mac. This cannot be undone.")228 }229 }230}231232private struct MenuBarSettings: View {233 @Environment(AppSettings.self) private var settings234235 var body: some View {236 @Bindable var settings = settings237 Form {238 Section("Menu bar") {239 Toggle("Show ORIX Monitor in the menu bar", isOn: $settings.showMenuBar)240 Toggle("Draw mini charts", isOn: $settings.menuBarGraphs)241 }242 Section("Indicators") {243 ForEach(MenuBarItem.allCases) { item in244 Toggle(MenuBarText.title(item), isOn: Binding(245 get: { settings.menuBarItems.contains(item) },246 set: { on in247 var items = settings.menuBarItems.filter { $0 != item }248 if on { items.append(item) }249 settings.menuBarItems = MenuBarItem.allCases.filter(items.contains)250 }))251 }252 Text("With every indicator off, the menu bar shows the ORIX Monitor pulse icon alone.").font(.caption).foregroundStyle(.secondary)253 }254 }255 .formStyle(.grouped)256 }257}258259private struct PrivacySettings: View {260 @Environment(AppSettings.self) private var settings261262 var body: some View {263 @Bindable var settings = settings264 Form {265 Section("Privacy mask") {266 Toggle("Hide addresses, host and user names", isOn: $settings.privacyMask)267 Text("For screenshots and screen sharing. Values are replaced by “•••” in the interface; nothing changes in what is stored.").font(.caption).foregroundStyle(.secondary)268 }269 Section("What ORIX Monitor does with your data") {270 Label("Everything is measured, stored and analysed on this Mac.", systemImage: "internaldrive")271 Label("No account, no analytics, no advertising, no update check.", systemImage: "person.crop.circle.badge.xmark")272 Label("The only network traffic it ever creates is the latency test, to the host you type, when you press the button.", systemImage: "network")273 Label("It asks for no permission except, if you want them, notifications.", systemImage: "lock.shield")274 Label("It runs without administrator rights and installs no helper.", systemImage: "checkmark.shield")275 }276 .font(.system(size: 12))277 }278 .formStyle(.grouped)279 }280}281282private struct AboutSettings: View {283 @Environment(MonitorModel.self) private var model284285 var body: some View {286 let info = Bundle.main.infoDictionary287 Form {288 Section {289 HStack(spacing: 14) {290 Image(nsImage: NSApp.applicationIconImage).resizable().frame(width: 64, height: 64).accessibilityHidden(true)291 VStack(alignment: .leading, spacing: 2) {292 Text("ORIX Monitor").font(.system(size: 18, weight: .bold))293 Text("Understand Every Pulse of Your Mac.").foregroundStyle(.secondary)294 Text("Version \(info?["CFBundleShortVersionString"] as? String ?? "—") (\(info?["CFBundleVersion"] as? String ?? "—"))").font(.caption).foregroundStyle(.secondary)295 }296 }297 }298 Section("This Mac") {299 LabeledContent("Model", value: model.system.model)300 LabeledContent("Chip", value: model.system.chip)301 LabeledContent("macOS", value: "\(model.system.osVersion) (\(model.system.osBuild))")302 }303 Section("ORIX Monitor's own footprint") {304 LabeledContent("CPU (of one core)", value: model.latest(.selfCPU).map { model.format.percent($0, digits: 1) } ?? "—")305 LabeledContent("Memory", value: model.snapshot.map { model.format.bytes($0.selfMemory, memory: true) } ?? "—")306 LabeledContent("Collection time per sample", value: model.snapshot.map { "\(model.format.number($0.collectionTime, digits: 1)) ms" } ?? "—")307 Text("Measured on itself, live, with the same method as every other process.").font(.caption).foregroundStyle(.secondary)308 }309 Section {310 Text("© 2026 Simon-Pierre Boucher. Part of the ORIX family of Apple utilities.").font(.caption).foregroundStyle(.secondary)311 }312 }313 .formStyle(.grouped)314 }315}316