UI redesign Phase 1: NavigationSplitView with collapsible sidebar
- Replace root VStack with NavigationSplitView (2-column, collapsible sidebar) - Add SidebarView: new chat button, conversation search, list with swipe actions - Slim HeaderView to text-only (provider + model + star); remove all icon rows - Move status pills (Online, MCP, Synced) to footer right side - Remove version number and shortcut hints from footer - Add resizable InputBar with drag handle (persisted height) and globe/network.slash online toggle - Fix Norwegian menu appearing on English systems (CFBundleLocalizations in Info.plist) - Add View menu (Model Info, History, Stats, Credits, Online Mode toggle ⌘⇧O) - Add ⌘L as alias for Search Conversations (muscle memory for /load users) - Add Check for Updates to Help menu with download URL from Gitea API - Add one-time Intel/Rosetta deprecation warning on first launch - Swift 6: fix self.Self.isoString() call sites in DatabaseService Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -134,15 +134,29 @@ final class DatabaseService: Sendable {
|
||||
nonisolated static let shared = DatabaseService()
|
||||
|
||||
private let dbQueue: DatabaseQueue
|
||||
private let isoFormatter: ISO8601DateFormatter
|
||||
|
||||
// Command history limit - keep most recent 5000 entries
|
||||
private static let maxHistoryEntries = 5000
|
||||
private nonisolated static let maxHistoryEntries = 5000
|
||||
|
||||
// ISO8601DateFormatter is @MainActor in macOS 27. Use Date.ISO8601FormatStyle (value type, Sendable).
|
||||
private nonisolated static let isoStyle = Date.ISO8601FormatStyle(
|
||||
dateSeparator: .dash,
|
||||
dateTimeSeparator: .standard,
|
||||
timeSeparator: .colon,
|
||||
timeZoneSeparator: .colon,
|
||||
includingFractionalSeconds: true,
|
||||
timeZone: .gmt
|
||||
)
|
||||
|
||||
private nonisolated static func isoString(from date: Date) -> String {
|
||||
isoStyle.format(date)
|
||||
}
|
||||
|
||||
private nonisolated static func isoDate(from string: String) -> Date? {
|
||||
(try? isoStyle.parse(string)) ?? (try? Date(string, strategy: .iso8601))
|
||||
}
|
||||
|
||||
nonisolated private init() {
|
||||
isoFormatter = ISO8601DateFormatter()
|
||||
isoFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||
|
||||
let fileManager = FileManager.default
|
||||
let appSupport = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
||||
let dbDirectory = appSupport.appendingPathComponent("oAI", isDirectory: true)
|
||||
@@ -156,7 +170,7 @@ final class DatabaseService: Sendable {
|
||||
try! migrator.migrate(dbQueue)
|
||||
}
|
||||
|
||||
private var migrator: DatabaseMigrator {
|
||||
private nonisolated var migrator: DatabaseMigrator {
|
||||
var migrator = DatabaseMigrator()
|
||||
|
||||
migrator.registerMigration("v1") { db in
|
||||
@@ -375,7 +389,7 @@ final class DatabaseService: Sendable {
|
||||
nonisolated func saveConversation(id: UUID, name: String, messages: [Message], primaryModel: String?) throws -> Conversation {
|
||||
Log.db.info("Saving conversation '\(name)' with \(messages.count) messages (primaryModel: \(primaryModel ?? "none"))")
|
||||
let now = Date()
|
||||
let nowString = isoFormatter.string(from: now)
|
||||
let nowString = Self.isoString(from: now)
|
||||
|
||||
let convRecord = ConversationRecord(
|
||||
id: id.uuidString,
|
||||
@@ -394,7 +408,7 @@ final class DatabaseService: Sendable {
|
||||
content: msg.content,
|
||||
tokens: msg.tokens,
|
||||
cost: msg.cost,
|
||||
timestamp: isoFormatter.string(from: msg.timestamp),
|
||||
timestamp: Self.isoString(from: msg.timestamp),
|
||||
sortOrder: index,
|
||||
modelId: msg.modelId
|
||||
)
|
||||
@@ -420,7 +434,7 @@ final class DatabaseService: Sendable {
|
||||
|
||||
/// Update an existing conversation in-place: rename it, replace all its messages.
|
||||
nonisolated func updateConversation(id: UUID, name: String, messages: [Message], primaryModel: String?) throws {
|
||||
let nowString = isoFormatter.string(from: Date())
|
||||
let nowString = Self.isoString(from: Date())
|
||||
|
||||
let messageRecords = messages.enumerated().compactMap { index, msg -> MessageRecord? in
|
||||
guard msg.role != .system else { return nil }
|
||||
@@ -431,7 +445,7 @@ final class DatabaseService: Sendable {
|
||||
content: msg.content,
|
||||
tokens: msg.tokens,
|
||||
cost: msg.cost,
|
||||
timestamp: isoFormatter.string(from: msg.timestamp),
|
||||
timestamp: Self.isoString(from: msg.timestamp),
|
||||
sortOrder: index,
|
||||
modelId: msg.modelId
|
||||
)
|
||||
@@ -466,7 +480,7 @@ final class DatabaseService: Sendable {
|
||||
let messages = messageRecords.compactMap { record -> Message? in
|
||||
guard let msgId = UUID(uuidString: record.id),
|
||||
let role = MessageRole(rawValue: record.role),
|
||||
let timestamp = self.isoFormatter.date(from: record.timestamp)
|
||||
let timestamp = Self.isoDate(from: record.timestamp)
|
||||
else { return nil }
|
||||
|
||||
let starred = (try? MessageMetadataRecord.fetchOne(db, key: record.id))?.user_starred == 1
|
||||
@@ -484,8 +498,8 @@ final class DatabaseService: Sendable {
|
||||
}
|
||||
|
||||
guard let convId = UUID(uuidString: convRecord.id),
|
||||
let createdAt = self.isoFormatter.date(from: convRecord.createdAt),
|
||||
let updatedAt = self.isoFormatter.date(from: convRecord.updatedAt)
|
||||
let createdAt = Self.isoDate(from: convRecord.createdAt),
|
||||
let updatedAt = Self.isoDate(from: convRecord.updatedAt)
|
||||
else { return nil }
|
||||
|
||||
let conversation = Conversation(
|
||||
@@ -509,8 +523,8 @@ final class DatabaseService: Sendable {
|
||||
|
||||
return records.compactMap { record -> Conversation? in
|
||||
guard let id = UUID(uuidString: record.id),
|
||||
let createdAt = self.isoFormatter.date(from: record.createdAt),
|
||||
let updatedAt = self.isoFormatter.date(from: record.updatedAt)
|
||||
let createdAt = Self.isoDate(from: record.createdAt),
|
||||
let updatedAt = Self.isoDate(from: record.updatedAt)
|
||||
else { return nil }
|
||||
|
||||
// Fetch message count without loading all messages
|
||||
@@ -524,7 +538,7 @@ final class DatabaseService: Sendable {
|
||||
.order(Column("sortOrder").desc)
|
||||
.fetchOne(db)
|
||||
|
||||
let lastDate = lastMsg.flatMap { self.isoFormatter.date(from: $0.timestamp) } ?? updatedAt
|
||||
let lastDate = lastMsg.flatMap { Self.isoDate(from: $0.timestamp) } ?? updatedAt
|
||||
|
||||
// Derive primary model: prefer the stored field, fall back to last message's modelId
|
||||
let primaryModel = record.primaryModel ?? lastMsg?.modelId
|
||||
@@ -574,7 +588,7 @@ final class DatabaseService: Sendable {
|
||||
convRecord.name = name
|
||||
}
|
||||
|
||||
convRecord.updatedAt = self.isoFormatter.string(from: Date())
|
||||
convRecord.updatedAt = Self.isoString(from: Date())
|
||||
try convRecord.update(db)
|
||||
|
||||
if let messages = messages {
|
||||
@@ -589,7 +603,7 @@ final class DatabaseService: Sendable {
|
||||
content: msg.content,
|
||||
tokens: msg.tokens,
|
||||
cost: msg.cost,
|
||||
timestamp: self.isoFormatter.string(from: msg.timestamp),
|
||||
timestamp: Self.isoString(from: msg.timestamp),
|
||||
sortOrder: index
|
||||
)
|
||||
}
|
||||
@@ -610,7 +624,7 @@ final class DatabaseService: Sendable {
|
||||
let record = HistoryRecord(
|
||||
id: UUID().uuidString,
|
||||
input: input,
|
||||
timestamp: isoFormatter.string(from: now)
|
||||
timestamp: Self.isoString(from: now)
|
||||
)
|
||||
|
||||
try? dbQueue.write { db in
|
||||
@@ -643,7 +657,7 @@ final class DatabaseService: Sendable {
|
||||
.fetchAll(db)
|
||||
|
||||
return records.compactMap { record in
|
||||
guard let date = isoFormatter.date(from: record.timestamp) else {
|
||||
guard let date = Self.isoDate(from: record.timestamp) else {
|
||||
return nil
|
||||
}
|
||||
return (input: record.input, timestamp: date)
|
||||
@@ -659,7 +673,7 @@ final class DatabaseService: Sendable {
|
||||
.fetchAll(db)
|
||||
|
||||
return records.compactMap { record in
|
||||
guard let date = isoFormatter.date(from: record.timestamp) else {
|
||||
guard let date = Self.isoDate(from: record.timestamp) else {
|
||||
return nil
|
||||
}
|
||||
return (input: record.input, timestamp: date)
|
||||
@@ -672,7 +686,7 @@ final class DatabaseService: Sendable {
|
||||
nonisolated func saveEmailLog(_ log: EmailLog) {
|
||||
let record = EmailLogRecord(
|
||||
id: log.id.uuidString,
|
||||
timestamp: isoFormatter.string(from: log.timestamp),
|
||||
timestamp: Self.isoString(from: log.timestamp),
|
||||
sender: log.sender,
|
||||
subject: log.subject,
|
||||
emailContent: log.emailContent,
|
||||
@@ -698,7 +712,7 @@ final class DatabaseService: Sendable {
|
||||
.fetchAll(db)
|
||||
|
||||
return records.compactMap { record in
|
||||
guard let timestamp = isoFormatter.date(from: record.timestamp),
|
||||
guard let timestamp = Self.isoDate(from: record.timestamp),
|
||||
let status = EmailLogStatus(rawValue: record.status),
|
||||
let id = UUID(uuidString: record.id) else {
|
||||
return nil
|
||||
@@ -805,7 +819,7 @@ final class DatabaseService: Sendable {
|
||||
// MARK: - Embedding Operations
|
||||
|
||||
nonisolated func saveMessageEmbedding(messageId: UUID, embedding: Data, model: String, dimension: Int) throws {
|
||||
let now = isoFormatter.string(from: Date())
|
||||
let now = Self.isoString(from: Date())
|
||||
let record = MessageEmbeddingRecord(
|
||||
message_id: messageId.uuidString,
|
||||
embedding: embedding,
|
||||
@@ -825,7 +839,7 @@ final class DatabaseService: Sendable {
|
||||
}
|
||||
|
||||
nonisolated func saveConversationEmbedding(conversationId: UUID, embedding: Data, model: String, dimension: Int) throws {
|
||||
let now = isoFormatter.string(from: Date())
|
||||
let now = Self.isoString(from: Date())
|
||||
let record = ConversationEmbeddingRecord(
|
||||
conversation_id: conversationId.uuidString,
|
||||
embedding: embedding,
|
||||
@@ -881,7 +895,7 @@ final class DatabaseService: Sendable {
|
||||
return Array(results.prefix(limit))
|
||||
}
|
||||
|
||||
private func deserializeEmbedding(_ data: Data) -> [Float] {
|
||||
private nonisolated func deserializeEmbedding(_ data: Data) -> [Float] {
|
||||
var embedding: [Float] = []
|
||||
embedding.reserveCapacity(data.count / 4)
|
||||
|
||||
@@ -905,7 +919,7 @@ final class DatabaseService: Sendable {
|
||||
model: String?,
|
||||
tokenCount: Int?
|
||||
) throws {
|
||||
let now = isoFormatter.string(from: Date())
|
||||
let now = Self.isoString(from: Date())
|
||||
let record = ConversationSummaryRecord(
|
||||
id: UUID().uuidString,
|
||||
conversation_id: conversationId.uuidString,
|
||||
|
||||
@@ -71,7 +71,7 @@ enum EmbeddingProvider {
|
||||
// MARK: - Embedding Service
|
||||
|
||||
final class EmbeddingService {
|
||||
static let shared = EmbeddingService()
|
||||
nonisolated static let shared = EmbeddingService()
|
||||
|
||||
private let settings = SettingsService.shared
|
||||
|
||||
@@ -281,7 +281,7 @@ final class EmbeddingService {
|
||||
// MARK: - Similarity Calculation
|
||||
|
||||
/// Calculate cosine similarity between two embeddings
|
||||
func cosineSimilarity(_ a: [Float], _ b: [Float]) -> Float {
|
||||
nonisolated func cosineSimilarity(_ a: [Float], _ b: [Float]) -> Float {
|
||||
guard a.count == b.count else {
|
||||
Log.api.error("Embedding dimension mismatch: \(a.count) vs \(b.count)")
|
||||
return 0.0
|
||||
|
||||
@@ -29,7 +29,7 @@ import CryptoKit
|
||||
import IOKit
|
||||
|
||||
class EncryptionService {
|
||||
static let shared = EncryptionService()
|
||||
nonisolated static let shared = EncryptionService()
|
||||
|
||||
private let salt = "oAI-secure-storage-v1" // App-specific salt
|
||||
private lazy var encryptionKey: SymmetricKey = {
|
||||
@@ -41,7 +41,7 @@ class EncryptionService {
|
||||
// MARK: - Public Interface
|
||||
|
||||
/// Encrypt a string value
|
||||
func encrypt(_ value: String) throws -> String {
|
||||
nonisolated func encrypt(_ value: String) throws -> String {
|
||||
guard let data = value.data(using: .utf8) else {
|
||||
throw EncryptionError.invalidInput
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class EncryptionService {
|
||||
}
|
||||
|
||||
/// Decrypt a string value
|
||||
func decrypt(_ encryptedValue: String) throws -> String {
|
||||
nonisolated func decrypt(_ encryptedValue: String) throws -> String {
|
||||
guard let data = Data(base64Encoded: encryptedValue) else {
|
||||
throw EncryptionError.invalidInput
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ class GitSyncService {
|
||||
|
||||
// Check if conversation already exists (by ID)
|
||||
if let existingId = UUID(uuidString: export.id) {
|
||||
if let existing = try? db.loadConversation(id: existingId) {
|
||||
if (try? db.loadConversation(id: existingId)) != nil {
|
||||
// Already exists - skip
|
||||
log.debug("Skipping existing conversation: \(export.name)")
|
||||
skipped += 1
|
||||
|
||||
@@ -300,6 +300,24 @@ class SettingsService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Input bar height in points — default 80
|
||||
var inputBarHeight: Double {
|
||||
get { cache["inputBarHeight"].flatMap(Double.init) ?? 80.0 }
|
||||
set {
|
||||
cache["inputBarHeight"] = String(newValue)
|
||||
DatabaseService.shared.setSetting(key: "inputBarHeight", value: String(newValue))
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the sidebar is visible — default true
|
||||
var sidebarVisible: Bool {
|
||||
get { cache["sidebarVisible"] != "false" }
|
||||
set {
|
||||
cache["sidebarVisible"] = String(newValue)
|
||||
DatabaseService.shared.setSetting(key: "sidebarVisible", value: String(newValue))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MCP Permissions
|
||||
|
||||
var mcpCanWriteFiles: Bool {
|
||||
|
||||
@@ -35,6 +35,11 @@ final class UpdateCheckService {
|
||||
|
||||
var updateAvailable: Bool = false
|
||||
var latestVersion: String? = nil
|
||||
var downloadURL: URL? = nil
|
||||
|
||||
// Manual check state — drives the update alert in ContentView
|
||||
var isCheckingManually: Bool = false
|
||||
var manualCheckMessage: String? = nil
|
||||
|
||||
private let apiURL = "https://gitlab.pm/api/v1/repos/rune/oai-swift/releases/latest"
|
||||
private let releasesURL = URL(string: "https://gitlab.pm/rune/oai-swift/releases")!
|
||||
@@ -48,6 +53,24 @@ final class UpdateCheckService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Manual check triggered from the Help menu. Non-blocking — result surfaces via manualCheckMessage.
|
||||
func checkForUpdatesManually() {
|
||||
guard !isCheckingManually else { return }
|
||||
isCheckingManually = true
|
||||
Task.detached(priority: .background) {
|
||||
await self.performCheck()
|
||||
let current = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
|
||||
await MainActor.run {
|
||||
if self.updateAvailable, let v = self.latestVersion {
|
||||
self.manualCheckMessage = String(localized: "Version \(v) is available.")
|
||||
} else {
|
||||
self.manualCheckMessage = String(localized: "You're up to date (v\(current)).")
|
||||
}
|
||||
self.isCheckingManually = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func performCheck() async {
|
||||
guard let url = URL(string: apiURL) else { return }
|
||||
|
||||
@@ -69,9 +92,16 @@ final class UpdateCheckService {
|
||||
let latestVer = tagName.hasPrefix("v") ? String(tagName.dropFirst()) : tagName
|
||||
let currentVer = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.0"
|
||||
|
||||
// Extract direct DMG download URL from release assets
|
||||
let dmgURL: URL? = (release["assets"] as? [[String: Any]])?
|
||||
.first { ($0["name"] as? String ?? "").lowercased().hasSuffix(".dmg") }
|
||||
.flatMap { $0["browser_download_url"] as? String }
|
||||
.flatMap { URL(string: $0) }
|
||||
|
||||
if isNewer(latestVer, than: currentVer) {
|
||||
await MainActor.run {
|
||||
self.latestVersion = latestVer
|
||||
self.downloadURL = dmgURL
|
||||
self.updateAvailable = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user