fix(macos): wrap usage errors in menu
This commit is contained in:
@@ -285,13 +285,23 @@ final class MenuSessionsInjector: NSObject, NSMenuDelegate {
|
|||||||
headerItem.isEnabled = false
|
headerItem.isEnabled = false
|
||||||
headerItem.view = self.makeHostedView(
|
headerItem.view = self.makeHostedView(
|
||||||
rootView: AnyView(MenuUsageHeaderView(
|
rootView: AnyView(MenuUsageHeaderView(
|
||||||
count: rows.count,
|
count: rows.count)),
|
||||||
statusText: errorText)),
|
|
||||||
width: width,
|
width: width,
|
||||||
highlighted: false)
|
highlighted: false)
|
||||||
menu.insertItem(headerItem, at: cursor)
|
menu.insertItem(headerItem, at: cursor)
|
||||||
cursor += 1
|
cursor += 1
|
||||||
|
|
||||||
|
if let errorText = errorText?.nonEmpty, !rows.isEmpty {
|
||||||
|
menu.insertItem(
|
||||||
|
self.makeMessageItem(
|
||||||
|
text: errorText,
|
||||||
|
symbolName: "exclamationmark.triangle",
|
||||||
|
width: width,
|
||||||
|
maxLines: 2),
|
||||||
|
at: cursor)
|
||||||
|
cursor += 1
|
||||||
|
}
|
||||||
|
|
||||||
if rows.isEmpty {
|
if rows.isEmpty {
|
||||||
menu.insertItem(
|
menu.insertItem(
|
||||||
self.makeMessageItem(text: errorText ?? "No usage available", symbolName: "minus", width: width),
|
self.makeMessageItem(text: errorText ?? "No usage available", symbolName: "minus", width: width),
|
||||||
@@ -444,13 +454,14 @@ final class MenuSessionsInjector: NSObject, NSMenuDelegate {
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
private func makeMessageItem(text: String, symbolName: String, width: CGFloat) -> NSMenuItem {
|
private func makeMessageItem(text: String, symbolName: String, width: CGFloat, maxLines: Int? = nil) -> NSMenuItem {
|
||||||
let view = AnyView(
|
let view = AnyView(
|
||||||
Label(text, systemImage: symbolName)
|
Label(text, systemImage: symbolName)
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
.lineLimit(nil)
|
.lineLimit(maxLines)
|
||||||
|
.truncationMode(.tail)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
.padding(.leading, 18)
|
.padding(.leading, 18)
|
||||||
.padding(.trailing, 12)
|
.padding(.trailing, 12)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct MenuUsageHeaderView: View {
|
struct MenuUsageHeaderView: View {
|
||||||
let count: Int
|
let count: Int
|
||||||
let statusText: String?
|
|
||||||
|
|
||||||
private let paddingTop: CGFloat = 8
|
private let paddingTop: CGFloat = 8
|
||||||
private let paddingBottom: CGFloat = 6
|
private let paddingBottom: CGFloat = 6
|
||||||
@@ -20,14 +19,6 @@ struct MenuUsageHeaderView: View {
|
|||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let statusText, !statusText.isEmpty {
|
|
||||||
Text(statusText)
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
.lineLimit(1)
|
|
||||||
.truncationMode(.tail)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding(.top, self.paddingTop)
|
.padding(.top, self.paddingTop)
|
||||||
.padding(.bottom, self.paddingBottom)
|
.padding(.bottom, self.paddingBottom)
|
||||||
|
|||||||
Reference in New Issue
Block a user