mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Merge branch 'task/single-line-activity-log'
This commit is contained in:
commit
60ec04ff69
11 files changed
+46
-65
No files matched your search
@@ -60,7 +60,7 @@ struct AccountStatsData {
|
||||
NotificationCenter.default.post(name: .AccountStatsDidChange, object: self)
|
||||
|
||||
Task {
|
||||
await AccountManager.shared.vacuumAllDatabases()
|
||||
await appDelegate.vacuumAllDatabases()
|
||||
isVacuuming = false
|
||||
refresh()
|
||||
}
|
||||
@@ -118,17 +118,13 @@ private extension AccountStatsViewModel {
|
||||
func databaseSize(for account: Account) -> Int {
|
||||
let dataFolder = account.dataFolder as NSString
|
||||
let baseNames = ["DB.sqlite3", "FeedSettings.db", "Sync.sqlite3"]
|
||||
// WAL databases create multiple files.
|
||||
let suffixes = ["", "-wal", "-shm", "-journal"]
|
||||
var totalSize = 0
|
||||
|
||||
for baseName in baseNames {
|
||||
for suffix in suffixes {
|
||||
let path = dataFolder.appendingPathComponent(baseName + suffix)
|
||||
if let attributes = try? FileManager.default.attributesOfItem(atPath: path),
|
||||
let size = attributes[FileAttributeKey.size] as? Int {
|
||||
totalSize += size
|
||||
}
|
||||
let path = dataFolder.appendingPathComponent(baseName)
|
||||
if let attributes = try? FileManager.default.attributesOfItem(atPath: path),
|
||||
let size = attributes[FileAttributeKey.size] as? Int {
|
||||
totalSize += size
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,11 @@ import ActivityLog
|
||||
private var copyButton: NSButton?
|
||||
private var hasBeenShown = false
|
||||
|
||||
/// Activity IDs for which we've logged the start entry.
|
||||
private var loggedStartIDs = Set<Int>()
|
||||
/// Activity IDs for which we've logged the completion entry.
|
||||
private var loggedCompletionIDs = Set<Int>()
|
||||
/// Number of text entries appended to the text view.
|
||||
private var textEntryCount = 0
|
||||
/// Maximum text entries before rebuilding (2 per activity: start + completion).
|
||||
/// Maximum text entries before rebuilding.
|
||||
private static let maxTextEntries = 1000
|
||||
|
||||
private var needsRebuild = false
|
||||
@@ -221,7 +219,6 @@ private extension ActivityLogWindowController {
|
||||
}
|
||||
|
||||
func reloadEntries() {
|
||||
loggedStartIDs.removeAll()
|
||||
loggedCompletionIDs.removeAll()
|
||||
textEntryCount = 0
|
||||
|
||||
@@ -230,11 +227,6 @@ private extension ActivityLogWindowController {
|
||||
|
||||
let combined = NSMutableAttributedString()
|
||||
for activity in allActivities {
|
||||
if activity.state == .running || activity.state == .completed || activity.state == .failed {
|
||||
combined.append(startAttributedString(for: activity))
|
||||
loggedStartIDs.insert(activity.id)
|
||||
textEntryCount += 1
|
||||
}
|
||||
if activity.state == .completed || activity.state == .failed {
|
||||
combined.append(completionAttributedString(for: activity))
|
||||
loggedCompletionIDs.insert(activity.id)
|
||||
@@ -259,14 +251,6 @@ private extension ActivityLogWindowController {
|
||||
var didAppend = false
|
||||
|
||||
for activity in allActivities {
|
||||
let isStarted = activity.state == .running || activity.state == .completed || activity.state == .failed
|
||||
if isStarted && !loggedStartIDs.contains(activity.id) {
|
||||
textView.textStorage?.append(startAttributedString(for: activity))
|
||||
loggedStartIDs.insert(activity.id)
|
||||
textEntryCount += 1
|
||||
didAppend = true
|
||||
}
|
||||
|
||||
let isFinished = activity.state == .completed || activity.state == .failed
|
||||
if isFinished && !loggedCompletionIDs.contains(activity.id) {
|
||||
textView.textStorage?.append(completionAttributedString(for: activity))
|
||||
@@ -300,26 +284,6 @@ private extension ActivityLogWindowController {
|
||||
|
||||
// MARK: - Attributed Strings
|
||||
|
||||
func startAttributedString(for activity: Activity) -> NSAttributedString {
|
||||
let result = NSMutableAttributedString()
|
||||
|
||||
let date = activity.startDate ?? Date()
|
||||
appendTimestamp(date, to: result)
|
||||
|
||||
let startAttributes: [NSAttributedString.Key: Any] = [
|
||||
.foregroundColor: NSColor.systemBlue,
|
||||
.font: NSFont.monospacedSystemFont(ofSize: Self.fontSize, weight: .medium),
|
||||
.paragraphStyle: Self.entryParagraphStyle
|
||||
]
|
||||
result.append(NSAttributedString(string: "▶ ", attributes: startAttributes))
|
||||
|
||||
appendSource(for: activity, to: result)
|
||||
appendKindAndDetail(for: activity, to: result)
|
||||
appendNewline(to: result)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func completionAttributedString(for activity: Activity) -> NSAttributedString {
|
||||
let result = NSMutableAttributedString()
|
||||
|
||||
|
||||
+13
-7
@@ -827,13 +827,19 @@ extension AppDelegate {
|
||||
|
||||
@IBAction func vacuumDatabases(_ sender: Any?) {
|
||||
Task {
|
||||
await AccountManager.shared.vacuumAllDatabases()
|
||||
await vacuumAndLog(databasePath: HTMLMetadataDatabase.shared.databasePath) {
|
||||
await HTMLMetadataDatabase.shared.vacuum()
|
||||
}
|
||||
await vacuumAndLog(databasePath: ImageMetadataDatabase.shared.databasePath) {
|
||||
await ImageMetadataDatabase.shared.vacuum()
|
||||
}
|
||||
await vacuumAllDatabases()
|
||||
}
|
||||
}
|
||||
|
||||
/// Vacuum every database the app owns — per-account databases plus the
|
||||
/// app-level HTMLMetadata and ImageMetadata databases.
|
||||
func vacuumAllDatabases() async {
|
||||
await AccountManager.shared.vacuumAllDatabases()
|
||||
await vacuumAndLog(databasePath: HTMLMetadataDatabase.shared.databasePath) {
|
||||
await HTMLMetadataDatabase.shared.vacuum()
|
||||
}
|
||||
await vacuumAndLog(databasePath: ImageMetadataDatabase.shared.databasePath) {
|
||||
await ImageMetadataDatabase.shared.vacuum()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ final class FeedSettingsDatabase: Sendable {
|
||||
self.serialDispatchQueue = DispatchQueue(label: "FeedSettingsDatabase")
|
||||
self.database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
serialDispatchQueue.sync { [database] in
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
}
|
||||
vacuumIfNeeded()
|
||||
|
||||
@@ -23,7 +23,6 @@ public actor ErrorLogDatabase {
|
||||
public init(databasePath: String) {
|
||||
self.databasePath = databasePath
|
||||
let database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
ErrorLogTable.pruneEntries(limit: Self.pruneLimit, database: database)
|
||||
database.vacuumIfNeeded()
|
||||
|
||||
@@ -55,7 +55,6 @@ public final actor HTMLMetadataDatabase {
|
||||
private init(databasePath: String) {
|
||||
self.databasePath = databasePath
|
||||
let database = FMDatabase.openAndSetUpDatabase(path: databasePath)
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
database.runCreateStatements(Self.tableCreationStatements)
|
||||
self.database = database
|
||||
|
||||
|
||||
@@ -41,12 +41,6 @@ import RSDatabaseObjC
|
||||
.appendingPathComponent("ImageMetadata.db").path
|
||||
self.databasePath = databasePath
|
||||
let queue = DatabaseQueue(databasePath: databasePath)
|
||||
queue.runInDatabaseSync { result in
|
||||
guard let database = try? result.get() else {
|
||||
return
|
||||
}
|
||||
database.executeStatements("PRAGMA journal_mode = WAL;")
|
||||
}
|
||||
try? queue.runCreateStatements(Self.tableCreationStatements)
|
||||
self.queue = queue
|
||||
|
||||
|
||||
@@ -202,6 +202,9 @@ private extension DatabaseQueue {
|
||||
|
||||
func openDatabase(_ database: FMDatabase) {
|
||||
database.open()
|
||||
// All databases are single-connection and serialized — WAL gains us nothing
|
||||
// and produces extra -wal/-shm files that bloat on disk.
|
||||
database.executeStatements("PRAGMA journal_mode = DELETE;")
|
||||
database.executeStatements("PRAGMA synchronous = 1;")
|
||||
database.setShouldCacheStatements(true)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ public extension FMDatabase {
|
||||
let database = FMDatabase(path: path)!
|
||||
|
||||
database.open()
|
||||
// All databases are single-connection and serialized — WAL gains us nothing
|
||||
// and produces extra -wal/-shm files that bloat on disk.
|
||||
database.executeStatements("PRAGMA journal_mode = DELETE;")
|
||||
database.executeStatements("PRAGMA synchronous = 1;")
|
||||
database.setShouldCacheStatements(true)
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ nonisolated public struct SpecialCase {
|
||||
return false
|
||||
}
|
||||
|
||||
/// Returns true if the URL’s host matches one of the supplied domain names.
|
||||
/// Returns true if the URL’s host belongs to one of the supplied domains.
|
||||
///
|
||||
/// Unlike `urlStringContainSpecialCase`, this checks only the host component — not the path or query.
|
||||
/// A leading `www.` on the URL’s host is treated as optional, so `example.com` in `domains` matches a host of either `example.com` or `www.example.com`.
|
||||
/// Subdomains also match: `micro.blog` in `domains` matches a host of `gruber.micro.blog`.
|
||||
/// The supplied `domains` are assumed to already be lowercased and to have any leading `www.` stripped.
|
||||
public static func urlStringMatchesDomain(_ urlString: String, _ domains: [String]) -> Bool {
|
||||
guard let url = URL(string: urlString), let host = url.host()?.lowercased(with: localeForLowercasing) else {
|
||||
@@ -36,7 +37,10 @@ nonisolated public struct SpecialCase {
|
||||
}
|
||||
let normalizedHost = stringByStrippingWWWPrefix(host)
|
||||
for domain in domains {
|
||||
if normalizedHost == domain {
|
||||
if domain.isEmpty {
|
||||
continue
|
||||
}
|
||||
if normalizedHost == domain || normalizedHost.hasSuffix("." + domain) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ extension AccountType {
|
||||
var logColor: NSColor {
|
||||
switch self {
|
||||
case .onMyMac:
|
||||
return .labelColor
|
||||
return .onMyMacLogColor
|
||||
case .cloudKit:
|
||||
return .systemPurple
|
||||
case .feedly:
|
||||
@@ -104,3 +104,17 @@ extension AccountType {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
extension NSColor {
|
||||
|
||||
private static let onMyMacLogLightColor = NSColor(red: 0x4A / 255.0, green: 0x55 / 255.0, blue: 0x60 / 255.0, alpha: 1.0)
|
||||
private static let onMyMacLogDarkColor = NSColor(red: 0xB0 / 255.0, green: 0xBA / 255.0, blue: 0xC4 / 255.0, alpha: 1.0)
|
||||
|
||||
/// Activity Log color for the On My Mac account. Slate gray — darker on light backgrounds, lighter on dark.
|
||||
static let onMyMacLogColor = NSColor(name: "onMyMacLogColor") { appearance in
|
||||
let isDark = appearance.bestMatch(from: [.darkAqua, .vibrantDark, .accessibilityHighContrastDarkAqua, .accessibilityHighContrastVibrantDark]) != nil
|
||||
return isDark ? onMyMacLogDarkColor : onMyMacLogLightColor
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user