Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Extract log viewer into package
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 6, 2024
1 parent bd7de96 commit 8ef6368
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 158 deletions.
58 changes: 30 additions & 28 deletions Aware.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
0347D59D2BAF9A3F00C5741E /* SuspendingClock+Drift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0347D59C2BAF9A3F00C5741E /* SuspendingClock+Drift.swift */; };
0347D59F2BAFB97300C5741E /* BackgroundTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0347D59E2BAFB97300C5741E /* BackgroundTask.swift */; };
034EC4B32BBF2780003FD1C9 /* LogWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034EC4B22BBF2780003FD1C9 /* LogWindow.swift */; platformFilters = (xros, ); };
0355BF462BC062D8002C06AD /* LogExport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355BF452BC062D8002C06AD /* LogExport.swift */; };
0355BF482BC0634D002C06AD /* LogRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355BF472BC0634D002C06AD /* LogRowView.swift */; };
0355BF4A2BC063A3002C06AD /* LogListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355BF492BC063A3002C06AD /* LogListView.swift */; };
0355BF4C2BC07D70002C06AD /* GroupedSortedCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355BF4B2BC07D70002C06AD /* GroupedSortedCollectionTests.swift */; };
0355BF4E2BC0989A002C06AD /* GroupedSortedCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0355BF4D2BC0989A002C06AD /* GroupedSortedCollection.swift */; };
036569CE2B9A40C8003D3DCA /* MenuBarTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036569CD2B9A40C8003D3DCA /* MenuBarTimelineView.swift */; platformFilters = (macos, ); };
036DA9B52B7AF52E0066B4B2 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036DA9B42B7AF52E0066B4B2 /* App.swift */; };
036EBD1B1C1408C200121D0B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 036EBD1A1C1408C200121D0B /* Assets.xcassets */; };
Expand All @@ -36,6 +31,7 @@
038858802BA54DBA003E287D /* Duration+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0388587F2BA54DBA003E287D /* Duration+Extensions.swift */; };
039011B12BC1C545000C65D6 /* Task+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 039011B02BC1C545000C65D6 /* Task+Timeout.swift */; };
039011B32BC1C6A8000C65D6 /* WindowAction+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = 039011B22BC1C6A8000C65D6 /* WindowAction+Async.swift */; };
039011D72BC1E73D000C65D6 /* Console in Frameworks */ = {isa = PBXBuildFile; productRef = 039011D62BC1E73D000C65D6 /* Console */; };
0394D1752B845FB400FE7020 /* TimerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0394D1742B845FB400FE7020 /* TimerView.swift */; platformFilters = (xros, ); };
0394D1772B84630E00FE7020 /* TimerTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0394D1762B84630E00FE7020 /* TimerTextView.swift */; platformFilters = (xros, ); };
03DA21642B84160800367F4C /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DA21632B84160800367F4C /* SettingsView.swift */; platformFilters = (xros, ); };
Expand Down Expand Up @@ -70,11 +66,6 @@
0347D59C2BAF9A3F00C5741E /* SuspendingClock+Drift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SuspendingClock+Drift.swift"; sourceTree = "<group>"; };
0347D59E2BAFB97300C5741E /* BackgroundTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundTask.swift; sourceTree = "<group>"; };
034EC4B22BBF2780003FD1C9 /* LogWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogWindow.swift; sourceTree = "<group>"; };
0355BF452BC062D8002C06AD /* LogExport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogExport.swift; sourceTree = "<group>"; };
0355BF472BC0634D002C06AD /* LogRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogRowView.swift; sourceTree = "<group>"; };
0355BF492BC063A3002C06AD /* LogListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogListView.swift; sourceTree = "<group>"; };
0355BF4B2BC07D70002C06AD /* GroupedSortedCollectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupedSortedCollectionTests.swift; sourceTree = "<group>"; };
0355BF4D2BC0989A002C06AD /* GroupedSortedCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupedSortedCollection.swift; sourceTree = "<group>"; };
036569CD2B9A40C8003D3DCA /* MenuBarTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarTimelineView.swift; sourceTree = "<group>"; };
036DA9B42B7AF52E0066B4B2 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
036EBD151C1408C200121D0B /* Aware.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aware.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -88,6 +79,7 @@
038D0B381C4DDD5600040C44 /* Aware.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Aware.entitlements; sourceTree = "<group>"; };
039011B02BC1C545000C65D6 /* Task+Timeout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Task+Timeout.swift"; sourceTree = "<group>"; };
039011B22BC1C6A8000C65D6 /* WindowAction+Async.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WindowAction+Async.swift"; sourceTree = "<group>"; };
039011D42BC1E678000C65D6 /* Console */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Console; sourceTree = "<group>"; };
0394D1742B845FB400FE7020 /* TimerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerView.swift; sourceTree = "<group>"; };
0394D1762B84630E00FE7020 /* TimerTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerTextView.swift; sourceTree = "<group>"; };
03DA21632B84160800367F4C /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
Expand All @@ -103,6 +95,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
039011D72BC1E73D000C65D6 /* Console in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -123,7 +116,6 @@
0347D59E2BAFB97300C5741E /* BackgroundTask.swift */,
0388587F2BA54DBA003E287D /* Duration+Extensions.swift */,
03F9E2301C24CCA8001DBE86 /* FormatStyle+Extensions.swift */,
0355BF4D2BC0989A002C06AD /* GroupedSortedCollection.swift */,
0347D5982BAF8B5400C5741E /* NotificationCenter+AsyncSequence.swift */,
03830C982BA6079D00532C40 /* NotificationCenter+Observer.swift */,
03E00DD32BB0A82100A6C522 /* NotificationName+Nonisolated.swift */,
Expand All @@ -132,27 +124,18 @@
0341CB742B9CDEAC00CC0C96 /* TimerState.swift */,
0341CB702B9C3FCE00CC0C96 /* UTCClock.swift */,
039011B22BC1C6A8000C65D6 /* WindowAction+Async.swift */,
0355BF442BC06282002C06AD /* LogView */,
);
path = Shared;
sourceTree = "<group>";
};
0355BF442BC06282002C06AD /* LogView */ = {
isa = PBXGroup;
children = (
0355BF452BC062D8002C06AD /* LogExport.swift */,
0355BF472BC0634D002C06AD /* LogRowView.swift */,
0355BF492BC063A3002C06AD /* LogListView.swift */,
);
path = LogView;
sourceTree = "<group>";
};
036EBD0C1C1408C200121D0B = {
isa = PBXGroup;
children = (
036EBD171C1408C200121D0B /* Aware */,
03F9E2271C24CAD3001DBE86 /* AwareTests */,
039011D32BC1E638000C65D6 /* Packages */,
036EBD161C1408C200121D0B /* Products */,
039011D52BC1E73D000C65D6 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -205,12 +188,26 @@
path = visionOS;
sourceTree = "<group>";
};
039011D32BC1E638000C65D6 /* Packages */ = {
isa = PBXGroup;
children = (
039011D42BC1E678000C65D6 /* Console */,
);
path = Packages;
sourceTree = SOURCE_ROOT;
};
039011D52BC1E73D000C65D6 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
03F9E2271C24CAD3001DBE86 /* AwareTests */ = {
isa = PBXGroup;
children = (
03162DE22BB130880004BFDE /* AsyncStreamTests.swift */,
03F9E2321C24CD2E001DBE86 /* FormatStylesTests.swift */,
0355BF4B2BC07D70002C06AD /* GroupedSortedCollectionTests.swift */,
0347D59A2BAF8CB200C5741E /* NotificationCenterTests.swift */,
0341CB762B9CDEC400CC0C96 /* TimerStateTests.swift */,
0341CB722B9C456400CC0C96 /* UTCClockTests.swift */,
Expand All @@ -234,6 +231,9 @@
dependencies = (
);
name = Aware;
packageProductDependencies = (
039011D62BC1E73D000C65D6 /* Console */,
);
productName = Aware;
productReference = 036EBD151C1408C200121D0B /* Aware.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -334,7 +334,6 @@
0347D59F2BAFB97300C5741E /* BackgroundTask.swift in Sources */,
038858802BA54DBA003E287D /* Duration+Extensions.swift in Sources */,
03F9E2311C24CCA8001DBE86 /* FormatStyle+Extensions.swift in Sources */,
0355BF4E2BC0989A002C06AD /* GroupedSortedCollection.swift in Sources */,
0347D5992BAF8B5400C5741E /* NotificationCenter+AsyncSequence.swift in Sources */,
03830C992BA6079D00532C40 /* NotificationCenter+Observer.swift in Sources */,
03E00DD42BB0A82100A6C522 /* NotificationName+Nonisolated.swift in Sources */,
Expand All @@ -343,9 +342,6 @@
0341CB752B9CDEAC00CC0C96 /* TimerState.swift in Sources */,
0341CB712B9C3FCE00CC0C96 /* UTCClock.swift in Sources */,
039011B32BC1C6A8000C65D6 /* WindowAction+Async.swift in Sources */,
0355BF462BC062D8002C06AD /* LogExport.swift in Sources */,
0355BF482BC0634D002C06AD /* LogRowView.swift in Sources */,
0355BF4A2BC063A3002C06AD /* LogListView.swift in Sources */,
037195362B804E4C00B807ED /* ActivityMonitor.swift in Sources */,
037C76B52BC09F1A0026CE65 /* LogWindow.swift in Sources */,
0381B4992B808A5A002213F6 /* MenuBar.swift in Sources */,
Expand All @@ -366,7 +362,6 @@
files = (
03162DE32BB130880004BFDE /* AsyncStreamTests.swift in Sources */,
03F9E2331C24CD2E001DBE86 /* FormatStylesTests.swift in Sources */,
0355BF4C2BC07D70002C06AD /* GroupedSortedCollectionTests.swift in Sources */,
0347D59B2BAF8CB200C5741E /* NotificationCenterTests.swift in Sources */,
0341CB772B9CDEC400CC0C96 /* TimerStateTests.swift in Sources */,
0341CB732B9C456400CC0C96 /* UTCClockTests.swift in Sources */,
Expand Down Expand Up @@ -652,6 +647,13 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
039011D62BC1E73D000C65D6 /* Console */ = {
isa = XCSwiftPackageProductDependency;
productName = Console;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 036EBD0D1C1408C200121D0B /* Project object */;
}
9 changes: 7 additions & 2 deletions Aware/macOS/LogWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#if os(macOS)

import Console
import OSLog
import SwiftUI

Expand All @@ -23,14 +24,18 @@ struct LogWindow: Scene {
LogListView(logExport.logs)
.task {
do {
self.logExport = try await LogExport.load(since: sceneCreatedDate)
self.logExport = try await LogExport.load(
since: sceneCreatedDate, subsystem: "com.awaremac.Aware"
)
} catch {
logger.error("Failed to load logs: \(error, privacy: .public)")
}
}
.refreshable {
do {
self.logExport = try await LogExport.load(since: sceneCreatedDate)
self.logExport = try await LogExport.load(
since: sceneCreatedDate, subsystem: "com.awaremac.Aware"
)
} catch {
logger.error("Failed to load logs: \(error, privacy: .public)")
}
Expand Down
1 change: 1 addition & 0 deletions Aware/visionOS/LogWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#if os(visionOS)

import Console
import OSLog
import SwiftUI

Expand Down
31 changes: 0 additions & 31 deletions AwareTests/GroupedSortedCollectionTests.swift

This file was deleted.

8 changes: 8 additions & 0 deletions Packages/Console/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
21 changes: 21 additions & 0 deletions Packages/Console/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version: 5.10

import PackageDescription

let package = Package(
name: "Console",
platforms: [
.macOS(.v13),
.visionOS(.v1),
],
products: [
.library(
name: "Console",
targets: ["Console"]
),
],
targets: [
.target(
name: "Console"),
]
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// GroupedSortedCollection.swift
// Aware
// Console
//
// Created by Joshua Peek on 4/5/24.
//

// TODO: Make this less generic
struct GroupedSortedCollection<Base, Key> where Key: Equatable, Base: Collection {
static func scan(_ elements: Base, keyForElement: (Base.Element) -> Key) -> Self {
guard let firstElement = elements.first else {
Expand Down Expand Up @@ -45,12 +46,6 @@ struct GroupedSortedCollection<Base, Key> where Key: Equatable, Base: Collection
private let baseIndicies: [Base.Index]
}

extension GroupedSortedCollection where Key == Base.Element {
static func scan(_ elements: Base) -> Self {
scan(elements) { el in el }
}
}

extension GroupedSortedCollection: BidirectionalCollection {
var startIndex: Int { keys.startIndex }
var endIndex: Int { keys.endIndex }
Expand Down
Loading

0 comments on commit 8ef6368

Please sign in to comment.