Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4163d8c8b | |||
| ef6088853c | |||
| 44f4206f34 | |||
| 0bb4be861c | |||
| 619545738a | |||
| 44cc620d3d |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,14 +1,28 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 26.1.9
|
## Unreleased (2026-04-21)
|
||||||
|
- Added a new `Summary` tab with a denser dashboard layout inspired by infrastructure monitoring tools.
|
||||||
|
- Added persisted metric history with SwiftData for CPU, memory, disk, and swap charts.
|
||||||
|
- Added `Hour`, `Day`, `Week`, and `Month` ranges to summary charts.
|
||||||
|
- Added CPU, memory, disk, and swap history widgets that expand across the available summary width.
|
||||||
|
- Reworked `General` to remain the more traditional detailed information tab while `Summary` focuses on quick status and trends.
|
||||||
|
- Isolated metric history into an app-specific SwiftData store and recover cleanly from incompatible history stores.
|
||||||
|
- Fixed the summary CPU chart to use the summary payload's reported CPU percentage and allow values above `100%` with a dynamic Y axis.
|
||||||
|
- Fixed excessive summary redraws by moving the interval indicator timer out of the main detail view so charts no longer refresh every second.
|
||||||
|
- Added optional sidebar groups for hosts, including group creation, editing, deletion, and host assignment.
|
||||||
|
- Added grouped host ordering, group reordering via drag and drop, and clearer visual feedback while moving groups.
|
||||||
|
- Improved group header styling to better distinguish groups and ungrouped hosts in the sidebar.
|
||||||
|
- Fixed a launch crash in grouped builds caused by async ping tasks writing back to stale array indexes after the server list changed.
|
||||||
|
|
||||||
|
## 26.1.9 (2026-04-19)
|
||||||
- Reduced idle CPU usage and energy impact by changing the interval indicator from a permanent 60 FPS timer to a 1-second update cadence.
|
- Reduced idle CPU usage and energy impact by changing the interval indicator from a permanent 60 FPS timer to a 1-second update cadence.
|
||||||
- Reset the interval indicator cleanly when the refresh interval changes or when the indicator is hidden.
|
- Reset the interval indicator cleanly when the refresh interval changes or when the indicator is hidden.
|
||||||
|
|
||||||
## 26.1.8
|
## 26.1.8 (2026-04-19)
|
||||||
- Fixed a crash in `PingService` caused by concurrent mutation of shared ping state from multiple async ping tasks.
|
- Fixed a crash in `PingService` caused by concurrent mutation of shared ping state from multiple async ping tasks.
|
||||||
- Moved ping state tracking and reboot suppression windows into an actor so ping success/failure handling is serialized safely.
|
- Moved ping state tracking and reboot suppression windows into an actor so ping success/failure handling is serialized safely.
|
||||||
|
|
||||||
## 26.1.7
|
## 26.1.7 (2026-04-19)
|
||||||
- Added remote reboot support for hosts running KeyHelp API 2.14 or newer.
|
- Added remote reboot support for hosts running KeyHelp API 2.14 or newer.
|
||||||
- Added a dedicated `APIv2_14` client and mapped 2.14+ hosts to it instead of treating them as API 2.13.
|
- Added a dedicated `APIv2_14` client and mapped 2.14+ hosts to it instead of treating them as API 2.13.
|
||||||
- Fixed the reboot request to call `/api/v2/server/reboot` with the required JSON confirmation payload.
|
- Fixed the reboot request to call `/api/v2/server/reboot` with the required JSON confirmation payload.
|
||||||
@@ -16,22 +30,22 @@
|
|||||||
- Improved API error messages by surfacing the server response body instead of only generic HTTP status codes.
|
- Improved API error messages by surfacing the server response body instead of only generic HTTP status codes.
|
||||||
- Reduced expected reboot noise by suppressing ping checks for a short grace period after a reboot request.
|
- Reduced expected reboot noise by suppressing ping checks for a short grace period after a reboot request.
|
||||||
|
|
||||||
## 26.1.6
|
## 26.1.6 (2026-04-19)
|
||||||
- Publish Gitea releases as stable by default instead of pre-releases.
|
- Publish Gitea releases as stable by default instead of pre-releases.
|
||||||
- Update the Homebrew tap automatically after each successful release by rewriting the cask version and DMG checksum, then pushing the tap repo.
|
- Update the Homebrew tap automatically after each successful release by rewriting the cask version and DMG checksum, then pushing the tap repo.
|
||||||
- Simplified the README for end users by adding clear install options and trimming internal release-engineering details.
|
- Simplified the README for end users by adding clear install options and trimming internal release-engineering details.
|
||||||
- Ignore the local `homebrew-tap/` checkout in the main app repository.
|
- Ignore the local `homebrew-tap/` checkout in the main app repository.
|
||||||
|
|
||||||
## 26.1.3
|
## 26.1.3 (2026-01-03)
|
||||||
- Fixed version handling for changelogs.
|
- Fixed version handling for changelogs.
|
||||||
|
|
||||||
## 26.1.2 (2025-01-03)
|
## 26.1.2 (2026-01-03)
|
||||||
- Synced version.json to 26.1.2.
|
- Synced version.json to 26.1.2.
|
||||||
|
|
||||||
## 26.1.1 (2025-01-03)
|
## 26.1.1 (2026-01-03)
|
||||||
- Fixed changelog extraction in publish script.
|
- Fixed changelog extraction in publish script.
|
||||||
|
|
||||||
## 26.1.0 (2025-01-03)
|
## 26.1.0 (2026-01-03)
|
||||||
- Auto-populate release description from CHANGELOG when publishing to Gitea.
|
- Auto-populate release description from CHANGELOG when publishing to Gitea.
|
||||||
|
|
||||||
## Prereleases
|
## Prereleases
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ protocol AnyServerAPI {
|
|||||||
func fetchLoadData() async throws -> Any
|
func fetchLoadData() async throws -> Any
|
||||||
func fetchMemoryData() async throws -> Any
|
func fetchMemoryData() async throws -> Any
|
||||||
func fetchUtilizationData() async throws -> Any
|
func fetchUtilizationData() async throws -> Any
|
||||||
|
func fetchCPUUtilizationPercent(apiKey: String) async throws -> Double
|
||||||
func fetchServerSummary(apiKey: String) async throws -> ServerInfo
|
func fetchServerSummary(apiKey: String) async throws -> ServerInfo
|
||||||
func restartServer(apiKey: String) async throws
|
func restartServer(apiKey: String) async throws
|
||||||
}
|
}
|
||||||
@@ -64,6 +65,10 @@ private struct AnyServerAPIWrapper<T: ServerAPIProtocol>: AnyServerAPI {
|
|||||||
return try await wrapped.fetchUtilization()
|
return try await wrapped.fetchUtilization()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchCPUUtilizationPercent(apiKey: String) async throws -> Double {
|
||||||
|
return try await wrapped.fetchCPUUtilizationPercent(apiKey: apiKey)
|
||||||
|
}
|
||||||
|
|
||||||
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
||||||
return try await wrapped.fetchServerSummary(apiKey: apiKey)
|
return try await wrapped.fetchServerSummary(apiKey: apiKey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ protocol ServerAPIProtocol {
|
|||||||
func fetchLoad() async throws -> LoadType
|
func fetchLoad() async throws -> LoadType
|
||||||
func fetchMemory() async throws -> MemoryType
|
func fetchMemory() async throws -> MemoryType
|
||||||
func fetchUtilization() async throws -> UtilizationType
|
func fetchUtilization() async throws -> UtilizationType
|
||||||
|
func fetchCPUUtilizationPercent(apiKey: String) async throws -> Double
|
||||||
func fetchServerSummary(apiKey: String) async throws -> ServerInfo
|
func fetchServerSummary(apiKey: String) async throws -> ServerInfo
|
||||||
func restartServer(apiKey: String) async throws
|
func restartServer(apiKey: String) async throws
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import Foundation
|
|||||||
struct Server: Identifiable, Codable, Hashable, Equatable {
|
struct Server: Identifiable, Codable, Hashable, Equatable {
|
||||||
let id: UUID
|
let id: UUID
|
||||||
var hostname: String
|
var hostname: String
|
||||||
|
var groupID: UUID?
|
||||||
var info: ServerInfo?
|
var info: ServerInfo?
|
||||||
var pingable: Bool
|
var pingable: Bool
|
||||||
|
|
||||||
init(id: UUID = UUID(), hostname: String, info: ServerInfo? = nil, pingable: Bool = false) {
|
init(id: UUID = UUID(), hostname: String, groupID: UUID? = nil, info: ServerInfo? = nil, pingable: Bool = false) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
|
self.groupID = groupID
|
||||||
self.info = info
|
self.info = info
|
||||||
self.pingable = pingable
|
self.pingable = pingable
|
||||||
}
|
}
|
||||||
@@ -23,24 +25,26 @@ struct Server: Identifiable, Codable, Hashable, Equatable {
|
|||||||
// MARK: - Manual conformance
|
// MARK: - Manual conformance
|
||||||
|
|
||||||
static func == (lhs: Server, rhs: Server) -> Bool {
|
static func == (lhs: Server, rhs: Server) -> Bool {
|
||||||
lhs.id == rhs.id && lhs.hostname == rhs.hostname && lhs.info == rhs.info && lhs.pingable == rhs.pingable
|
lhs.id == rhs.id && lhs.hostname == rhs.hostname && lhs.groupID == rhs.groupID && lhs.info == rhs.info && lhs.pingable == rhs.pingable
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash(into hasher: inout Hasher) {
|
func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(id)
|
hasher.combine(id)
|
||||||
hasher.combine(hostname)
|
hasher.combine(hostname)
|
||||||
|
hasher.combine(groupID)
|
||||||
hasher.combine(info)
|
hasher.combine(info)
|
||||||
hasher.combine(pingable)
|
hasher.combine(pingable)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case id, hostname, info, pingable
|
case id, hostname, groupID, info, pingable
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
id = try container.decode(UUID.self, forKey: .id)
|
id = try container.decode(UUID.self, forKey: .id)
|
||||||
hostname = try container.decode(String.self, forKey: .hostname)
|
hostname = try container.decode(String.self, forKey: .hostname)
|
||||||
|
groupID = try container.decodeIfPresent(UUID.self, forKey: .groupID)
|
||||||
info = try container.decodeIfPresent(ServerInfo.self, forKey: .info)
|
info = try container.decodeIfPresent(ServerInfo.self, forKey: .info)
|
||||||
pingable = try container.decodeIfPresent(Bool.self, forKey: .pingable) ?? false
|
pingable = try container.decodeIfPresent(Bool.self, forKey: .pingable) ?? false
|
||||||
}
|
}
|
||||||
@@ -49,6 +53,7 @@ struct Server: Identifiable, Codable, Hashable, Equatable {
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(id, forKey: .id)
|
try container.encode(id, forKey: .id)
|
||||||
try container.encode(hostname, forKey: .hostname)
|
try container.encode(hostname, forKey: .hostname)
|
||||||
|
try container.encodeIfPresent(groupID, forKey: .groupID)
|
||||||
try container.encodeIfPresent(info, forKey: .info)
|
try container.encodeIfPresent(info, forKey: .info)
|
||||||
try container.encode(pingable, forKey: .pingable)
|
try container.encode(pingable, forKey: .pingable)
|
||||||
}
|
}
|
||||||
|
|||||||
11
Sources/Model/API/ServerGroup.swift
Normal file
11
Sources/Model/API/ServerGroup.swift
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct ServerGroup: Identifiable, Codable, Hashable, Equatable {
|
||||||
|
let id: UUID
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
init(id: UUID = UUID(), name: String) {
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,16 @@ struct ServerInfo: Codable, Hashable, Equatable {
|
|||||||
self.cpuCount = cpuCount
|
self.cpuCount = cpuCount
|
||||||
self.level = level
|
self.level = level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var displayPercent: Double {
|
||||||
|
let clampedPercent = min(max(percent, 0), 100)
|
||||||
|
guard clampedPercent != percent else {
|
||||||
|
return clampedPercent
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalized = (minute1 / Double(max(cpuCount, 1))) * 100
|
||||||
|
return min(max(normalized, 0), 100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Memory: Codable, Hashable, Equatable {
|
struct Memory: Codable, Hashable, Equatable {
|
||||||
@@ -155,6 +165,7 @@ struct ServerInfo: Codable, Hashable, Equatable {
|
|||||||
var memory: Memory
|
var memory: Memory
|
||||||
var swap: Memory
|
var swap: Memory
|
||||||
var diskSpace: DiskSpace
|
var diskSpace: DiskSpace
|
||||||
|
var cpuUtilizationPercent: Double?
|
||||||
var panelVersion: String
|
var panelVersion: String
|
||||||
var panelBuild: String
|
var panelBuild: String
|
||||||
var apiVersion: String
|
var apiVersion: String
|
||||||
@@ -189,6 +200,13 @@ struct ServerInfo: Codable, Hashable, Equatable {
|
|||||||
var supportsRestartCommand: Bool {
|
var supportsRestartCommand: Bool {
|
||||||
ServerInfo.version(apiVersion, isAtLeast: "2.14")
|
ServerInfo.version(apiVersion, isAtLeast: "2.14")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var summaryCPUPercent: Double {
|
||||||
|
if let cpuUtilizationPercent {
|
||||||
|
return min(max(cpuUtilizationPercent, 0), 100)
|
||||||
|
}
|
||||||
|
return load.displayPercent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Helpers & Sample Data
|
// MARK: - Helpers & Sample Data
|
||||||
@@ -284,6 +302,7 @@ extension ServerInfo {
|
|||||||
memory: Memory(free: 8_000_000_000, used: 4_000_000_000, total: 12_000_000_000, percent: 33.3),
|
memory: Memory(free: 8_000_000_000, used: 4_000_000_000, total: 12_000_000_000, percent: 33.3),
|
||||||
swap: Memory(free: 4_000_000_000, used: 1_000_000_000, total: 5_000_000_000, percent: 20.0),
|
swap: Memory(free: 4_000_000_000, used: 1_000_000_000, total: 5_000_000_000, percent: 20.0),
|
||||||
diskSpace: DiskSpace(free: 100_000_000_000, used: 50_000_000_000, total: 150_000_000_000, percent: 33.3),
|
diskSpace: DiskSpace(free: 100_000_000_000, used: 50_000_000_000, total: 150_000_000_000, percent: 33.3),
|
||||||
|
cpuUtilizationPercent: 12.5,
|
||||||
panelVersion: "25.0",
|
panelVersion: "25.0",
|
||||||
panelBuild: "3394",
|
panelBuild: "3394",
|
||||||
apiVersion: "2",
|
apiVersion: "2",
|
||||||
|
|||||||
@@ -168,6 +168,17 @@ class APIv2_12: BaseAPIClient, ServerAPIProtocol {
|
|||||||
return try await performRequest(request, responseType: UtilizationType.self)
|
return try await performRequest(request, responseType: UtilizationType.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchCPUUtilizationPercent(apiKey: String) async throws -> Double {
|
||||||
|
let url = Endpoint.utilization.url(baseURL: baseURL)
|
||||||
|
var request = URLRequest(url: url)
|
||||||
|
request.setValue("application/json", forHTTPHeaderField: "Accept")
|
||||||
|
request.setValue(apiKey, forHTTPHeaderField: "X-API-KEY")
|
||||||
|
request.timeoutInterval = 30
|
||||||
|
|
||||||
|
let utilization = try await performRequest(request, responseType: UtilizationType.self)
|
||||||
|
return utilization.cpu.overall
|
||||||
|
}
|
||||||
|
|
||||||
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
||||||
let summaryURL = baseURL.appendingPathComponent("api/v2/server")
|
let summaryURL = baseURL.appendingPathComponent("api/v2/server")
|
||||||
var request = URLRequest(url: summaryURL)
|
var request = URLRequest(url: summaryURL)
|
||||||
@@ -397,6 +408,7 @@ private extension APIv2_12 {
|
|||||||
total: disk.total,
|
total: disk.total,
|
||||||
percent: disk.percent
|
percent: disk.percent
|
||||||
),
|
),
|
||||||
|
cpuUtilizationPercent: nil,
|
||||||
panelVersion: meta.panelVersion,
|
panelVersion: meta.panelVersion,
|
||||||
panelBuild: String(meta.panelBuild),
|
panelBuild: String(meta.panelBuild),
|
||||||
apiVersion: meta.apiVersion,
|
apiVersion: meta.apiVersion,
|
||||||
|
|||||||
@@ -168,6 +168,17 @@ class APIv2_13: BaseAPIClient, ServerAPIProtocol {
|
|||||||
return try await performRequest(request, responseType: UtilizationType.self)
|
return try await performRequest(request, responseType: UtilizationType.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchCPUUtilizationPercent(apiKey: String) async throws -> Double {
|
||||||
|
let url = Endpoint.utilization.url(baseURL: baseURL)
|
||||||
|
var request = URLRequest(url: url)
|
||||||
|
request.setValue("application/json", forHTTPHeaderField: "Accept")
|
||||||
|
request.setValue(apiKey, forHTTPHeaderField: "X-API-KEY")
|
||||||
|
request.timeoutInterval = 30
|
||||||
|
|
||||||
|
let utilization = try await performRequest(request, responseType: UtilizationType.self)
|
||||||
|
return utilization.cpu.overall
|
||||||
|
}
|
||||||
|
|
||||||
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
func fetchServerSummary(apiKey: String) async throws -> ServerInfo {
|
||||||
let summaryURL = baseURL.appendingPathComponent("api/v2/server")
|
let summaryURL = baseURL.appendingPathComponent("api/v2/server")
|
||||||
var request = URLRequest(url: summaryURL)
|
var request = URLRequest(url: summaryURL)
|
||||||
@@ -397,6 +408,7 @@ private extension APIv2_13 {
|
|||||||
total: disk.total,
|
total: disk.total,
|
||||||
percent: disk.percent
|
percent: disk.percent
|
||||||
),
|
),
|
||||||
|
cpuUtilizationPercent: nil,
|
||||||
panelVersion: meta.panelVersion,
|
panelVersion: meta.panelVersion,
|
||||||
panelBuild: String(meta.panelBuild),
|
panelBuild: String(meta.panelBuild),
|
||||||
apiVersion: meta.apiVersion,
|
apiVersion: meta.apiVersion,
|
||||||
|
|||||||
35
Sources/Model/History/MetricSample.swift
Normal file
35
Sources/Model/History/MetricSample.swift
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// MetricSample.swift
|
||||||
|
// iKeyMon
|
||||||
|
//
|
||||||
|
// Created by tracer on 21.04.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftData
|
||||||
|
|
||||||
|
@Model
|
||||||
|
final class MetricSample {
|
||||||
|
var serverID: UUID
|
||||||
|
var timestamp: Date
|
||||||
|
var cpuPercent: Double
|
||||||
|
var memoryPercent: Double
|
||||||
|
var swapPercent: Double
|
||||||
|
var diskPercent: Double
|
||||||
|
|
||||||
|
init(
|
||||||
|
serverID: UUID,
|
||||||
|
timestamp: Date = .now,
|
||||||
|
cpuPercent: Double,
|
||||||
|
memoryPercent: Double,
|
||||||
|
swapPercent: Double,
|
||||||
|
diskPercent: Double
|
||||||
|
) {
|
||||||
|
self.serverID = serverID
|
||||||
|
self.timestamp = timestamp
|
||||||
|
self.cpuPercent = cpuPercent
|
||||||
|
self.memoryPercent = memoryPercent
|
||||||
|
self.swapPercent = swapPercent
|
||||||
|
self.diskPercent = diskPercent
|
||||||
|
}
|
||||||
|
}
|
||||||
80
Sources/Views/GroupFormView.swift
Normal file
80
Sources/Views/GroupFormView.swift
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GroupFormView: View {
|
||||||
|
enum Mode {
|
||||||
|
case add
|
||||||
|
case edit(ServerGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mode: Mode
|
||||||
|
@Binding var groups: [ServerGroup]
|
||||||
|
let onSave: () -> Void
|
||||||
|
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@State private var name: String
|
||||||
|
|
||||||
|
init(mode: Mode, groups: Binding<[ServerGroup]>, onSave: @escaping () -> Void) {
|
||||||
|
self.mode = mode
|
||||||
|
self._groups = groups
|
||||||
|
self.onSave = onSave
|
||||||
|
|
||||||
|
switch mode {
|
||||||
|
case .add:
|
||||||
|
self._name = State(initialValue: "")
|
||||||
|
case .edit(let group):
|
||||||
|
self._name = State(initialValue: group.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 16) {
|
||||||
|
Text(title)
|
||||||
|
.font(.headline)
|
||||||
|
|
||||||
|
TextField("Group name", text: $name)
|
||||||
|
.textFieldStyle(.roundedBorder)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Button("Cancel") {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button("Save") {
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
.disabled(trimmedName.isEmpty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.frame(width: 320)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var title: String {
|
||||||
|
switch mode {
|
||||||
|
case .add:
|
||||||
|
return "Add Group"
|
||||||
|
case .edit:
|
||||||
|
return "Edit Group"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var trimmedName: String {
|
||||||
|
name.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func save() {
|
||||||
|
switch mode {
|
||||||
|
case .add:
|
||||||
|
groups.append(ServerGroup(name: trimmedName))
|
||||||
|
case .edit(let group):
|
||||||
|
if let index = groups.firstIndex(where: { $0.id == group.id }) {
|
||||||
|
groups[index].name = trimmedName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSave()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,16 +8,24 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Combine
|
import Combine
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
import SwiftData
|
||||||
|
import AppKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct MainView: View {
|
struct MainView: View {
|
||||||
|
|
||||||
private static let serverOrderKeyStatic = "serverOrder"
|
private static let serverOrderKeyStatic = "serverOrder"
|
||||||
private static let storedServersKeyStatic = "storedServers"
|
private static let storedServersKeyStatic = "storedServers"
|
||||||
|
private static let storedGroupsKeyStatic = "storedGroups"
|
||||||
|
|
||||||
@State var showAddServerSheet: Bool = false
|
@State var showAddServerSheet: Bool = false
|
||||||
|
@State private var showAddGroupSheet: Bool = false
|
||||||
@State private var serverBeingEdited: Server?
|
@State private var serverBeingEdited: Server?
|
||||||
|
@State private var groupBeingEdited: ServerGroup?
|
||||||
@State private var serverToDelete: Server?
|
@State private var serverToDelete: Server?
|
||||||
|
@State private var groupToDelete: ServerGroup?
|
||||||
@State private var showDeleteConfirmation = false
|
@State private var showDeleteConfirmation = false
|
||||||
|
@State private var showDeleteGroupConfirmation = false
|
||||||
@State private var isFetchingInfo: Bool = false
|
@State private var isFetchingInfo: Bool = false
|
||||||
@AppStorage("pingInterval") private var pingInterval: Int = 10
|
@AppStorage("pingInterval") private var pingInterval: Int = 10
|
||||||
@AppStorage("refreshInterval") private var refreshInterval: Int = 60
|
@AppStorage("refreshInterval") private var refreshInterval: Int = 60
|
||||||
@@ -27,12 +35,17 @@ struct MainView: View {
|
|||||||
@State private var refreshSubscription: AnyCancellable?
|
@State private var refreshSubscription: AnyCancellable?
|
||||||
@State private var pingTimer: Timer?
|
@State private var pingTimer: Timer?
|
||||||
@State private var restartingServerID: UUID?
|
@State private var restartingServerID: UUID?
|
||||||
|
@State private var draggedGroupID: UUID?
|
||||||
|
@State private var groupDropIndicator: GroupDropIndicator?
|
||||||
@State private var lastRefreshInterval: Int?
|
@State private var lastRefreshInterval: Int?
|
||||||
|
@State private var lastMetricPrune: Date?
|
||||||
@State private var previousServiceStates: [String: String] = [:]
|
@State private var previousServiceStates: [String: String] = [:]
|
||||||
private let serverOrderKey = MainView.serverOrderKeyStatic
|
private let serverOrderKey = MainView.serverOrderKeyStatic
|
||||||
private let storedServersKey = MainView.storedServersKeyStatic
|
private let storedGroupsKey = MainView.storedGroupsKeyStatic
|
||||||
|
@Environment(\.modelContext) private var modelContext
|
||||||
|
|
||||||
@State private var servers: [Server] = MainView.loadStoredServers()
|
@State private var servers: [Server] = MainView.loadStoredServers()
|
||||||
|
@State private var groups: [ServerGroup] = MainView.loadStoredGroups()
|
||||||
|
|
||||||
// @State private var selectedServer: Server?
|
// @State private var selectedServer: Server?
|
||||||
@State private var selectedServerID: UUID?
|
@State private var selectedServerID: UUID?
|
||||||
@@ -40,34 +53,38 @@ struct MainView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
var mainContent: some View {
|
var mainContent: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
|
ZStack {
|
||||||
|
SidebarMaterialView()
|
||||||
|
|
||||||
List(selection: $selectedServerID) {
|
List(selection: $selectedServerID) {
|
||||||
ForEach(servers) { server in
|
sidebarContent
|
||||||
HStack {
|
|
||||||
Image(systemName: "dot.circle.fill")
|
|
||||||
.foregroundColor(server.pingable ? .green : .red)
|
|
||||||
Text(server.hostname)
|
|
||||||
}
|
}
|
||||||
.tag(server)
|
.listStyle(.sidebar)
|
||||||
.contextMenu {
|
.scrollContentBackground(.hidden)
|
||||||
Button("Edit") {
|
.background(Color.clear)
|
||||||
print("Editing:", server.hostname)
|
|
||||||
serverBeingEdited = server
|
|
||||||
}
|
}
|
||||||
Divider()
|
.background(
|
||||||
Button("Delete", role: .destructive) {
|
RoundedRectangle(cornerRadius: 0, style: .continuous)
|
||||||
serverToDelete = server
|
.fill(.ultraThinMaterial)
|
||||||
showDeleteConfirmation = true
|
)
|
||||||
}
|
.overlay(alignment: .trailing) {
|
||||||
}
|
Rectangle()
|
||||||
}
|
.fill(Color.white.opacity(0.08))
|
||||||
.onMove(perform: moveServer)
|
.frame(width: 1)
|
||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .primaryAction) {
|
ToolbarItem(placement: .primaryAction) {
|
||||||
Button(action: { showAddServerSheet = true }) {
|
Menu {
|
||||||
|
Button("Add Host") {
|
||||||
|
showAddServerSheet = true
|
||||||
|
}
|
||||||
|
Button("Add Group") {
|
||||||
|
showAddGroupSheet = true
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
Image(systemName: "plus")
|
Image(systemName: "plus")
|
||||||
}
|
}
|
||||||
.help("Add Host")
|
.help("Add Host or Group")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Servers")
|
.navigationTitle("Servers")
|
||||||
@@ -99,22 +116,43 @@ struct MainView: View {
|
|||||||
ServerFormView(
|
ServerFormView(
|
||||||
mode: .add,
|
mode: .add,
|
||||||
servers: $servers,
|
servers: $servers,
|
||||||
|
groups: $groups,
|
||||||
dismiss: { showAddServerSheet = false }
|
dismiss: { showAddServerSheet = false }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $showAddGroupSheet) {
|
||||||
|
GroupFormView(mode: .add, groups: $groups) {
|
||||||
|
saveGroups()
|
||||||
|
}
|
||||||
|
}
|
||||||
.sheet(item: $serverBeingEdited) { server in
|
.sheet(item: $serverBeingEdited) { server in
|
||||||
ServerFormView(
|
ServerFormView(
|
||||||
mode: .edit(server),
|
mode: .edit(server),
|
||||||
servers: $servers,
|
servers: $servers,
|
||||||
|
groups: $groups,
|
||||||
dismiss: { serverBeingEdited = nil }
|
dismiss: { serverBeingEdited = nil }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
.sheet(item: $groupBeingEdited) { group in
|
||||||
|
GroupFormView(mode: .edit(group), groups: $groups) {
|
||||||
|
saveGroups()
|
||||||
|
}
|
||||||
|
}
|
||||||
.alert("Are you sure you want to delete this server?", isPresented: $showDeleteConfirmation, presenting: serverToDelete) { server in
|
.alert("Are you sure you want to delete this server?", isPresented: $showDeleteConfirmation, presenting: serverToDelete) { server in
|
||||||
Button("Delete", role: .destructive) {
|
Button("Delete", role: .destructive) {
|
||||||
ServerFormView.delete(server: server, from: &servers)
|
ServerFormView.delete(server: server, from: &servers)
|
||||||
|
saveServers()
|
||||||
}
|
}
|
||||||
Button("Cancel", role: .cancel) {}
|
Button("Cancel", role: .cancel) {}
|
||||||
}
|
}
|
||||||
|
.alert("Are you sure you want to delete this group?", isPresented: $showDeleteGroupConfirmation, presenting: groupToDelete) { group in
|
||||||
|
Button("Delete", role: .destructive) {
|
||||||
|
deleteGroup(group)
|
||||||
|
}
|
||||||
|
Button("Cancel", role: .cancel) {}
|
||||||
|
} message: { group in
|
||||||
|
Text("Servers in \(group.name) will remain available and become ungrouped.")
|
||||||
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
requestNotificationPermissions()
|
requestNotificationPermissions()
|
||||||
|
|
||||||
@@ -149,9 +187,146 @@ struct MainView: View {
|
|||||||
setupRefreshTimer()
|
setupRefreshTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onChange(of: groups) { _, _ in
|
||||||
|
saveGroups()
|
||||||
|
}
|
||||||
.frame(minWidth: 800, minHeight: 450)
|
.frame(minWidth: 800, minHeight: 450)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var sidebarContent: some View {
|
||||||
|
if groups.isEmpty {
|
||||||
|
ForEach(servers) { server in
|
||||||
|
sidebarRow(for: server)
|
||||||
|
}
|
||||||
|
.onMove(perform: moveServer)
|
||||||
|
} else {
|
||||||
|
ForEach(groups) { group in
|
||||||
|
Section {
|
||||||
|
ForEach(servers(in: group)) { server in
|
||||||
|
sidebarRow(for: server)
|
||||||
|
}
|
||||||
|
.onMove { source, destination in
|
||||||
|
moveServers(in: group.id, from: source, to: destination)
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
groupHeader(for: group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ungroupedServers.isEmpty {
|
||||||
|
Section {
|
||||||
|
ForEach(ungroupedServers) { server in
|
||||||
|
sidebarRow(for: server)
|
||||||
|
}
|
||||||
|
.onMove { source, destination in
|
||||||
|
moveServers(in: nil, from: source, to: destination)
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
sidebarSectionHeader("Ungrouped")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sidebarSectionHeader(_ title: String) -> some View {
|
||||||
|
HStack {
|
||||||
|
Text(title)
|
||||||
|
.font(.system(size: NSFont.systemFontSize + 1, weight: .bold))
|
||||||
|
.foregroundStyle(Color.accentColor)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sidebarRow(for server: Server) -> some View {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "dot.circle.fill")
|
||||||
|
.foregroundColor(server.pingable ? .green : .red)
|
||||||
|
Text(server.hostname)
|
||||||
|
}
|
||||||
|
.tag(server.id)
|
||||||
|
.contextMenu {
|
||||||
|
Button("Edit") {
|
||||||
|
print("Editing:", server.hostname)
|
||||||
|
serverBeingEdited = server
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
Button("Delete", role: .destructive) {
|
||||||
|
serverToDelete = server
|
||||||
|
showDeleteConfirmation = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func groupHeader(for group: ServerGroup) -> some View {
|
||||||
|
let activePlacement = groupDropIndicator?.groupID == group.id ? groupDropIndicator?.placement : nil
|
||||||
|
|
||||||
|
return VStack(spacing: 0) {
|
||||||
|
if activePlacement == .before {
|
||||||
|
dropIndicator
|
||||||
|
}
|
||||||
|
|
||||||
|
sidebarSectionHeader(group.name)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.background {
|
||||||
|
if activePlacement != nil {
|
||||||
|
RoundedRectangle(cornerRadius: 6, style: .continuous)
|
||||||
|
.fill(Color.accentColor.opacity(0.12))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if activePlacement == .after {
|
||||||
|
dropIndicator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onDrag {
|
||||||
|
draggedGroupID = group.id
|
||||||
|
return NSItemProvider(object: group.id.uuidString as NSString)
|
||||||
|
}
|
||||||
|
.onDrop(
|
||||||
|
of: [UTType.text],
|
||||||
|
delegate: GroupDropDelegate(
|
||||||
|
targetGroup: group,
|
||||||
|
groups: $groups,
|
||||||
|
draggedGroupID: $draggedGroupID,
|
||||||
|
indicator: $groupDropIndicator
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.contextMenu {
|
||||||
|
Button("Edit Group") {
|
||||||
|
groupBeingEdited = group
|
||||||
|
}
|
||||||
|
Button("Delete Group", role: .destructive) {
|
||||||
|
groupToDelete = group
|
||||||
|
showDeleteGroupConfirmation = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var dropIndicator: some View {
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
Capsule()
|
||||||
|
.fill(Color.accentColor)
|
||||||
|
.frame(height: 3)
|
||||||
|
.shadow(color: Color.accentColor.opacity(0.25), radius: 1, y: 0)
|
||||||
|
Color.clear
|
||||||
|
.frame(height: 4)
|
||||||
|
}
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var ungroupedServers: [Server] {
|
||||||
|
servers.filter { server in
|
||||||
|
guard let groupID = server.groupID else { return true }
|
||||||
|
return groups.contains(where: { $0.id == groupID }) == false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func servers(in group: ServerGroup) -> [Server] {
|
||||||
|
servers.filter { $0.groupID == group.id }
|
||||||
|
}
|
||||||
|
|
||||||
private func fetchServerInfo(for id: UUID) {
|
private func fetchServerInfo(for id: UUID) {
|
||||||
guard let server = servers.first(where: { $0.id == id }) else {
|
guard let server = servers.first(where: { $0.id == id }) else {
|
||||||
print("❌ [MainView] fetchServerInfo: server not found for id \(id)")
|
print("❌ [MainView] fetchServerInfo: server not found for id \(id)")
|
||||||
@@ -179,6 +354,7 @@ struct MainView: View {
|
|||||||
var updated = servers[index]
|
var updated = servers[index]
|
||||||
updated.info = info
|
updated.info = info
|
||||||
servers[index] = updated
|
servers[index] = updated
|
||||||
|
recordMetricSample(for: id, info: info)
|
||||||
checkServiceStatusChanges(for: server.hostname, newInfo: info)
|
checkServiceStatusChanges(for: server.hostname, newInfo: info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,6 +390,7 @@ struct MainView: View {
|
|||||||
var updated = servers[index]
|
var updated = servers[index]
|
||||||
updated.info = info
|
updated.info = info
|
||||||
servers[index] = updated
|
servers[index] = updated
|
||||||
|
recordMetricSample(for: id, info: info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -223,6 +400,41 @@ struct MainView: View {
|
|||||||
|
|
||||||
private func moveServer(from source: IndexSet, to destination: Int) {
|
private func moveServer(from source: IndexSet, to destination: Int) {
|
||||||
servers.move(fromOffsets: source, toOffset: destination)
|
servers.move(fromOffsets: source, toOffset: destination)
|
||||||
|
saveServers()
|
||||||
|
saveServerOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func moveServers(in groupID: UUID?, from source: IndexSet, to destination: Int) {
|
||||||
|
let matchingServers = servers.filter { server in
|
||||||
|
if let groupID {
|
||||||
|
return server.groupID == groupID
|
||||||
|
}
|
||||||
|
return server.groupID == nil || groups.contains(where: { $0.id == server.groupID }) == false
|
||||||
|
}
|
||||||
|
|
||||||
|
var reorderedServers = matchingServers
|
||||||
|
reorderedServers.move(fromOffsets: source, toOffset: destination)
|
||||||
|
|
||||||
|
let replacements = Dictionary(uniqueKeysWithValues: reorderedServers.map { ($0.id, $0) })
|
||||||
|
var reorderedIDs = reorderedServers.map(\.id)
|
||||||
|
|
||||||
|
servers = servers.map { server in
|
||||||
|
let belongsInSection: Bool
|
||||||
|
if let groupID {
|
||||||
|
belongsInSection = server.groupID == groupID
|
||||||
|
} else {
|
||||||
|
belongsInSection = server.groupID == nil || groups.contains(where: { $0.id == server.groupID }) == false
|
||||||
|
}
|
||||||
|
|
||||||
|
guard belongsInSection, let nextID = reorderedIDs.first else {
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
reorderedIDs.removeFirst()
|
||||||
|
return replacements[nextID] ?? server
|
||||||
|
}
|
||||||
|
|
||||||
|
saveServers()
|
||||||
saveServerOrder()
|
saveServerOrder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,16 +444,91 @@ struct MainView: View {
|
|||||||
print("💾 [MainView] Saved server order with \(ids.count) entries")
|
print("💾 [MainView] Saved server order with \(ids.count) entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func saveServers() {
|
||||||
|
if let data = try? JSONEncoder().encode(servers) {
|
||||||
|
UserDefaults.standard.set(data, forKey: MainView.storedServersKeyStatic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func saveGroups() {
|
||||||
|
if let data = try? JSONEncoder().encode(groups) {
|
||||||
|
UserDefaults.standard.set(data, forKey: storedGroupsKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func recordMetricSample(for serverID: UUID, info: ServerInfo) {
|
||||||
|
let sample = MetricSample(
|
||||||
|
serverID: serverID,
|
||||||
|
cpuPercent: info.load.percent,
|
||||||
|
memoryPercent: info.memory.percent,
|
||||||
|
swapPercent: info.swap.percent,
|
||||||
|
diskPercent: info.diskSpace.percent
|
||||||
|
)
|
||||||
|
modelContext.insert(sample)
|
||||||
|
|
||||||
|
do {
|
||||||
|
try modelContext.save()
|
||||||
|
} catch {
|
||||||
|
print("❌ [MainView] Failed to save metric sample: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
pruneOldMetricSamplesIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func pruneOldMetricSamplesIfNeeded() {
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
if let lastMetricPrune, now.timeIntervalSince(lastMetricPrune) < 3600 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let cutoff = now.addingTimeInterval(-30 * 24 * 60 * 60)
|
||||||
|
let descriptor = FetchDescriptor<MetricSample>(
|
||||||
|
predicate: #Predicate { sample in
|
||||||
|
sample.timestamp < cutoff
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
do {
|
||||||
|
let expiredSamples = try modelContext.fetch(descriptor)
|
||||||
|
for sample in expiredSamples {
|
||||||
|
modelContext.delete(sample)
|
||||||
|
}
|
||||||
|
if !expiredSamples.isEmpty {
|
||||||
|
try modelContext.save()
|
||||||
|
}
|
||||||
|
lastMetricPrune = now
|
||||||
|
} catch {
|
||||||
|
print("❌ [MainView] Failed to prune metric samples: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deleteGroup(_ group: ServerGroup) {
|
||||||
|
groups.removeAll { $0.id == group.id }
|
||||||
|
for index in servers.indices {
|
||||||
|
if servers[index].groupID == group.id {
|
||||||
|
servers[index].groupID = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveGroups()
|
||||||
|
saveServers()
|
||||||
|
}
|
||||||
|
|
||||||
private struct PingResponse: Codable {
|
private struct PingResponse: Codable {
|
||||||
let response: String
|
let response: String
|
||||||
}
|
}
|
||||||
|
|
||||||
func pingAllServers() {
|
func pingAllServers() {
|
||||||
for (index, server) in servers.enumerated() {
|
let pingTargets = servers.map { ($0.id, $0.hostname) }
|
||||||
|
|
||||||
|
for (serverID, hostname) in pingTargets {
|
||||||
Task {
|
Task {
|
||||||
let apiKey = KeychainHelper.loadApiKey(for: server.hostname)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
let apiKey = KeychainHelper.loadApiKey(for: hostname)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
let pingable = await PingService.ping(hostname: server.hostname, apiKey: apiKey, notificationsEnabled: enableStatusNotifications)
|
let pingable = await PingService.ping(hostname: hostname, apiKey: apiKey, notificationsEnabled: enableStatusNotifications)
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
guard let index = servers.firstIndex(where: { $0.id == serverID }) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
servers[index].pingable = pingable
|
servers[index].pingable = pingable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,6 +586,20 @@ struct MainView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func loadStoredGroups() -> [ServerGroup] {
|
||||||
|
let defaults = UserDefaults.standard
|
||||||
|
guard let data = defaults.data(forKey: storedGroupsKeyStatic) else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
return try JSONDecoder().decode([ServerGroup].self, from: data)
|
||||||
|
} catch {
|
||||||
|
print("❌ [MainView] Failed to decode stored groups: \(error)")
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func requestNotificationPermissions() {
|
private func requestNotificationPermissions() {
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
@@ -421,6 +722,90 @@ struct MainView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct SidebarMaterialView: NSViewRepresentable {
|
||||||
|
func makeNSView(context: Context) -> NSVisualEffectView {
|
||||||
|
let view = NSVisualEffectView()
|
||||||
|
view.blendingMode = .behindWindow
|
||||||
|
view.material = .sidebar
|
||||||
|
view.state = .active
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
|
||||||
|
nsView.state = .active
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct GroupDropDelegate: DropDelegate {
|
||||||
|
enum Placement {
|
||||||
|
case before
|
||||||
|
case after
|
||||||
|
}
|
||||||
|
|
||||||
|
let targetGroup: ServerGroup
|
||||||
|
@Binding var groups: [ServerGroup]
|
||||||
|
@Binding var draggedGroupID: UUID?
|
||||||
|
@Binding var indicator: GroupDropIndicator?
|
||||||
|
|
||||||
|
func dropEntered(info: DropInfo) {
|
||||||
|
updateIndicator(with: info)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dropUpdated(info: DropInfo) -> DropProposal? {
|
||||||
|
updateIndicator(with: info)
|
||||||
|
return DropProposal(operation: .move)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dropExited(info: DropInfo) {
|
||||||
|
indicator = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func performDrop(info: DropInfo) -> Bool {
|
||||||
|
defer {
|
||||||
|
draggedGroupID = nil
|
||||||
|
indicator = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard
|
||||||
|
let draggedGroupID,
|
||||||
|
draggedGroupID != targetGroup.id,
|
||||||
|
let fromIndex = groups.firstIndex(where: { $0.id == draggedGroupID }),
|
||||||
|
let toIndex = groups.firstIndex(where: { $0.id == targetGroup.id })
|
||||||
|
else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
let placement = placement(for: info)
|
||||||
|
let proposedIndex = placement == .after ? toIndex + 1 : toIndex
|
||||||
|
groups.move(
|
||||||
|
fromOffsets: IndexSet(integer: fromIndex),
|
||||||
|
toOffset: proposedIndex > fromIndex ? proposedIndex + 1 : proposedIndex
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateIndicator(with info: DropInfo) {
|
||||||
|
guard let draggedGroupID, draggedGroupID != targetGroup.id else {
|
||||||
|
indicator = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
indicator = GroupDropIndicator(
|
||||||
|
groupID: targetGroup.id,
|
||||||
|
placement: placement(for: info)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func placement(for info: DropInfo) -> Placement {
|
||||||
|
info.location.y > 12 ? .after : .before
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct GroupDropIndicator: Equatable {
|
||||||
|
let groupID: UUID
|
||||||
|
let placement: GroupDropDelegate.Placement
|
||||||
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
MainView()
|
MainView()
|
||||||
.environmentObject(SparkleUpdater())
|
.environmentObject(SparkleUpdater())
|
||||||
|
|||||||
@@ -20,30 +20,34 @@ struct ServerDetailView: View {
|
|||||||
var isRestarting: Bool = false
|
var isRestarting: Bool = false
|
||||||
var onRestart: (() async -> ServerActionFeedback)? = nil
|
var onRestart: (() async -> ServerActionFeedback)? = nil
|
||||||
@AppStorage("showIntervalIndicator") private var showIntervalIndicator: Bool = true
|
@AppStorage("showIntervalIndicator") private var showIntervalIndicator: Bool = true
|
||||||
@AppStorage("refreshInterval") private var refreshInterval: Int = 60
|
|
||||||
|
|
||||||
private var showPlaceholder: Bool {
|
private var showPlaceholder: Bool {
|
||||||
server.info == nil
|
server.info == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@State private var progress: Double = 0
|
|
||||||
@State private var showRestartSheet = false
|
@State private var showRestartSheet = false
|
||||||
@State private var restartFeedback: ServerActionFeedback?
|
@State private var restartFeedback: ServerActionFeedback?
|
||||||
private let indicatorTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
if showIntervalIndicator {
|
if showIntervalIndicator {
|
||||||
ProgressView(value: progress)
|
RefreshIntervalIndicator()
|
||||||
.progressViewStyle(LinearProgressViewStyle())
|
|
||||||
.padding(.horizontal)
|
|
||||||
.frame(height: 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZStack(alignment: .topTrailing) {
|
ZStack(alignment: .topTrailing) {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
Spacer().frame(height: 6)
|
Spacer().frame(height: 6)
|
||||||
TabView {
|
TabView {
|
||||||
|
SummaryView(
|
||||||
|
server: resolvedBinding,
|
||||||
|
canRestart: canRestart,
|
||||||
|
isRestarting: isRestarting
|
||||||
|
) {
|
||||||
|
showRestartSheet = true
|
||||||
|
}
|
||||||
|
.tabItem {
|
||||||
|
Text("Summary").unredacted()
|
||||||
|
}
|
||||||
GeneralView(
|
GeneralView(
|
||||||
server: resolvedBinding,
|
server: resolvedBinding,
|
||||||
canRestart: canRestart,
|
canRestart: canRestart,
|
||||||
@@ -85,21 +89,6 @@ struct ServerDetailView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(indicatorTimer) { _ in
|
|
||||||
guard showIntervalIndicator else { return }
|
|
||||||
withAnimation(.linear(duration: 1)) {
|
|
||||||
progress += 1.0 / Double(refreshInterval)
|
|
||||||
if progress >= 1 { progress = 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onChange(of: refreshInterval) { _, _ in
|
|
||||||
progress = 0
|
|
||||||
}
|
|
||||||
.onChange(of: showIntervalIndicator) { _, isVisible in
|
|
||||||
if !isVisible {
|
|
||||||
progress = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showRestartSheet) {
|
.sheet(isPresented: $showRestartSheet) {
|
||||||
RestartConfirmationSheet(
|
RestartConfirmationSheet(
|
||||||
hostname: server.hostname,
|
hostname: server.hostname,
|
||||||
@@ -133,6 +122,30 @@ struct ServerDetailView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct RefreshIntervalIndicator: View {
|
||||||
|
@AppStorage("refreshInterval") private var refreshInterval: Int = 60
|
||||||
|
@State private var progress: Double = 0
|
||||||
|
private let indicatorTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ProgressView(value: progress)
|
||||||
|
.progressViewStyle(LinearProgressViewStyle())
|
||||||
|
.padding(.horizontal)
|
||||||
|
.frame(height: 2)
|
||||||
|
.onReceive(indicatorTimer) { _ in
|
||||||
|
withAnimation(.linear(duration: 1)) {
|
||||||
|
progress += 1.0 / Double(max(refreshInterval, 1))
|
||||||
|
if progress >= 1 {
|
||||||
|
progress = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: refreshInterval) { _, _ in
|
||||||
|
progress = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ServerDetailView(
|
ServerDetailView(
|
||||||
server: .constant(Server(id: UUID(), hostname: "preview.example.com", info: ServerInfo.placeholder)),
|
server: .constant(Server(id: UUID(), hostname: "preview.example.com", info: ServerInfo.placeholder)),
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ struct ServerFormView: View {
|
|||||||
var mode: Mode
|
var mode: Mode
|
||||||
|
|
||||||
@Binding var servers: [Server]
|
@Binding var servers: [Server]
|
||||||
|
@Binding var groups: [ServerGroup]
|
||||||
|
|
||||||
@State private var hostname: String
|
@State private var hostname: String
|
||||||
@State private var apiKey: String
|
@State private var apiKey: String
|
||||||
|
@State private var selectedGroupID: UUID?
|
||||||
@State private var connectionOK: Bool = false
|
@State private var connectionOK: Bool = false
|
||||||
@State private var testingConnection: Bool = false
|
@State private var testingConnection: Bool = false
|
||||||
@State private var connectionError: String = ""
|
@State private var connectionError: String = ""
|
||||||
@@ -29,25 +31,30 @@ struct ServerFormView: View {
|
|||||||
init(
|
init(
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
servers: Binding<[Server]>,
|
servers: Binding<[Server]>,
|
||||||
|
groups: Binding<[ServerGroup]>,
|
||||||
dismiss: @escaping () -> Void
|
dismiss: @escaping () -> Void
|
||||||
) {
|
) {
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self._servers = servers
|
self._servers = servers
|
||||||
|
self._groups = groups
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case .add:
|
case .add:
|
||||||
self._hostname = State(initialValue: "")
|
self._hostname = State(initialValue: "")
|
||||||
self._apiKey = State(initialValue: "")
|
self._apiKey = State(initialValue: "")
|
||||||
|
self._selectedGroupID = State(initialValue: nil)
|
||||||
case .edit(let server):
|
case .edit(let server):
|
||||||
self._hostname = State(initialValue: server.hostname)
|
self._hostname = State(initialValue: server.hostname)
|
||||||
self._apiKey = State(initialValue: KeychainHelper.loadApiKey(for: server.hostname) ?? "")
|
self._apiKey = State(initialValue: KeychainHelper.loadApiKey(for: server.hostname) ?? "")
|
||||||
|
self._selectedGroupID = State(initialValue: server.groupID)
|
||||||
|
self._connectionOK = State(initialValue: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Text("Edit Server")
|
Text(modeTitle)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
|
||||||
TextField("Hostname", text: $hostname)
|
TextField("Hostname", text: $hostname)
|
||||||
@@ -57,6 +64,14 @@ struct ServerFormView: View {
|
|||||||
SecureField("API Key", text: $apiKey)
|
SecureField("API Key", text: $apiKey)
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||||
|
|
||||||
|
Picker("Group", selection: $selectedGroupID) {
|
||||||
|
Text("No Group").tag(nil as UUID?)
|
||||||
|
ForEach(groups) { group in
|
||||||
|
Text(group.name).tag(Optional(group.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.menu)
|
||||||
|
|
||||||
if !connectionError.isEmpty {
|
if !connectionError.isEmpty {
|
||||||
Text(connectionError)
|
Text(connectionError)
|
||||||
.foregroundColor(.red)
|
.foregroundColor(.red)
|
||||||
@@ -77,8 +92,6 @@ struct ServerFormView: View {
|
|||||||
|
|
||||||
Button("Save") {
|
Button("Save") {
|
||||||
saveServer()
|
saveServer()
|
||||||
updateServer()
|
|
||||||
saveServers()
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
.disabled(hostname.isEmpty || apiKey.isEmpty || !connectionOK)
|
.disabled(hostname.isEmpty || apiKey.isEmpty || !connectionOK)
|
||||||
@@ -93,6 +106,8 @@ struct ServerFormView: View {
|
|||||||
print("serve \(server)")
|
print("serve \(server)")
|
||||||
hostname = server.hostname
|
hostname = server.hostname
|
||||||
apiKey = KeychainHelper.loadApiKey(for: server.hostname) ?? ""
|
apiKey = KeychainHelper.loadApiKey(for: server.hostname) ?? ""
|
||||||
|
selectedGroupID = server.groupID
|
||||||
|
connectionOK = true
|
||||||
print("💡 Loaded server: \(hostname)")
|
print("💡 Loaded server: \(hostname)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,41 +220,23 @@ struct ServerFormView: View {
|
|||||||
switch mode {
|
switch mode {
|
||||||
case .add:
|
case .add:
|
||||||
print("adding server")
|
print("adding server")
|
||||||
let newServer = Server(hostname: trimmedHost)
|
let newServer = Server(hostname: trimmedHost, groupID: selectedGroupID)
|
||||||
servers.append(newServer)
|
servers.append(newServer)
|
||||||
KeychainHelper.saveApiKey(trimmedKey, for: trimmedHost)
|
KeychainHelper.saveApiKey(trimmedKey, for: trimmedHost)
|
||||||
saveServers()
|
|
||||||
case .edit(let oldServer):
|
case .edit(let oldServer):
|
||||||
if let index = servers.firstIndex(where: { $0.id == oldServer.id }) {
|
if let index = servers.firstIndex(where: { $0.id == oldServer.id }) {
|
||||||
let oldHostname = servers[index].hostname
|
let oldHostname = servers[index].hostname
|
||||||
servers[index].hostname = trimmedHost
|
servers[index].hostname = trimmedHost
|
||||||
|
servers[index].groupID = selectedGroupID
|
||||||
if oldHostname != trimmedHost {
|
if oldHostname != trimmedHost {
|
||||||
KeychainHelper.deleteApiKey(for: oldHostname)
|
KeychainHelper.deleteApiKey(for: oldHostname)
|
||||||
}
|
}
|
||||||
KeychainHelper.saveApiKey(trimmedKey, for: trimmedHost)
|
KeychainHelper.saveApiKey(trimmedKey, for: trimmedHost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private func updateServer() {
|
|
||||||
print ("in edit server")
|
|
||||||
guard case let .edit(server) = mode else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if let index = servers.firstIndex(where: { $0.id == server.id }) {
|
|
||||||
// Only replace hostname if changed
|
|
||||||
let oldHostname = servers[index].hostname
|
|
||||||
servers[index].hostname = hostname
|
|
||||||
|
|
||||||
// Update Keychain
|
|
||||||
if oldHostname != hostname {
|
|
||||||
KeychainHelper.deleteApiKey(for: oldHostname)
|
|
||||||
}
|
|
||||||
KeychainHelper.saveApiKey(apiKey, for: hostname)
|
|
||||||
saveServers()
|
saveServers()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private func saveServers() {
|
private func saveServers() {
|
||||||
if let data = try? JSONEncoder().encode(servers) {
|
if let data = try? JSONEncoder().encode(servers) {
|
||||||
@@ -265,6 +262,9 @@ struct ServerFormView: View {
|
|||||||
servers: .constant([
|
servers: .constant([
|
||||||
Server(hostname: "example.com")
|
Server(hostname: "example.com")
|
||||||
]),
|
]),
|
||||||
|
groups: .constant([
|
||||||
|
ServerGroup(name: "Production")
|
||||||
|
]),
|
||||||
dismiss: {}
|
dismiss: {}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,53 +49,76 @@ struct GeneralView: View {
|
|||||||
|
|
||||||
TableRowView {
|
TableRowView {
|
||||||
Text("Operating system")
|
Text("Operating system")
|
||||||
|
} value: {
|
||||||
|
InfoCell(value: operatingSystemRows, monospaced: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
TableRowView {
|
||||||
|
Text("CPU")
|
||||||
} value: {
|
} value: {
|
||||||
InfoCell(
|
InfoCell(
|
||||||
value: {
|
value: [
|
||||||
guard let os = server.info?.operatingSystem else { return [] }
|
"\(server.info?.cpuCores ?? 0) cores",
|
||||||
var rows: [String] = []
|
String(format: "Load %.2f%% (%.2f / %.2f / %.2f)",
|
||||||
|
server.info?.load.percent ?? 0,
|
||||||
let distro = [os.distribution, os.version]
|
server.info?.load.minute1 ?? 0,
|
||||||
.filter { !$0.isEmpty }
|
server.info?.load.minute5 ?? 0,
|
||||||
.joined(separator: " ")
|
server.info?.load.minute15 ?? 0)
|
||||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
],
|
||||||
var description = os.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if description.isEmpty {
|
|
||||||
description = distro
|
|
||||||
} else if !distro.isEmpty && description.range(of: distro, options: [.caseInsensitive]) == nil {
|
|
||||||
description += " • \(distro)"
|
|
||||||
}
|
|
||||||
if !os.architecture.isEmpty &&
|
|
||||||
description.range(of: os.architecture, options: [.caseInsensitive]) == nil {
|
|
||||||
description += " (\(os.architecture))"
|
|
||||||
}
|
|
||||||
if !description.isEmpty {
|
|
||||||
rows.append(description)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let updates = os.updates {
|
|
||||||
var updateDescription = "Updates: \(updates.updateCount)"
|
|
||||||
if updates.securityUpdateCount > 0 {
|
|
||||||
updateDescription += " • \(updates.securityUpdateCount) security"
|
|
||||||
}
|
|
||||||
rows.append(updateDescription)
|
|
||||||
if updates.rebootRequired {
|
|
||||||
rows.append("Reboot required")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if os.endOfLife {
|
|
||||||
rows.append("End-of-life release")
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows
|
|
||||||
}(),
|
|
||||||
monospaced: true
|
monospaced: true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
TableRowView {
|
TableRowView {
|
||||||
Text("Sytem PHP version")
|
Text("Memory")
|
||||||
|
} value: {
|
||||||
|
InfoCell(
|
||||||
|
value: [
|
||||||
|
"Used \(server.info?.memory.used ?? 0) / Total \(server.info?.memory.total ?? 0)",
|
||||||
|
String(format: "%.2f %%", server.info?.memory.percent ?? 0)
|
||||||
|
].map { line in
|
||||||
|
line
|
||||||
|
.replacingOccurrences(of: "\(server.info?.memory.used ?? 0)", with: (server.info?.memory.used ?? 0).toNiceBinaryUnit())
|
||||||
|
.replacingOccurrences(of: "\(server.info?.memory.total ?? 0)", with: (server.info?.memory.total ?? 0).toNiceBinaryUnit())
|
||||||
|
},
|
||||||
|
monospaced: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TableRowView {
|
||||||
|
Text("Swap")
|
||||||
|
} value: {
|
||||||
|
InfoCell(
|
||||||
|
value: [
|
||||||
|
"Used \(server.info?.swap.used ?? 0) / Total \(server.info?.swap.total ?? 0)",
|
||||||
|
String(format: "%.2f %%", server.info?.swap.percent ?? 0)
|
||||||
|
].map { line in
|
||||||
|
line
|
||||||
|
.replacingOccurrences(of: "\(server.info?.swap.used ?? 0)", with: (server.info?.swap.used ?? 0).toNiceBinaryUnit())
|
||||||
|
.replacingOccurrences(of: "\(server.info?.swap.total ?? 0)", with: (server.info?.swap.total ?? 0).toNiceBinaryUnit())
|
||||||
|
},
|
||||||
|
monospaced: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TableRowView {
|
||||||
|
Text("Disk space")
|
||||||
|
} value: {
|
||||||
|
InfoCell(
|
||||||
|
value: [
|
||||||
|
"Used \(server.info?.diskSpace.used ?? 0) / Total \(server.info?.diskSpace.total ?? 0)",
|
||||||
|
String(format: "%.2f %%", server.info?.diskSpace.percent ?? 0)
|
||||||
|
].map { line in
|
||||||
|
line
|
||||||
|
.replacingOccurrences(of: "\(server.info?.diskSpace.used ?? 0)", with: (server.info?.diskSpace.used ?? 0).toNiceBinaryUnit())
|
||||||
|
.replacingOccurrences(of: "\(server.info?.diskSpace.total ?? 0)", with: (server.info?.diskSpace.total ?? 0).toNiceBinaryUnit())
|
||||||
|
},
|
||||||
|
monospaced: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TableRowView {
|
||||||
|
Text("System PHP version")
|
||||||
} value: {
|
} value: {
|
||||||
InfoCell(value: [server.info?.phpVersion ?? ""], monospaced: true)
|
InfoCell(value: [server.info?.phpVersion ?? ""], monospaced: true)
|
||||||
}
|
}
|
||||||
@@ -103,22 +126,7 @@ struct GeneralView: View {
|
|||||||
TableRowView(showDivider: false) {
|
TableRowView(showDivider: false) {
|
||||||
Text("Additional PHP interpreters")
|
Text("Additional PHP interpreters")
|
||||||
} value: {
|
} value: {
|
||||||
InfoCell(
|
InfoCell(value: additionalPHPRows, monospaced: true)
|
||||||
value: {
|
|
||||||
let interpreters = server.info?.additionalPHPInterpreters ?? []
|
|
||||||
if interpreters.isEmpty {
|
|
||||||
return ["None"]
|
|
||||||
}
|
|
||||||
let versions = interpreters
|
|
||||||
.map { $0.fullVersion }
|
|
||||||
.filter { !$0.isEmpty }
|
|
||||||
if versions.isEmpty {
|
|
||||||
return ["None"]
|
|
||||||
}
|
|
||||||
return [versions.joined(separator: " • ")]
|
|
||||||
}(),
|
|
||||||
monospaced: true
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if canRestart, let onRestart {
|
if canRestart, let onRestart {
|
||||||
@@ -155,6 +163,60 @@ struct GeneralView: View {
|
|||||||
.scrollDisabled(true)
|
.scrollDisabled(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var operatingSystemRows: [String] {
|
||||||
|
guard let os = server.info?.operatingSystem else { return [] }
|
||||||
|
var rows: [String] = []
|
||||||
|
|
||||||
|
let distro = [os.distribution, os.version]
|
||||||
|
.filter { !$0.isEmpty }
|
||||||
|
.joined(separator: " ")
|
||||||
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
|
||||||
|
var description = os.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
if description.isEmpty {
|
||||||
|
description = distro
|
||||||
|
} else if !distro.isEmpty && description.range(of: distro, options: [.caseInsensitive]) == nil {
|
||||||
|
description += " • \(distro)"
|
||||||
|
}
|
||||||
|
if !os.architecture.isEmpty &&
|
||||||
|
description.range(of: os.architecture, options: [.caseInsensitive]) == nil {
|
||||||
|
description += " (\(os.architecture))"
|
||||||
|
}
|
||||||
|
if !description.isEmpty {
|
||||||
|
rows.append(description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let updates = os.updates {
|
||||||
|
var updateDescription = "Updates: \(updates.updateCount)"
|
||||||
|
if updates.securityUpdateCount > 0 {
|
||||||
|
updateDescription += " • \(updates.securityUpdateCount) security"
|
||||||
|
}
|
||||||
|
rows.append(updateDescription)
|
||||||
|
if updates.rebootRequired {
|
||||||
|
rows.append("Reboot required")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.endOfLife {
|
||||||
|
rows.append("End-of-life release")
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
private var additionalPHPRows: [String] {
|
||||||
|
let interpreters = server.info?.additionalPHPInterpreters ?? []
|
||||||
|
let versions = interpreters
|
||||||
|
.map { $0.fullVersion }
|
||||||
|
.filter { !$0.isEmpty }
|
||||||
|
|
||||||
|
if versions.isEmpty {
|
||||||
|
return ["None"]
|
||||||
|
}
|
||||||
|
|
||||||
|
return [versions.joined(separator: " • ")]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
434
Sources/Views/Tabs/SummaryView.swift
Normal file
434
Sources/Views/Tabs/SummaryView.swift
Normal file
@@ -0,0 +1,434 @@
|
|||||||
|
//
|
||||||
|
// SummaryView.swift
|
||||||
|
// iKeyMon
|
||||||
|
//
|
||||||
|
// Created by tracer on 21.04.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import SwiftData
|
||||||
|
import Charts
|
||||||
|
|
||||||
|
struct SummaryView: View {
|
||||||
|
private enum TimeRange: String, CaseIterable, Identifiable {
|
||||||
|
case hour = "Hour"
|
||||||
|
case day = "Day"
|
||||||
|
case week = "Week"
|
||||||
|
case month = "Month"
|
||||||
|
|
||||||
|
var id: String { rawValue }
|
||||||
|
|
||||||
|
var duration: TimeInterval {
|
||||||
|
switch self {
|
||||||
|
case .hour:
|
||||||
|
return 60 * 60
|
||||||
|
case .day:
|
||||||
|
return 24 * 60 * 60
|
||||||
|
case .week:
|
||||||
|
return 7 * 24 * 60 * 60
|
||||||
|
case .month:
|
||||||
|
return 30 * 24 * 60 * 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var axisLabelFormat: Date.FormatStyle {
|
||||||
|
switch self {
|
||||||
|
case .hour:
|
||||||
|
return .dateTime.hour().minute()
|
||||||
|
case .day:
|
||||||
|
return .dateTime.hour()
|
||||||
|
case .week:
|
||||||
|
return .dateTime.month(.abbreviated).day()
|
||||||
|
case .month:
|
||||||
|
return .dateTime.month(.abbreviated).day()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Binding var server: Server
|
||||||
|
var canRestart: Bool = false
|
||||||
|
var isRestarting: Bool = false
|
||||||
|
var onRestart: (() -> Void)? = nil
|
||||||
|
@Query(sort: \MetricSample.timestamp, order: .forward) private var metricSamples: [MetricSample]
|
||||||
|
@State private var selectedRange: TimeRange = .hour
|
||||||
|
|
||||||
|
private let cardSpacing: CGFloat = 16
|
||||||
|
private let minCardWidth: CGFloat = 260
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
let contentWidth = max(geometry.size.width - 36, 0)
|
||||||
|
let chartColumns = summaryColumns(for: contentWidth)
|
||||||
|
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 18) {
|
||||||
|
summaryHeader
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Picker("Time Range", selection: $selectedRange) {
|
||||||
|
ForEach(TimeRange.allCases) { range in
|
||||||
|
Text(range.rawValue)
|
||||||
|
.tag(range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.frame(maxWidth: 260)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
|
||||||
|
LazyVGrid(columns: chartColumns, spacing: cardSpacing) {
|
||||||
|
historyChartCard(
|
||||||
|
title: "CPU usage",
|
||||||
|
currentValue: server.info?.load.percent ?? 0,
|
||||||
|
tint: loadTint,
|
||||||
|
samples: filteredSamples,
|
||||||
|
value: \.cpuPercent,
|
||||||
|
yAxisDomain: cpuChartDomain,
|
||||||
|
yAxisValues: nil,
|
||||||
|
clampValuesToDomain: false,
|
||||||
|
footer: [
|
||||||
|
("1 min", String(format: "%.2f", server.info?.load.minute1 ?? 0)),
|
||||||
|
("5 min", String(format: "%.2f", server.info?.load.minute5 ?? 0)),
|
||||||
|
("15 min", String(format: "%.2f", server.info?.load.minute15 ?? 0))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
historyChartCard(
|
||||||
|
title: "Memory usage",
|
||||||
|
currentValue: server.info?.memory.percent ?? 0,
|
||||||
|
tint: .blue,
|
||||||
|
samples: filteredSamples,
|
||||||
|
value: \.memoryPercent,
|
||||||
|
footer: [
|
||||||
|
("Used", (server.info?.memory.used ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Free", (server.info?.memory.free ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Total", (server.info?.memory.total ?? 0).toNiceBinaryUnit())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
historyChartCard(
|
||||||
|
title: "Disk usage",
|
||||||
|
currentValue: server.info?.diskSpace.percent ?? 0,
|
||||||
|
tint: .green,
|
||||||
|
samples: filteredSamples,
|
||||||
|
value: \.diskPercent,
|
||||||
|
footer: [
|
||||||
|
("Used", (server.info?.diskSpace.used ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Free", (server.info?.diskSpace.free ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Total", (server.info?.diskSpace.total ?? 0).toNiceBinaryUnit())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
historyChartCard(
|
||||||
|
title: "Swap usage",
|
||||||
|
currentValue: server.info?.swap.percent ?? 0,
|
||||||
|
tint: .orange,
|
||||||
|
samples: filteredSamples,
|
||||||
|
value: \.swapPercent,
|
||||||
|
footer: [
|
||||||
|
("Used", (server.info?.swap.used ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Free", (server.info?.swap.free ?? 0).toNiceBinaryUnit()),
|
||||||
|
("Total", (server.info?.swap.total ?? 0).toNiceBinaryUnit())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
.padding(18)
|
||||||
|
.frame(width: contentWidth, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func summaryColumns(for width: CGFloat) -> [GridItem] {
|
||||||
|
let count = max(1, min(4, Int((width + cardSpacing) / (minCardWidth + cardSpacing))))
|
||||||
|
return Array(
|
||||||
|
repeating: GridItem(.flexible(minimum: minCardWidth), spacing: cardSpacing, alignment: .top),
|
||||||
|
count: count
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var selectedRangeStart: Date {
|
||||||
|
Date().addingTimeInterval(-selectedRange.duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var filteredSamples: [MetricSample] {
|
||||||
|
return metricSamples.filter { sample in
|
||||||
|
sample.serverID == server.id && sample.timestamp >= selectedRangeStart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var cpuChartDomain: ClosedRange<Double> {
|
||||||
|
let values = filteredSamples.map(\.cpuPercent) + [server.info?.load.percent ?? 0]
|
||||||
|
let maximum = max(values.max() ?? 0, 100)
|
||||||
|
let roundedUpperBound = ceil(maximum / 25) * 25
|
||||||
|
return 0 ... roundedUpperBound
|
||||||
|
}
|
||||||
|
|
||||||
|
private var summaryHeader: some View {
|
||||||
|
dashboardCard {
|
||||||
|
HStack(alignment: .top, spacing: 16) {
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
HStack(alignment: .center, spacing: 10) {
|
||||||
|
Circle()
|
||||||
|
.fill(server.pingable ? Color.green : Color.red)
|
||||||
|
.frame(width: 10, height: 10)
|
||||||
|
|
||||||
|
Text(server.hostname)
|
||||||
|
.font(.system(size: 22, weight: .semibold))
|
||||||
|
|
||||||
|
statusBadge(server.pingable ? "Online" : "Offline", tint: server.pingable ? .green : .red)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
statusBadge(panelBadgeText, tint: .orange)
|
||||||
|
statusBadge(apiBadgeText, tint: .blue)
|
||||||
|
if let operatingSystemSummary = server.info?.operatingSystemSummary, !operatingSystemSummary.isEmpty {
|
||||||
|
statusBadge(operatingSystemSummary, tint: .secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(summaryLine)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(minLength: 12)
|
||||||
|
|
||||||
|
if canRestart, let onRestart {
|
||||||
|
Button(role: .destructive) {
|
||||||
|
onRestart()
|
||||||
|
} label: {
|
||||||
|
if isRestarting {
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
ProgressView()
|
||||||
|
.controlSize(.small)
|
||||||
|
Text("Rebooting…")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Label("Reboot Server", systemImage: "arrow.clockwise.circle")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.disabled(isRestarting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func historyChartCard(
|
||||||
|
title: String,
|
||||||
|
currentValue: Double,
|
||||||
|
tint: Color,
|
||||||
|
samples: [MetricSample],
|
||||||
|
value: KeyPath<MetricSample, Double>,
|
||||||
|
yAxisDomain: ClosedRange<Double> = 0...100,
|
||||||
|
yAxisValues: [Double]? = [0, 25, 50, 75, 100],
|
||||||
|
clampValuesToDomain: Bool = true,
|
||||||
|
footer: [(String, String)],
|
||||||
|
caption: String? = nil
|
||||||
|
) -> some View {
|
||||||
|
dashboardCard {
|
||||||
|
VStack(alignment: .leading, spacing: 14) {
|
||||||
|
HStack(alignment: .firstTextBaseline) {
|
||||||
|
Text(title)
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text(String(format: "%.2f %%", currentValue))
|
||||||
|
.font(.title3.weight(.semibold))
|
||||||
|
.foregroundStyle(tint)
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
|
||||||
|
if samples.isEmpty {
|
||||||
|
ContentUnavailableView(
|
||||||
|
"No chart data yet",
|
||||||
|
systemImage: "chart.xyaxis.line",
|
||||||
|
description: Text("History appears after a few refresh cycles.")
|
||||||
|
)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.padding(.vertical, 24)
|
||||||
|
} else {
|
||||||
|
Chart(samples) { sample in
|
||||||
|
let rawValue = sample[keyPath: value]
|
||||||
|
let sampleValue = clampValuesToDomain
|
||||||
|
? min(max(rawValue, yAxisDomain.lowerBound), yAxisDomain.upperBound)
|
||||||
|
: rawValue
|
||||||
|
|
||||||
|
AreaMark(
|
||||||
|
x: .value("Time", sample.timestamp),
|
||||||
|
y: .value(title, sampleValue)
|
||||||
|
)
|
||||||
|
.interpolationMethod(.catmullRom)
|
||||||
|
.foregroundStyle(
|
||||||
|
LinearGradient(
|
||||||
|
colors: [
|
||||||
|
tint.opacity(0.55),
|
||||||
|
tint.opacity(0.12)
|
||||||
|
],
|
||||||
|
startPoint: .top,
|
||||||
|
endPoint: .bottom
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
LineMark(
|
||||||
|
x: .value("Time", sample.timestamp),
|
||||||
|
y: .value(title, sampleValue)
|
||||||
|
)
|
||||||
|
.interpolationMethod(.catmullRom)
|
||||||
|
.foregroundStyle(tint)
|
||||||
|
.lineStyle(StrokeStyle(lineWidth: 2))
|
||||||
|
}
|
||||||
|
.chartYScale(domain: yAxisDomain)
|
||||||
|
.chartXScale(domain: selectedRangeStart ... Date())
|
||||||
|
.chartXAxis {
|
||||||
|
AxisMarks(values: .automatic(desiredCount: 6)) { value in
|
||||||
|
AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5))
|
||||||
|
.foregroundStyle(.secondary.opacity(0.25))
|
||||||
|
AxisTick()
|
||||||
|
.foregroundStyle(.secondary.opacity(0.7))
|
||||||
|
AxisValueLabel(format: selectedRange.axisLabelFormat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.chartYAxis {
|
||||||
|
if let yAxisValues {
|
||||||
|
AxisMarks(position: .leading, values: yAxisValues) { value in
|
||||||
|
AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5))
|
||||||
|
.foregroundStyle(.secondary.opacity(0.2))
|
||||||
|
AxisTick()
|
||||||
|
.foregroundStyle(.secondary.opacity(0.7))
|
||||||
|
AxisValueLabel {
|
||||||
|
if let percent = value.as(Double.self) {
|
||||||
|
Text("\(Int(percent))%")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AxisMarks(position: .leading, values: .automatic(desiredCount: 5)) { value in
|
||||||
|
AxisGridLine(stroke: StrokeStyle(lineWidth: 0.5))
|
||||||
|
.foregroundStyle(.secondary.opacity(0.2))
|
||||||
|
AxisTick()
|
||||||
|
.foregroundStyle(.secondary.opacity(0.7))
|
||||||
|
AxisValueLabel {
|
||||||
|
if let percent = value.as(Double.self) {
|
||||||
|
Text("\(Int(percent))%")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 220)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 16) {
|
||||||
|
ForEach(Array(footer.enumerated()), id: \.offset) { _, item in
|
||||||
|
metric(item.0, value: item.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let caption {
|
||||||
|
Text(caption)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func metric(_ title: String, value: String) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(title.uppercased())
|
||||||
|
.font(.caption2.weight(.semibold))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(value)
|
||||||
|
.font(.system(.body, design: .monospaced))
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func statusBadge(_ text: String, tint: Color) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.caption.weight(.semibold))
|
||||||
|
.foregroundStyle(tint == .secondary ? .secondary : tint)
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.vertical, 5)
|
||||||
|
.background {
|
||||||
|
Capsule(style: .continuous)
|
||||||
|
.fill(tint == .secondary ? Color.secondary.opacity(0.12) : tint.opacity(0.14))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func dashboardCard<Content: View>(@ViewBuilder content: () -> Content) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
.padding(18)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
||||||
|
.fill(Color.white.opacity(0.03))
|
||||||
|
)
|
||||||
|
.overlay {
|
||||||
|
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
||||||
|
.stroke(Color.white.opacity(0.06), lineWidth: 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var apiBadgeText: String {
|
||||||
|
guard let apiVersion = server.info?.apiVersion, !apiVersion.isEmpty else {
|
||||||
|
return "API unknown"
|
||||||
|
}
|
||||||
|
return "API \(apiVersion)"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var panelBadgeText: String {
|
||||||
|
guard let panelVersion = server.info?.panelVersion, !panelVersion.isEmpty else {
|
||||||
|
return "KeyHelp unknown"
|
||||||
|
}
|
||||||
|
return "KeyHelp \(panelVersion)"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var summaryLine: String {
|
||||||
|
var parts: [String] = []
|
||||||
|
|
||||||
|
if let uptime = server.info?.uptime, !uptime.isEmpty {
|
||||||
|
parts.append("Uptime \(uptime)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let serverTime = server.info?.formattedServerTime, !serverTime.isEmpty {
|
||||||
|
parts.append("Server time \(serverTime)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if parts.isEmpty {
|
||||||
|
return "Live summary for \(server.hostname)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.joined(separator: " • ")
|
||||||
|
}
|
||||||
|
|
||||||
|
private var loadTint: Color {
|
||||||
|
switch server.info?.load.level.lowercased() {
|
||||||
|
case "warning":
|
||||||
|
return .orange
|
||||||
|
case "critical":
|
||||||
|
return .red
|
||||||
|
default:
|
||||||
|
return .green
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
struct PreviewWrapper: View {
|
||||||
|
@State var previewServer = Server(hostname: "example.com", info: .placeholder)
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
SummaryView(server: $previewServer, canRestart: true)
|
||||||
|
.padding()
|
||||||
|
.frame(width: 1100, height: 760)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PreviewWrapper()
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import SwiftData
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
import AppKit
|
import AppKit
|
||||||
#endif
|
#endif
|
||||||
@@ -13,6 +14,7 @@ import AppKit
|
|||||||
@main
|
@main
|
||||||
struct iKeyMonApp: App {
|
struct iKeyMonApp: App {
|
||||||
@StateObject private var sparkleUpdater = SparkleUpdater()
|
@StateObject private var sparkleUpdater = SparkleUpdater()
|
||||||
|
private let modelContainer: ModelContainer
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@@ -20,6 +22,8 @@ struct iKeyMonApp: App {
|
|||||||
NSApplication.shared.applicationIconImage = customIcon
|
NSApplication.shared.applicationIconImage = customIcon
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
self.modelContainer = Self.makeModelContainer()
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
@@ -30,6 +34,7 @@ struct iKeyMonApp: App {
|
|||||||
NSApp.terminate(nil)
|
NSApp.terminate(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.modelContainer(modelContainer)
|
||||||
.windowResizability(.contentMinSize)
|
.windowResizability(.contentMinSize)
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
@@ -38,4 +43,55 @@ struct iKeyMonApp: App {
|
|||||||
.environmentObject(sparkleUpdater)
|
.environmentObject(sparkleUpdater)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func makeModelContainer() -> ModelContainer {
|
||||||
|
let schema = Schema([MetricSample.self])
|
||||||
|
let storeURL = metricStoreURL()
|
||||||
|
let configuration = ModelConfiguration(url: storeURL)
|
||||||
|
|
||||||
|
do {
|
||||||
|
return try ModelContainer(for: schema, configurations: [configuration])
|
||||||
|
} catch {
|
||||||
|
print("⚠️ [SwiftData] Failed to open metric store at \(storeURL.path): \(error)")
|
||||||
|
resetMetricStore(at: storeURL)
|
||||||
|
|
||||||
|
do {
|
||||||
|
return try ModelContainer(for: schema, configurations: [configuration])
|
||||||
|
} catch {
|
||||||
|
fatalError("Unable to create metric history store: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func metricStoreURL() -> URL {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let appSupport = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
||||||
|
let directory = appSupport
|
||||||
|
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "net.24unix.iKeyMon", isDirectory: true)
|
||||||
|
|
||||||
|
do {
|
||||||
|
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
|
||||||
|
} catch {
|
||||||
|
fatalError("Unable to create application support directory: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
return directory.appendingPathComponent("metric-history.store")
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func resetMetricStore(at url: URL) {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let sidecarURLs = [
|
||||||
|
url,
|
||||||
|
url.appendingPathExtension("shm"),
|
||||||
|
url.appendingPathExtension("wal")
|
||||||
|
]
|
||||||
|
|
||||||
|
for sidecarURL in sidecarURLs where fileManager.fileExists(atPath: sidecarURL.path) {
|
||||||
|
do {
|
||||||
|
try fileManager.removeItem(at: sidecarURL)
|
||||||
|
} catch {
|
||||||
|
print("⚠️ [SwiftData] Failed to remove \(sidecarURL.path): \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
Sparkle/appcast.xml
vendored
32
Sparkle/appcast.xml
vendored
@@ -2,6 +2,22 @@
|
|||||||
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
|
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<title>iKeyMon</title>
|
<title>iKeyMon</title>
|
||||||
|
<item>
|
||||||
|
<title>26.1.11</title>
|
||||||
|
<pubDate>Tue, 21 Apr 2026 18:06:37 +0200</pubDate>
|
||||||
|
<sparkle:version>187</sparkle:version>
|
||||||
|
<sparkle:shortVersionString>26.1.11</sparkle:shortVersionString>
|
||||||
|
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
||||||
|
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.11/iKeyMon-26.1.11.zip" length="3292064" type="application/octet-stream" sparkle:edSignature="8+eCOcRbetd/LCrEPYNDD6K1F+V+8lflUORk1piWrWtGkKD4Q1GQhJ9rNTZ1gcGKHaqXf024y4h4uoHeo4/yBw=="/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>26.1.10</title>
|
||||||
|
<pubDate>Tue, 21 Apr 2026 00:18:16 +0200</pubDate>
|
||||||
|
<sparkle:version>184</sparkle:version>
|
||||||
|
<sparkle:shortVersionString>26.1.10</sparkle:shortVersionString>
|
||||||
|
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
||||||
|
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.10/iKeyMon-26.1.10.zip" length="3193339" type="application/octet-stream" sparkle:edSignature="SwXVc4kmCUAec7VcDcoxDySDhGTXwdLz30q9SiyvaGK/P7cel3iljlvDd6Rc4/M1wtHoOZXXo+93lFhnLMB+Aw=="/>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<title>26.1.9</title>
|
<title>26.1.9</title>
|
||||||
<pubDate>Sun, 19 Apr 2026 23:04:07 +0200</pubDate>
|
<pubDate>Sun, 19 Apr 2026 23:04:07 +0200</pubDate>
|
||||||
@@ -10,21 +26,5 @@
|
|||||||
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
||||||
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.9/iKeyMon-26.1.9.zip" length="3109488" type="application/octet-stream" sparkle:edSignature="ZV96uUMdYC/X90H3G10FMzmZHKUEWpe1geSe/5IBJ7EOCUmx7Mz352i6VMWumFnCtDD4jHo173W9eySUX9KvDA=="/>
|
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.9/iKeyMon-26.1.9.zip" length="3109488" type="application/octet-stream" sparkle:edSignature="ZV96uUMdYC/X90H3G10FMzmZHKUEWpe1geSe/5IBJ7EOCUmx7Mz352i6VMWumFnCtDD4jHo173W9eySUX9KvDA=="/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<title>26.1.8</title>
|
|
||||||
<pubDate>Sun, 19 Apr 2026 22:50:15 +0200</pubDate>
|
|
||||||
<sparkle:version>179</sparkle:version>
|
|
||||||
<sparkle:shortVersionString>26.1.8</sparkle:shortVersionString>
|
|
||||||
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
|
||||||
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.8/iKeyMon-26.1.8.zip" length="3108005" type="application/octet-stream" sparkle:edSignature="OyoweSuRk5kusKUlqKQudZjrHkw5UPrLkix+ccpKphO1en2XdtQZa61hnA6HwcHM302jb+YlvN8n9f2Zkr9GBg=="/>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<title>26.1.7</title>
|
|
||||||
<pubDate>Sun, 19 Apr 2026 16:54:42 +0200</pubDate>
|
|
||||||
<sparkle:version>177</sparkle:version>
|
|
||||||
<sparkle:shortVersionString>26.1.7</sparkle:shortVersionString>
|
|
||||||
<sparkle:minimumSystemVersion>15.2</sparkle:minimumSystemVersion>
|
|
||||||
<enclosure url="https://git.24unix.net/tracer/iKeyMon/releases/download/v26.1.7/iKeyMon-26.1.7.zip" length="3106520" type="application/octet-stream" sparkle:edSignature="xuNlxCsTtVgroriFU7fphcfHxAEC8cpd6tHnHMXknJ2jvKm27ShQMqjSW2jdqNAz0a0kNtPM8HwTL+e6nvUyCQ=="/>
|
|
||||||
</item>
|
|
||||||
</channel>
|
</channel>
|
||||||
</rss>
|
</rss>
|
||||||
@@ -322,7 +322,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = iKeyMon.entitlements;
|
CODE_SIGN_ENTITLEMENTS = iKeyMon.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 181;
|
CURRENT_PROJECT_VERSION = 187;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = Q5486ZVAFT;
|
DEVELOPMENT_TEAM = Q5486ZVAFT;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@@ -337,7 +337,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 26.1.9;
|
MARKETING_VERSION = 26.1.11;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.24unix.iKeyMon;
|
PRODUCT_BUNDLE_IDENTIFIER = net.24unix.iKeyMon;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -353,7 +353,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = iKeyMon.entitlements;
|
CODE_SIGN_ENTITLEMENTS = iKeyMon.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 181;
|
CURRENT_PROJECT_VERSION = 187;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = Q5486ZVAFT;
|
DEVELOPMENT_TEAM = Q5486ZVAFT;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@@ -368,7 +368,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 26.1.9;
|
MARKETING_VERSION = 26.1.11;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.24unix.iKeyMon;
|
PRODUCT_BUNDLE_IDENTIFIER = net.24unix.iKeyMon;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"marketing_version": "26.1.9"
|
"marketing_version": "26.1.11"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user