Skip to content

Commit 70a0dc7

Browse files
committed
feat: don't copy if clip is too big
1 parent 353614a commit 70a0dc7

File tree

17 files changed

+326
-276
lines changed

17 files changed

+326
-276
lines changed

ClipboardItem+CoreDataProperties.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import CoreData
1212

1313
extension ClipboardItem {
1414

15-
@nonobjc public class func fetchRequest(q: String?) -> NSFetchRequest<ClipboardItem> {
15+
@nonobjc public class func fetchRequest(q: String?, _ limit: Int = 20) -> NSFetchRequest<ClipboardItem> {
1616
let request = NSFetchRequest<ClipboardItem>(entityName: "ClipboardItem")
1717
request.fetchBatchSize = 10
18-
request.fetchLimit = 20
18+
request.fetchLimit = limit
1919
let createdAtSortDescriptor = NSSortDescriptor(key: "createdAt", ascending: false)
2020
request.sortDescriptors = [createdAtSortDescriptor]
2121
if let textQuery = q, !textQuery.isEmpty {
@@ -31,6 +31,4 @@ extension ClipboardItem {
3131

3232
}
3333

34-
extension ClipboardItem : Identifiable {
35-
36-
}
34+
extension ClipboardItem : Identifiable {}

PerfectClip 2021-12-16 17-13-37/PerfectClip.app/Contents/Info.plist

Lines changed: 0 additions & 50 deletions
This file was deleted.
Binary file not shown.

PerfectClip 2021-12-16 17-13-37/PerfectClip.app/Contents/PkgInfo

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.
Binary file not shown.

PerfectClip 2021-12-16 17-13-37/PerfectClip.app/Contents/_CodeSignature/CodeResources

Lines changed: 0 additions & 139 deletions
This file was deleted.

PerfectClip.xcodeproj/project.pbxproj

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/* Begin PBXBuildFile section */
1010
D10CD47A277DE3ED001F9024 /* HotKey in Frameworks */ = {isa = PBXBuildFile; productRef = D10CD479277DE3ED001F9024 /* HotKey */; };
1111
D10CD47C278650BD001F9024 /* SearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = D10CD47B278650BD001F9024 /* SearchField.swift */; };
12+
D176C13227C2B40600D0BF11 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D176C13127C2B40600D0BF11 /* Extensions.swift */; };
13+
D176C13427C2BF5C00D0BF11 /* ClipsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D176C13327C2BF5C00D0BF11 /* ClipsListView.swift */; };
14+
D1BE855827C103A000C65FCE /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BE855727C103A000C65FCE /* HomeView.swift */; };
15+
D1BE855A27C1185F00C65FCE /* TabButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BE855927C1185F00C65FCE /* TabButton.swift */; };
1216
D1EDCC2427669453005E2CF7 /* PerfectClipApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EDCC2327669453005E2CF7 /* PerfectClipApp.swift */; };
1317
D1EDCC2627669453005E2CF7 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EDCC2527669453005E2CF7 /* ContentView.swift */; };
1418
D1EDCC2827669454005E2CF7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D1EDCC2727669454005E2CF7 /* Assets.xcassets */; };
@@ -42,6 +46,10 @@
4246

4347
/* Begin PBXFileReference section */
4448
D10CD47B278650BD001F9024 /* SearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchField.swift; sourceTree = "<group>"; };
49+
D176C13127C2B40600D0BF11 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
50+
D176C13327C2BF5C00D0BF11 /* ClipsListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClipsListView.swift; sourceTree = "<group>"; };
51+
D1BE855727C103A000C65FCE /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
52+
D1BE855927C1185F00C65FCE /* TabButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabButton.swift; sourceTree = "<group>"; };
4553
D1EDCC2027669453005E2CF7 /* PerfectClip.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PerfectClip.app; sourceTree = BUILT_PRODUCTS_DIR; };
4654
D1EDCC2327669453005E2CF7 /* PerfectClipApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerfectClipApp.swift; sourceTree = "<group>"; };
4755
D1EDCC2527669453005E2CF7 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -122,6 +130,10 @@
122130
D1EDCC532767D0A1005E2CF7 /* Model.xcdatamodeld */,
123131
D1EDCC562767D483005E2CF7 /* Store.swift */,
124132
D10CD47B278650BD001F9024 /* SearchField.swift */,
133+
D1BE855727C103A000C65FCE /* HomeView.swift */,
134+
D1BE855927C1185F00C65FCE /* TabButton.swift */,
135+
D176C13127C2B40600D0BF11 /* Extensions.swift */,
136+
D176C13327C2BF5C00D0BF11 /* ClipsListView.swift */,
125137
);
126138
path = PerfectClip;
127139
sourceTree = "<group>";
@@ -287,13 +299,17 @@
287299
isa = PBXSourcesBuildPhase;
288300
buildActionMask = 2147483647;
289301
files = (
302+
D1BE855827C103A000C65FCE /* HomeView.swift in Sources */,
290303
D10CD47C278650BD001F9024 /* SearchField.swift in Sources */,
291304
D1EDCC2627669453005E2CF7 /* ContentView.swift in Sources */,
305+
D1BE855A27C1185F00C65FCE /* TabButton.swift in Sources */,
306+
D176C13427C2BF5C00D0BF11 /* ClipsListView.swift in Sources */,
292307
D1EDCC522766A253005E2CF7 /* MenuView.swift in Sources */,
293308
D1EDCC552767D0A1005E2CF7 /* Model.xcdatamodeld in Sources */,
294309
D1EDCC5C2767D596005E2CF7 /* ClipboardItem+CoreDataProperties.swift in Sources */,
295310
D1EDCC5B2767D596005E2CF7 /* ClipboardItem+CoreDataClass.swift in Sources */,
296311
D1EDCC572767D483005E2CF7 /* Store.swift in Sources */,
312+
D176C13227C2B40600D0BF11 /* Extensions.swift in Sources */,
297313
D1EDCC2427669453005E2CF7 /* PerfectClipApp.swift in Sources */,
298314
);
299315
runOnlyForDeploymentPostprocessing = 0;
@@ -366,6 +382,7 @@
366382
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
367383
COPY_PHASE_STRIP = NO;
368384
DEBUG_INFORMATION_FORMAT = dwarf;
385+
ENABLE_PREVIEWS = NO;
369386
ENABLE_STRICT_OBJC_MSGSEND = YES;
370387
ENABLE_TESTABILITY = YES;
371388
GCC_C_LANGUAGE_STANDARD = gnu11;
@@ -428,9 +445,11 @@
428445
COPY_PHASE_STRIP = NO;
429446
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
430447
ENABLE_NS_ASSERTIONS = NO;
448+
ENABLE_PREVIEWS = NO;
431449
ENABLE_STRICT_OBJC_MSGSEND = YES;
432450
GCC_C_LANGUAGE_STANDARD = gnu11;
433451
GCC_NO_COMMON_BLOCKS = YES;
452+
GCC_OPTIMIZATION_LEVEL = 0;
434453
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
435454
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
436455
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -442,7 +461,7 @@
442461
MTL_FAST_MATH = YES;
443462
SDKROOT = macosx;
444463
SWIFT_COMPILATION_MODE = wholemodule;
445-
SWIFT_OPTIMIZATION_LEVEL = "-O";
464+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
446465
};
447466
name = Release;
448467
};

PerfectClip.xcodeproj/xcuserdata/petarpetrov.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,22 @@
33
uuid = "E62549D2-D73A-4848-8EA5-2A51D0CC38C6"
44
type = "1"
55
version = "2.0">
6+
<Breakpoints>
7+
<BreakpointProxy
8+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
9+
<BreakpointContent
10+
uuid = "C430F3FC-61EB-4DC1-BBEB-C79E77955EC4"
11+
shouldBeEnabled = "No"
12+
ignoreCount = "0"
13+
continueAfterRunningActions = "No"
14+
filePath = "PerfectClip/HomeView.swift"
15+
startingColumnNumber = "9223372036854775807"
16+
endingColumnNumber = "9223372036854775807"
17+
startingLineNumber = "12"
18+
endingLineNumber = "12"
19+
landmarkName = "body"
20+
landmarkType = "24">
21+
</BreakpointContent>
22+
</BreakpointProxy>
23+
</Breakpoints>
624
</Bucket>

PerfectClip/ClipsListView.swift

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,67 @@
88
import SwiftUI
99

1010
struct ClipsListView: View {
11+
@State private var store: Store?
12+
@State private var selection = Set<ClipboardItem.ID>()
13+
@State private var searchText = ""
14+
15+
func filter(item: ClipboardItem) -> Bool {
16+
if ((store?.searchText.isEmpty) != nil) {
17+
return true
18+
}
19+
return (item.text?.lowercased().contains((store?.searchText.lowercased())!) ?? false)
20+
}
21+
1122
var body: some View {
12-
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
23+
Group {
24+
Table(store?.clipboardItems.filter(filter) ?? [], selection: $selection) {
25+
TableColumn("Text", value: \.text!)
26+
TableColumn("Created At") { clip in
27+
Text(clip.createdAt!.formatDate())
28+
}.width(100)
29+
}
30+
.onAppear {
31+
lazy var persistentContainer: NSPersistentContainer = {
32+
let container = NSPersistentContainer(name: "Model")
33+
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
34+
if let error = error as NSError? {
35+
fatalError("Unresolved error \(error), \(error.userInfo)")
36+
}
37+
})
38+
return container
39+
}()
40+
store = Store(managedObjectContext: persistentContainer.viewContext)
41+
store?.fetchQuery(100)
42+
}
43+
.onDeleteCommand(perform: {
44+
store?.clipboardItems.forEach({ item in
45+
if selection.contains(ObjectIdentifier(item)) {
46+
store?.deleteItem(item)
47+
}
48+
})
49+
})
50+
.padding()
51+
}
52+
.toolbar {
53+
Button("Clear All") {
54+
if (store != nil) && store?.clipboardItems != nil {
55+
store!.clearHistory(store!.clipboardItems)
56+
}
57+
58+
}
59+
}
60+
.searchable(text: $searchText)
61+
.onSubmit(of: .search) {
62+
store?.searchText = searchText
63+
store?.fetchQuery()
64+
}
65+
.onChange(of: searchText) { _newSearchText in
66+
if searchText.isEmpty {
67+
store?.searchText = ""
68+
store?.fetchQuery(100)
69+
}
70+
}
71+
.navigationTitle("Clips")
1372
}
1473
}
1574

0 commit comments

Comments
 (0)