1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-03-30 16:30:09 +02:00

🐛 Address some MainActor annotations

This commit is contained in:
2025-11-26 12:07:58 +01:00
parent 7089a1c9e8
commit bd85584c88
4 changed files with 25 additions and 27 deletions

View File

@@ -151,24 +151,20 @@ extension MainMenu {
When the environment is not OK, present an alert to inform the user. When the environment is not OK, present an alert to inform the user.
*/ */
private func onEnvironmentFail() async { private func onEnvironmentFail() async {
Task { @MainActor [self] in NVAlert()
NVAlert() .withInformation(
.withInformation( title: "alert.cannot_start.title".localized,
title: "alert.cannot_start.title".localized, subtitle: "alert.cannot_start.subtitle".localized,
subtitle: "alert.cannot_start.subtitle".localized, description: "alert.cannot_start.description".localized
description: "alert.cannot_start.description".localized )
) .withPrimary(text: "alert.cannot_start.retry".localized)
.withPrimary(text: "alert.cannot_start.retry".localized) .withSecondary(text: "alert.cannot_start.close".localized, action: { vc in
.withSecondary(text: "alert.cannot_start.close".localized, action: { vc in vc.close(with: .alertSecondButtonReturn)
vc.close(with: .alertSecondButtonReturn) exit(1)
exit(1) })
}) .show()
.show()
Task { // An issue occurred, fire startup checks again after dismissal await startup()
await startup()
}
}
} }
/** /**

View File

@@ -24,6 +24,7 @@ struct HeaderView: View {
// MARK: - NSMenuItem // MARK: - NSMenuItem
@MainActor
static func asMenuItem( static func asMenuItem(
text: String, text: String,
minimumWidth: CGFloat? = nil minimumWidth: CGFloat? = nil

View File

@@ -12,6 +12,7 @@ import NVAlert
struct ServicesView: View { struct ServicesView: View {
@MainActor
static func asMenuItem(perRow: Int = 4) -> NSMenuItem { static func asMenuItem(perRow: Int = 4) -> NSMenuItem {
let view = { let view = {
let rootView = Self(manager: ServicesManager.shared, perRow: perRow) let rootView = Self(manager: ServicesManager.shared, perRow: perRow)
@@ -103,6 +104,13 @@ struct ServiceView: View {
var service: Service var service: Service
@State var isBusy: Bool = false @State var isBusy: Bool = false
@MainActor
private func toggleService() async {
isBusy = true
await ServicesManager.shared.toggleService(named: service.name)
isBusy = false
}
var body: some View { var body: some View {
VStack(alignment: .center, spacing: 0) { VStack(alignment: .center, spacing: 0) {
Text(service.name.uppercased()) Text(service.name.uppercased())
@@ -133,11 +141,7 @@ struct ServiceView: View {
} }
if service.status == .error { if service.status == .error {
Button { Button {
Task { Task { await toggleService() }
isBusy = true
await ServicesManager.shared.toggleService(named: service.name)
isBusy = false
}
} label: { } label: {
Text("E") Text("E")
.frame(width: 12.0, height: 12.0) .frame(width: 12.0, height: 12.0)
@@ -148,11 +152,7 @@ struct ServiceView: View {
} }
if service.status == .active || service.status == .inactive { if service.status == .active || service.status == .inactive {
Button { Button {
Task { Task { await toggleService() }
isBusy = true
await ServicesManager.shared.toggleService(named: service.name)
isBusy = false
}
} label: { } label: {
Image( Image(
systemName: service.status == .active ? "checkmark" : "xmark" systemName: service.status == .active ? "checkmark" : "xmark"

View File

@@ -10,6 +10,7 @@ import SwiftUI
struct StatsView: View { struct StatsView: View {
@MainActor
static func asMenuItem(memory: String, post: String, upload: String) -> NSMenuItem { static func asMenuItem(memory: String, post: String, upload: String) -> NSMenuItem {
let item = NSMenuItem() let item = NSMenuItem()
let view = NSHostingView( let view = NSHostingView(