Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Oct 10, 2024
1 parent d679320 commit ba74c54
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 267 deletions.
1 change: 1 addition & 0 deletions Sources/Pulse/LoggerStore/LoggerStore+Entities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class LoggerMessageEntity: NSManagedObject {
public final class NetworkTaskEntity: NSManagedObject {
// Primary
@NSManaged public var createdAt: Date
@NSManaged public var isPinned: Bool
@NSManaged public var session: UUID
@NSManaged public var taskId: UUID

Expand Down
1 change: 1 addition & 0 deletions Sources/Pulse/LoggerStore/LoggerStore+Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extension LoggerStore {

task.properties = [
Attribute("createdAt", .dateAttributeType),
Attribute("isPinned", .booleanAttributeType),
Attribute("session", .UUIDAttributeType),
Attribute("taskId", .UUIDAttributeType),
Attribute("taskType", .integer16AttributeType),
Expand Down
14 changes: 13 additions & 1 deletion Sources/Pulse/LoggerStore/LoggerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,12 @@ extension LoggerStore {
}
}

package func clearSessions(withIDs sessionIDs: Set<UUID>) {
perform { _ in
try? self._removeMessagesForSessions(withIDs: sessionIDs, isInverted: false)
}
}

private func _removeSessions(withIDs sessionIDs: Set<UUID>, isInverted: Bool = false) throws {
try deleteEntities(for: {
let request = LoggerSessionEntity.fetchRequest()
Expand All @@ -816,6 +822,10 @@ extension LoggerStore {
return request
}())

try _removeMessagesForSessions(withIDs: sessionIDs, isInverted: isInverted)
}

private func _removeMessagesForSessions(withIDs sessionIDs: Set<UUID>, isInverted: Bool) throws {
var predicate = NSPredicate(format: "session IN %@", sessionIDs)
predicate = isInverted ? NSCompoundPredicate(notPredicateWithSubpredicate: predicate) : predicate
try removeMessages(with: predicate)
Expand All @@ -825,7 +835,9 @@ extension LoggerStore {

/// Removes all of the previously recorded messages.
public func removeAll() {
perform { _ in self._removeAll() }
perform { _ in
self._removeAll()
}
}

private func _removeAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ struct StatusIndicatorView: View {
}
}
}

struct BookmarkIconView: View {
var body: some View {
Image(systemName: "bookmark.fill")
.font(.footnote)
.foregroundColor(.pink)
.frame(width: 8, height: 8)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ package struct ConsoleMessageCell: View {
.foregroundColor(titleColor)
Spacer()
#if !os(watchOS)
#if canImport(RiftSupport)
PinView(message: message)
#endif
if message.isPinned {
BookmarkIconView()
}
ConsoleTimestampView(date: message.createdAt)
.padding(.trailing, 3)
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/PulseUI/Features/Console/Views/ConsoleTaskCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ package struct ConsoleTaskCell: View {
info.higlighted(highlightedArea == .header)

Spacer()
#if canImport(RiftSupport)
PinView(task: task)
#endif
if task.isPinned {
BookmarkIconView()
}
ConsoleTimestampView(date: task.createdAt)
.padding(.trailing, 3)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import SwiftUI
import Pulse
import Combine

#if !os(macOS)

@available(iOS 16, visionOS 1, *)
struct ConsoleDomainsSelectionView: View {
@ObservedObject var viewModel: ConsoleFiltersViewModel
Expand All @@ -23,8 +25,8 @@ struct ConsoleDomainsSelectionView: View {
}
}

private extension ConsoleFiltersViewModel {
func bindingForHosts(index: LoggerStoreIndex) -> Binding<Set<String>> {
extension ConsoleFiltersViewModel {
package func bindingForHosts(index: LoggerStoreIndex) -> Binding<Set<String>> {
Binding(get: {
if let focused = self.criteria.network.host.focused {
return [focused]
Expand All @@ -43,3 +45,5 @@ private extension ConsoleFiltersViewModel {
})
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import SwiftUI
import Pulse
import Combine

#if !os(macOS)

@available(iOS 16, visionOS 1, *)
struct ConsoleLabelsSelectionView: View {
@ObservedObject var viewModel: ConsoleFiltersViewModel
Expand All @@ -23,8 +25,10 @@ struct ConsoleLabelsSelectionView: View {
}
}

private extension ConsoleFiltersViewModel {
func bindingForSelectedLabels(index: LoggerStoreIndex) -> Binding<Set<String>> {
#endif

extension ConsoleFiltersViewModel {
package func bindingForSelectedLabels(index: LoggerStoreIndex) -> Binding<Set<String>> {
Binding(get: {
if let focused = self.criteria.messages.labels.focused {
return [focused]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).

#if !os(macOS)

import SwiftUI
import Pulse

Expand All @@ -14,7 +16,7 @@ package struct ConsoleSearchListSelectionView<Data: RandomAccessCollection, ID:
package let description: (Data.Element) -> String
@ViewBuilder package let label: (Data.Element) -> Label

#if os(iOS) || os(macOS) || os(visionOS)
#if os(iOS) || os(visionOS)
package var limit = 6
#else
package var limit = 3
Expand Down Expand Up @@ -42,34 +44,6 @@ package struct ConsoleSearchListSelectionView<Data: RandomAccessCollection, ID:

@State private var searchText = ""

#if os(macOS)
@State private var isExpanded = false

package var body: some View {
if items.isEmpty {
emptyView
} else {
let filtered = self.filteredItems
HStack {
SearchBar(title: "Search", text: $searchText)
Spacer()
buttonToggleAll
}
ForEach(isExpanded ? filtered : Array(filtered.prefix(limit)), id: id, content: makeRow)
if filtered.count > limit {
HStack {
if !isExpanded {
Button(action: { isExpanded = true }) {
Text("Show All ") + Text("(\(items.count))").foregroundColor(.secondary)
}
} else {
Button("Show Less") { isExpanded = false }
}
}
}
}
}
#else
@State private var isExpandedListPresented = false
@State private var isSearching = false

Expand Down Expand Up @@ -116,7 +90,6 @@ package struct ConsoleSearchListSelectionView<Data: RandomAccessCollection, ID:
.disableAutocorrection(true)
#endif
}
#endif

// MARK: - Shared

Expand All @@ -136,10 +109,6 @@ package struct ConsoleSearchListSelectionView<Data: RandomAccessCollection, ID:
selection.remove(item[keyPath: id])
}
}), label: { label(item).lineLimit(1) })
#if os(macOS)
.help(description(item))
.frame(maxWidth: .infinity, alignment: .leading)
#endif
}

private var filteredItems: [Data.Element] {
Expand Down Expand Up @@ -182,3 +151,5 @@ private struct ConsoleSearchListSelectionViewDemo: View {
}
}
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ package struct ConsoleSessionsPickerView: View {

#if os(iOS) || os(visionOS) || os(macOS)
package static var makeSessionPicker: (_ selection: Binding<Set<UUID>>) -> AnyView = {
#if os(macOS)
AnyView(EmptyView()) // Has to be injected
#else
AnyView(SessionPickerView(selection: $0))
#endif
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import Pulse
import CoreData
import Combine

#if os(macOS)
import AppKit
#endif

@available(iOS 16, visionOS 1, *)
package final class ConsoleSearchOccurrence: Identifiable, Equatable, Hashable {
package let id = ConsoleSearchOccurrenceId()
Expand Down Expand Up @@ -40,9 +44,33 @@ private let previewAttibutes = TextHelper().attributes(role: .body2, style: .mon

@available(iOS 16, visionOS 1, *)
extension ConsoleSearchOccurrence {
static func makePreview(for match: ConsoleSearchMatch, attributes customAttributes: [NSAttributedString.Key: Any] = [:]) -> AttributedString {
package static func makePreview(for match: ConsoleSearchMatch, attributes customAttributes: [NSAttributedString.Key: Any] = [:]) -> AttributedString {
let segments = makePreviewSegments(for: match)

var attributes = AttributeContainer(customAttributes)
#if os(macOS)
attributes.foregroundColor = .secondary
attributes.font = .callout
#endif

let prefixStartIndex = match.line.index(match.range.lowerBound, offsetBy: -50, limitedBy: match.line.startIndex) ?? match.line.startIndex
var middle = AttributedString(segments[1], attributes: attributes)
#if os(macOS)
middle.foregroundColor = .primary
middle.font = Font.callout.weight(.semibold)
#else
middle.foregroundColor = .orange
#endif
return AttributedString(segments[0], attributes: attributes) + middle + AttributedString(segments[2], attributes: attributes)
}

package static func makePreviewSegments(for match: ConsoleSearchMatch) -> [Substring] {
let prefixOffset: Int
#if os(macOS)
prefixOffset = -20
#else
prefixOffset = -50
#endif
let prefixStartIndex = match.line.index(match.range.lowerBound, offsetBy: prefixOffset, limitedBy: match.line.startIndex) ?? match.line.startIndex
let prefixRange = prefixStartIndex..<match.range.lowerBound

let suffixUpperBound = match.line.index(match.range.upperBound, offsetBy: 200, limitedBy: match.line.endIndex) ?? match.line.endIndex
Expand All @@ -62,11 +90,7 @@ extension ConsoleSearchOccurrence {
if isEllipsisNeeded {
prefix.insert("", at: prefix.startIndex)
}

let attributes = AttributeContainer(customAttributes)
var middle = AttributedString(match.line[match.range], attributes: attributes)
middle.foregroundColor = .orange
return AttributedString(prefix, attributes: attributes) + middle + AttributedString(suffix, attributes: attributes)
return [prefix, match.line[match.range], suffix]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ final class ConsoleSearchOperation {
var lineCount = 0
content.enumerateLines { line, stop in
lineCount += 1
for range in line.ranges(of: term.text, options: term.options) {
for range in line.ranges(of: term.text, options: term.options, limit: ConsoleSearchMatch.limit) {
let match = ConsoleSearchMatch(line: line, lineNumber: lineCount, range: range, term: term)
matches.append(match)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ package struct ConsoleSearchMatch {
package let range: Range<String.Index>
package let term: ConsoleSearchTerm

package static let limit = 1000
package static let limit = 6

package init(line: String, lineNumber: Int, range: Range<String.Index>, term: ConsoleSearchTerm) {
self.line = line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ struct ConsoleSearchResultDetailsView: View {
}
}

#endif

#if os(iOS) || os(visionOS) || os(macOS)

@available(iOS 16, visionOS 1, *)
package struct PlainListGroupSeparator: View {
package init() {}
Expand All @@ -127,10 +131,6 @@ package struct PlainListGroupSeparator: View {
}
}

#endif

#if os(iOS) || os(visionOS) || os(macOS)

@available(iOS 16, macOS 13, visionOS 1, *)
package struct PlainListSectionHeader<Content: View>: View {
package var title: String?
Expand Down Expand Up @@ -171,39 +171,4 @@ extension PlainListSectionHeader where Content == Text {
}
}

@available(iOS 16, visionOS 1, *)
package struct PlainListSeeAllView: View {
let count: Int

package init(count: Int) {
self.count = count
}

package var body: some View {
(Text("Show All").foregroundColor(.accentColor) +
Text(" (\(count))"))
.font(.subheadline)
.foregroundColor(.secondary)
.frame(maxWidth: .infinity, alignment: .leading)
}
}

@available(iOS 16, visionOS 1, *)
package struct PlainListSectionHeaderSeparator: View {
let title: String

package init(title: String) {
self.title = title
}

package var body: some View {
HStack(alignment: .bottom, spacing: 0) {
Text(title)
.foregroundColor(.secondary)
.font(.subheadline.weight(.medium))
Spacer()
}
}
}

#endif
Loading

0 comments on commit ba74c54

Please sign in to comment.