Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"indentation": {
"spaces": 4
},
"lineLength": 120,
"multiElementCollectionTrailingCommas": true,
"spacesAroundRangeFormationOperators": true,
}
783 changes: 666 additions & 117 deletions ChatMLX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions ChatMLX.xcodeproj/xcshareddata/xcschemes/ChatMLX.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.SQLDebug"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.CloudKitDebug 1 "
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.MigrationDebug"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.Logging.stderr "
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
Expand Down
55 changes: 55 additions & 0 deletions ChatMLX.xcodeproj/xcshareddata/xcschemes/ChatMLXTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "527821992CB821A600638477"
BuildableName = "ChatMLXTests.xctest"
BlueprintName = "ChatMLXTests"
ReferencedContainer = "container:ChatMLX.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
<key>ChatMLX.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>0</integer>
</dict>
<key>ChatMLXTests.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand All @@ -17,6 +22,11 @@
<key>primary</key>
<true/>
</dict>
<key>527821992CB821A600638477</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
131 changes: 131 additions & 0 deletions ChatMLX/Application/ChatMLXApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// ChatMLXApp.swift
// ChatMLX
//
// Created by John Mai on 2024/8/3.
//

import Defaults
import SwiftUI
import os

@main
struct ChatMLXApp: App {
// MARK: - Properties

private let currentVersion = getVersion()
private let viewContext = PersistenceController.shared.container.viewContext
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ChatMLXApp")

// MARK: - Environment

@Environment(\.scenePhase) private var scenePhase
@Environment(\.openSettings) private var openSettings
@Environment(\.dismissWindow) private var dismissWindow
@Environment(\.openWindow) private var openWindow

// MARK: - State

@State private var conversationStore: ConversationStore = .init()
@State private var settingsViewModel: SettingsViewModel = .init()
@State private var errorWrapper: ErrorWrapper?
@State private var settingsStore = SettingsStore()


// MARK: - User Defaults

@Default(.language) var language
@Default(.lastLaunchedVersion) var lastLaunchedVersion

init() {
updateVersionIfNeeded()
}

var body: some Scene {
Group {
mainWindow()
settingsWindow()
}
.environment(conversationStore)
.environment(ModelStore())
.environment(settingsStore)
.environment(DownloadStore.shared)
.environment(settingsViewModel)
.environment(\.managedObjectContext, viewContext)
.environment(\.locale, .init(identifier: language.rawValue))
.environment(\.appError) { error in
Task { @MainActor in
errorWrapper = ErrorWrapper(error: error, guidance: "")
}
}
.onChange(of: scenePhase) { _, newValue in
if newValue == .background {
try? viewContext.saveChanges()
}
}

menu()
}
}

// MARK: - Scenes

extension ChatMLXApp {
// MARK: - Main Window

private func mainWindow() -> some Scene {
WindowGroup(id: Constants.mainWindowID) {
ConversationView(selectedConversation: $conversationStore.selectedConversation)
.frame(minWidth: 900, minHeight: 580)
.sheet(item: $errorWrapper) { errorWrapper in
ErrorView(errorWrapper: errorWrapper)
}
}
}

// MARK: - Settings Window

private func settingsWindow() -> some Scene {
Settings {
SettingsView()
.frame(width: 650, height: 480)
.sheet(item: $errorWrapper) { errorWrapper in
ErrorView(errorWrapper: errorWrapper)
}
}
}

// MARK: - Menu

private func menu() -> some Scene {
MenuBarExtra {
Button("Open \(Bundle.main.name)") {
dismissWindow(id: Constants.mainWindowID)
NSApp.activate(ignoringOtherApps: true)
openWindow(id: Constants.mainWindowID)
}
Button("New Conversation") {}
Button("Settings") {
openSettings()
}
.keyboardShortcut(",")
Button("Quit") {
NSApp.terminate(nil)
}
.keyboardShortcut("q")
} label: {
Image("menubarIcon")
.renderingMode(.template)
}
}
}

// MARK: - Private Methods

extension ChatMLXApp {
private func updateVersionIfNeeded() {
if currentVersion != lastLaunchedVersion {
Defaults[.lastLaunchedVersion] = currentVersion
}
}
}
38 changes: 0 additions & 38 deletions ChatMLX/Assets.xcassets/AccentColor.colorset/Contents.json

This file was deleted.

Loading