Skip to content

Commit

Permalink
fix: keybarod on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustDev committed Feb 13, 2024
1 parent 4082e75 commit 3b78a5f
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 14 deletions.
12 changes: 8 additions & 4 deletions Enchanted.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
FF9300DE2B782A28000859F4 /* UnreachableAPIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF9300DD2B782A28000859F4 /* UnreachableAPIView.swift */; };
FF9300E02B783945000859F4 /* InputFields_macOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF9300DF2B783945000859F4 /* InputFields_macOS.swift */; };
FFB0327D2B312F3D0066A9DB /* RecordingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB0327C2B312F3D0066A9DB /* RecordingView.swift */; };
FFB21A872B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB21A862B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift */; };
FFBBF4842B34881B008D611C /* SpeechRecogniser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBBF4832B34881B008D611C /* SpeechRecogniser.swift */; };
FFBBF4882B34F9C8008D611C /* View+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBBF4872B34F9C8008D611C /* View+Extension.swift */; };
FFBBF48A2B350283008D611C /* SelectedImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBBF4892B350283008D611C /* SelectedImageView.swift */; };
Expand Down Expand Up @@ -112,6 +113,7 @@
FF9300DD2B782A28000859F4 /* UnreachableAPIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnreachableAPIView.swift; sourceTree = "<group>"; };
FF9300DF2B783945000859F4 /* InputFields_macOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFields_macOS.swift; sourceTree = "<group>"; };
FFB0327C2B312F3D0066A9DB /* RecordingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingView.swift; sourceTree = "<group>"; };
FFB21A862B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyboardReadable+Extension.swift"; sourceTree = "<group>"; };
FFBBF4822B348345008D611C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
FFBBF4832B34881B008D611C /* SpeechRecogniser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeechRecogniser.swift; sourceTree = "<group>"; };
FFBBF4872B34F9C8008D611C /* View+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -336,6 +338,7 @@
FF1002512B2609970011A4DC /* ModelContext+Extension.swift */,
FFBBF48B2B35051D008D611C /* UIImage+Extension.swift */,
FFBBF4872B34F9C8008D611C /* View+Extension.swift */,
FFB21A862B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -484,6 +487,7 @@
FFBBF48C2B35051D008D611C /* UIImage+Extension.swift in Sources */,
FF1002302B2482BA0011A4DC /* ChatMessageView.swift in Sources */,
FF1002322B2483A20011A4DC /* Colours+Extension.swift in Sources */,
FFB21A872B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift in Sources */,
FF66A51D2B76949A00FAAC1E /* Helpers.swift in Sources */,
FF10026A2B2731C60011A4DC /* ModelSelectorView.swift in Sources */,
FF38F84F2B7A7B6700546B56 /* MenuBarControlView_macOS.swift in Sources */,
Expand Down Expand Up @@ -657,7 +661,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Enchanted/Enchanted.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 4;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Enchanted/Preview Content\"";
DEVELOPMENT_TEAM = JDDZ55DT74;
Expand All @@ -682,7 +686,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.4.4;
PRODUCT_BUNDLE_IDENTIFIER = subj.Enchanted;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -702,7 +706,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = Enchanted/Enchanted.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 4;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Enchanted/Preview Content\"";
DEVELOPMENT_TEAM = JDDZ55DT74;
Expand All @@ -727,7 +731,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.4.1;
MARKETING_VERSION = 1.4.4;
PRODUCT_BUNDLE_IDENTIFIER = subj.Enchanted;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
34 changes: 34 additions & 0 deletions Enchanted/Extensions/KeyboardReadable+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// KeyboardReadable+Extension.swift
// Enchanted
//
// Created by Augustinas Malinauskas on 13/02/2024.
//

import SwiftUI
import Combine

#if os(iOS)
/// Publisher to read keyboard changes.
protocol KeyboardReadable {
var keyboardPublisher: AnyPublisher<Bool, Never> { get }
}

extension KeyboardReadable {
var keyboardPublisher: AnyPublisher<Bool, Never> {
Publishers.Merge(
NotificationCenter.default
.publisher(for: UIResponder.keyboardWillShowNotification)
.map { _ in true },

NotificationCenter.default
.publisher(for: UIResponder.keyboardWillHideNotification)
.map { _ in false }
)
.eraseToAnyPublisher()
}
}
#elseif os(macOS)
/// Mock protocol
protocol KeyboardReadable {}
#endif
1 change: 0 additions & 1 deletion Enchanted/Services/SwiftDataService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ actor SwiftDataService {
ConversationSD.self,
MessageSD.self,
])
print("init bruv")
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

do {
Expand Down
2 changes: 1 addition & 1 deletion Enchanted/Stores/ConversationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class ConversationStore {
messages = []
}
selectedConversation = nil
try? await swiftDataService.deleteEverything()
try? await swiftDataService.deleteConversations()
try? await loadConversations()
}
}
Expand Down
6 changes: 6 additions & 0 deletions Enchanted/UI/Shared/ApplicationEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ struct ApplicationEntry: View {
var body: some View {
Chat(languageModelStore: languageModelStore, conversationStore: conversationStore, appStore: appStore)
.task {
if let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String {
print("CFBundleVersion: \(build)")
}
if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
print("CFBundleShortVersionString: \(version)")
}
Task.detached {
async let loadModels: () = languageModelStore.loadModels()
async let loadConversations: () = conversationStore.loadConversations()
Expand Down
25 changes: 20 additions & 5 deletions Enchanted/UI/Shared/Chat/Components/EmptyConversaitonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

import SwiftUI

struct EmptyConversaitonView: View {
@State var showPrompts = false
struct EmptyConversaitonView: View, KeyboardReadable {
@State var showPromptsAnimation = false
@State var prompts: [SamplePrompts] = []
var sendPrompt: (String) -> ()
#if os(iOS)
@State var isKeyboardVisible = false
#endif

#if os(macOS)
var columns = Array.init(repeating: GridItem(.flexible(), spacing: 15), count: 4)
Expand Down Expand Up @@ -55,24 +58,36 @@ struct EmptyConversaitonView: View {
.padding(15)
.background(Color.gray5Custom)
.clipShape(RoundedRectangle(cornerRadius: 10))

}
.transition(.slide)
.showIf(showPrompts)
.showIf(showPromptsAnimation)
.buttonStyle(.plain)
}
}
.frame(maxWidth: 700)
.padding()
.transition(AnyTransition(.opacity).combined(with: .slide))
#if os(iOS)
.showIf(!isKeyboardVisible)
#endif
}
Spacer()
}
.onAppear {
withAnimation {
prompts = SamplePrompts.samples.shuffled()
showPrompts = true
showPromptsAnimation = true
}
}
#if os(iOS)
.onReceive(keyboardPublisher) { newIsKeyboardVisible in
withAnimation {
isKeyboardVisible = newIsKeyboardVisible
}
}
#endif

}
}

Expand Down
4 changes: 4 additions & 0 deletions Enchanted/UI/Shared/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct Settings: View {
}
}

private func deleteAll() {
conversationStore.deleteAllConversations()
}

@State var ollamaStatus: Bool?
var body: some View {
SettingsView(
Expand Down
9 changes: 8 additions & 1 deletion Enchanted/UI/macOS/Chat/ChatView_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ struct ChatView: View {
conversationState: conversationState,
onStopGenerateTap: onStopGenerateTap,
selectedModel: selectedModel,
onSendMessageTap: onSendMessageTap
onSendMessageTap: onSendMessageTap,
editMessage: $editMessage
)
.padding()
.frame(maxWidth: 800)
Expand All @@ -78,6 +79,12 @@ struct ChatView: View {
onNewConversationTap: onNewConversationTap
)
}
.onChange(of: editMessage, initial: false) { _, newMessage in
if let newMessage = newMessage {
message = newMessage.content
isFocusedInput = true
}
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions Enchanted/UI/macOS/Chat/Components/InputFields_macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ struct InputFieldsView: View {
var onStopGenerateTap: @MainActor () -> Void
var selectedModel: LanguageModelSD?
var onSendMessageTap: @MainActor (_ prompt: String, _ model: LanguageModelSD, _ image: Image?, _ trimmingMessageId: String?) -> ()
@Binding var editMessage: MessageSD?

@State private var selectedImage: Image?
@State private var editMessage: MessageSD?
@FocusState private var isFocusedInput: Bool

@MainActor private func sendMessage() {
Expand Down Expand Up @@ -97,7 +97,8 @@ struct InputFieldsView: View {
message: .constant(""),
conversationState: .completed,
onStopGenerateTap: {},
onSendMessageTap: {_, _, _, _ in}
onSendMessageTap: {_, _, _, _ in},
editMessage: .constant(nil)
)
}
#endif

0 comments on commit 3b78a5f

Please sign in to comment.