Skip to content

Commit

Permalink
Settings - Ollama Ping Interval (#102)
Browse files Browse the repository at this point in the history
* Settings - Ping Interval

Adding a setting to set the interval in seconds when the app should check
if the Ollama service is reachable. Default is 5 seconds.

* fix: support no pinging at all

---------

Co-authored-by: Augustinas Malinauskas <augustinasmal@gmail.com>
  • Loading branch information
vanhalt and AugustDev committed May 7, 2024
1 parent 3b72211 commit 680c28b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Enchanted/Stores/AppStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ final class AppStore {

private var cancellables = Set<AnyCancellable>()
private var timer: Timer?
private var pingInterval: TimeInterval = 5
@MainActor var isReachable: Bool = true
@MainActor var notifications: [NotificationMessage] = []
@MainActor var menuBarIcon: String? = nil

init() {
startCheckingReachability()
if let storedIntervalString = UserDefaults.standard.string(forKey: "pingInterval") {
pingInterval = Double(storedIntervalString) ?? 5

if pingInterval <= 0 {
pingInterval = .infinity
}
}
startCheckingReachability(interval: pingInterval)
}

deinit {
Expand Down
2 changes: 2 additions & 0 deletions Enchanted/UI/Shared/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Settings: View {
@AppStorage("defaultOllamaModel") private var defaultOllamaModel: String = ""
@AppStorage("ollamaBearerToken") private var ollamaBearerToken: String = ""
@AppStorage("appUserInitials") private var appUserInitials: String = ""
@AppStorage("pingInterval") private var pingInterval: String = "5"

@Environment(\.presentationMode) var presentationMode

Expand Down Expand Up @@ -59,6 +60,7 @@ struct Settings: View {
defaultOllamModel: $defaultOllamaModel,
ollamaBearerToken: $ollamaBearerToken,
appUserInitials: $appUserInitials,
pingInterval: $pingInterval,
save: save,
checkServer: checkServer,
deleteAllConversations: conversationStore.deleteAllConversations,
Expand Down
5 changes: 5 additions & 0 deletions Enchanted/UI/Shared/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct SettingsView: View {
@Binding var defaultOllamModel: String
@Binding var ollamaBearerToken: String
@Binding var appUserInitials: String
@Binding var pingInterval: String
@State var ollamaStatus: Bool?
var save: () -> ()
var checkServer: () -> ()
Expand Down Expand Up @@ -101,6 +102,9 @@ struct SettingsView: View {
#if os(iOS)
.autocapitalization(.none)
#endif
TextField("Ping Interval (seconds)", text: $pingInterval)
.disableAutocorrection(true)
.textFieldStyle(RoundedBorderTextFieldStyle())

Section(header: Text("APP").font(.headline).padding(.top, 20)) {

Expand Down Expand Up @@ -164,6 +168,7 @@ struct SettingsView: View {
defaultOllamModel: .constant("llama2"),
ollamaBearerToken: .constant("x"),
appUserInitials: .constant("AM"),
pingInterval: .constant("5"),
save: {},
checkServer: {},
deleteAllConversations: {},
Expand Down

0 comments on commit 680c28b

Please sign in to comment.