aboutsummaryrefslogtreecommitdiff
path: root/iTexSnip/Views
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2024-10-22 23:21:56 -0600
committerNavan Chauhan <navanchauhan@gmail.com>2024-10-22 23:21:56 -0600
commitd5a52a1f01e9b1af5e3ea1dfd7d45865c97c9ade (patch)
tree9ec5a65c4b8aae5f2ab65e7686b81dd94fca560c /iTexSnip/Views
parent7b8af36bf8131d4be783f4c4c425ca5f5fa0ac52 (diff)
add option to load model on demand
Diffstat (limited to 'iTexSnip/Views')
-rw-r--r--iTexSnip/Views/MenuBarView.swift47
1 files changed, 39 insertions, 8 deletions
diff --git a/iTexSnip/Views/MenuBarView.swift b/iTexSnip/Views/MenuBarView.swift
index 255ad99..4face4d 100644
--- a/iTexSnip/Views/MenuBarView.swift
+++ b/iTexSnip/Views/MenuBarView.swift
@@ -38,6 +38,7 @@ struct MenuBarView: View {
@Environment(\.modelContext) var modelContext
@State var model: TexTellerModel?
@Query(sort: \ImageSnippet.dateModifed, order: .reverse) var snippets: [ImageSnippet]
+ @AppStorage("loadModelOnStart") var loadModelOnStart: Bool = true
let columns = [
GridItem(.flexible(), spacing: 16),
@@ -99,15 +100,17 @@ struct MenuBarView: View {
Spacer()
}.task {
- do {
- if self.model == nil {
- let mymodel = try await TexTellerModel.asyncInit()
- self.model = mymodel
- print("Loaded da model")
+ if loadModelOnStart {
+ do {
+ if self.model == nil {
+ let mymodel = try await TexTellerModel.asyncInit()
+ self.model = mymodel
+ print("Loaded da model")
+ }
+ } catch {
+ print("Failed to load da model: \(error)")
+ }
}
- } catch {
- print("Failed to load da model: \(error)")
- }
}
}
}
@@ -122,6 +125,17 @@ struct MenuBarView: View {
if panel.runModal() == .OK {
if let url = panel.url, let image = NSImage(contentsOf: url) {
let newSnippet = ImageSnippet(image: image)
+ if self.loadModelOnStart == false {
+ do {
+ if self.model == nil {
+ let mymodel = try TexTellerModel()
+ self.model = mymodel
+ print("Loaded model on demand")
+ }
+ } catch {
+ print("Failed to load da model: \(error)")
+ }
+ }
do {
if self.model != nil {
let latex = try self.model!.texIt(image)
@@ -132,6 +146,9 @@ struct MenuBarView: View {
} catch {
print("Failed to save new snippet: \(error)")
}
+ if self.loadModelOnStart == false {
+ self.model = nil
+ }
}
}
}
@@ -167,6 +184,17 @@ struct MenuBarView: View {
if FileManager.default.fileExists(atPath: tempPath) {
if let screenshotImage = NSImage(contentsOfFile: tempPath) {
let newSnippet = ImageSnippet(image: screenshotImage)
+ if self.loadModelOnStart == false {
+ do {
+ if self.model == nil {
+ let mymodel = try TexTellerModel()
+ self.model = mymodel
+ print("Loaded model on demand")
+ }
+ } catch {
+ print("Failed to load da model: \(error)")
+ }
+ }
do {
if self.model != nil {
let latex = try self.model!.texIt(screenshotImage)
@@ -177,6 +205,9 @@ struct MenuBarView: View {
} catch {
print("Failed to add snippet: \(error)")
}
+ if (self.loadModelOnStart == false) {
+ self.model = nil
+ }
} else {
print("Failed to get image...")
}