Skip to content

Commit

Permalink
add explicit setting for recording clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonjmcghee committed Dec 28, 2023
1 parent 06eb22f commit 049977f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
961C96102B2E73B00093F228 /* ffmpeg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 961C960D2B2E73840093F228 /* ffmpeg */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
961C96132B2EB7DB0093F228 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961C96122B2EB7DB0093F228 /* TimelineView.swift */; };
961C96152B2EBEE50093F228 /* DB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961C96142B2EBEE50093F228 /* DB.swift */; };
969BA2EC2B3D1D46009EE9C6 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969BA2EB2B3D1D46009EE9C6 /* SettingsManager.swift */; };
969F3EFF2B3A8C4D0085787B /* HotKey in Frameworks */ = {isa = PBXBuildFile; productRef = 969F3EFE2B3A8C4D0085787B /* HotKey */; };
969F3F042B3B70560085787B /* SQLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96E66BBF2B2F5745006E1E97 /* SQLite.framework */; };
969F3F052B3B70560085787B /* SQLite.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96E66BBF2B2F5745006E1E97 /* SQLite.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -183,6 +184,7 @@
961C960D2B2E73840093F228 /* ffmpeg */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = ffmpeg; sourceTree = "<group>"; };
961C96122B2EB7DB0093F228 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
961C96142B2EBEE50093F228 /* DB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DB.swift; sourceTree = "<group>"; };
969BA2EB2B3D1D46009EE9C6 /* SettingsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsManager.swift; sourceTree = "<group>"; };
969F3F072B3B7C7C0085787B /* RemFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemFileManager.swift; sourceTree = "<group>"; };
969F3F092B3B7F760085787B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
969F3F0A2B3CB2110085787B /* Field.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Field.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -261,6 +263,7 @@
969F3F072B3B7C7C0085787B /* RemFileManager.swift */,
969F3F0A2B3CB2110085787B /* Field.swift */,
969F3F0C2B3CCEC30085787B /* Ask.swift */,
969BA2EB2B3D1D46009EE9C6 /* SettingsManager.swift */,
);
path = rem;
sourceTree = "<group>";
Expand Down Expand Up @@ -593,6 +596,7 @@
961C95DA2B2E19B30093F228 /* remApp.swift in Sources */,
96B0DA382B3A02530030E8AE /* ClipboardManager.swift in Sources */,
969F3F0B2B3CB2110085787B /* Field.swift in Sources */,
969BA2EC2B3D1D46009EE9C6 /* SettingsManager.swift in Sources */,
969F3F0D2B3CCEC30085787B /* Ask.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
35 changes: 33 additions & 2 deletions rem/remApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct remApp: App {
class AppDelegate: NSObject, NSApplicationDelegate {
var timelineViewWindow: NSWindow?
var timelineView = TimelineView(viewModel: TimelineViewModel())

var settingsManager = SettingsManager()
var settingsViewWindow: NSWindow?

var statusBarItem: NSStatusItem!
var popover: NSPopover!
Expand Down Expand Up @@ -123,13 +126,37 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem(title: "Open Timeline", action: #selector(self.showTimelineView), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Search", action: #selector(self.showSearchView), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Copy Recent Context", action: #selector(self.copyRecentContext), keyEquivalent: ""))
menu.addItem(NSMenuItem.separator()) // Separator
menu.addItem(NSMenuItem(title: "⚠️ Purge All Data ⚠️", action: #selector(self.confirmPurgeAllData), keyEquivalent: ""))
menu.addItem(NSMenuItem.separator()) // Separator
menu.addItem(
withTitle: "Settings",
action: #selector(self.openSettings),
keyEquivalent: ""
)
menu.addItem(NSMenuItem(title: "Quit", action: #selector(self.quitApp), keyEquivalent: "q"))
self.statusBarItem.menu = menu
}
}

@objc func openSettings() {
if settingsViewWindow == nil {
let settingsView = SettingsView(settingsManager: settingsManager)
settingsViewWindow = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 400, height: 300),
styleMask: [.titled, .closable],
backing: .buffered,
defer: false)
settingsViewWindow?.isReleasedWhenClosed = false
settingsViewWindow?.center()
settingsViewWindow?.contentView = NSHostingView(rootView: settingsView)
settingsViewWindow?.makeKeyAndOrderFront(nil)
} else if (!(settingsViewWindow?.isVisible ?? false)) {
settingsViewWindow?.makeKeyAndOrderFront(nil)
settingsViewWindow?.orderFrontRegardless() // Ensure it comes to the front
}
}

@objc func confirmPurgeAllData() {
let alert = NSAlert()
alert.messageText = "Purge all data?"
Expand Down Expand Up @@ -357,8 +384,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let nsImage = NSImage(cgImage: image, size: NSSize(width: image.width, height: image.height))
let analysis = try await ImageAnalyzer().analyze(nsImage, orientation: CGImagePropertyOrientation.up, configuration: configuration)
let textToAssociate = analysis.transcript
let newClipboardText = ClipboardManager.shared.getClipboardIfChanged() ?? ""
DatabaseManager.shared.insertTextForFrame(frameId: frameId, text: [textToAssociate, newClipboardText].joined(separator: "\n"))
var text = [textToAssociate]
if self.settingsManager.settings.saveEverythingCopiedToClipboard {
let newClipboardText = ClipboardManager.shared.getClipboardIfChanged() ?? ""
text.append(newClipboardText)
}
DatabaseManager.shared.insertTextForFrame(frameId: frameId, text: text.joined(separator: "\n"))
// print(textToAssociate)
} catch {
print("OCR error: \(error.localizedDescription)")
Expand Down

0 comments on commit 049977f

Please sign in to comment.