Skip to content

Commit

Permalink
to be honest, I forgot what went here.. I just want to get this updat…
Browse files Browse the repository at this point in the history
…e out already
  • Loading branch information
alin23 committed Jul 6, 2024
1 parent e707cf1 commit ee834c3
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Clop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
C73802012BD1B804001BEE6C /* bin.tar.lrz */ = {isa = PBXFileReference; lastKnownFileType = file; path = bin.tar.lrz; sourceTree = "<group>"; };
C73802042BD1B81A001BEE6C /* lrzip */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = lrzip; sourceTree = SOURCE_ROOT; };
C73802062BDCD76D001BEE6C /* CompareView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompareView.swift; sourceTree = "<group>"; };
C744D07D2B444F6B003D77DE /* Lowtech */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Lowtech; path = ../Lowtech; sourceTree = "<group>"; };
C75FD1EB2AF4324C000B426B /* Clop.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Clop.app; sourceTree = BUILT_PRODUCTS_DIR; };
C75FD1FD2AF434FE000B426B /* FinderOptimiser-setapp.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "FinderOptimiser-setapp.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
C75FD20C2AF4351D000B426B /* ClopCLI-setapp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ClopCLI-setapp"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -275,6 +274,7 @@
C7AB662B2883015A0041BEC8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
C7AB662D2883015A0041BEC8 /* Clop.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Clop.entitlements; sourceTree = "<group>"; };
C7AB663A288460F30041BEC8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
C7AD8E8A2C2463CE008E4182 /* Lowtech */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Lowtech; path = ../Lowtech; sourceTree = "<group>"; };
C7C066702AF620A8004237F8 /* ClopCLI-setapp.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = "ClopCLI-setapp.entitlements"; sourceTree = "<group>"; };
C7C066712AF620A8004237F8 /* FinderOptimiser-setapp.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = "FinderOptimiser-setapp.entitlements"; sourceTree = "<group>"; };
C7C066722AF620A8004237F8 /* Setapp.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Setapp.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -379,7 +379,7 @@
C7AB6618288301590041BEC8 = {
isa = PBXGroup;
children = (
C744D07D2B444F6B003D77DE /* Lowtech */,
C7AD8E8A2C2463CE008E4182 /* Lowtech */,
C70B5F302AC029DA00345739 /* Shared.swift */,
C7C0666F2AF62055004237F8 /* Setapp */,
C7AB6623288301590041BEC8 /* Clop */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/getsentry/sentry-cocoa",
"state" : {
"revision" : "a62862c99f5bcb28fd78617fab1a5fe29607c06c",
"version" : "8.28.0"
"revision" : "08862789e1cbba7a9561bed69832a9306f339cd3",
"version" : "8.29.1"
}
},
{
Expand All @@ -104,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/sparkle-project/Sparkle",
"state" : {
"revision" : "41847a58cdef7506b257591fcca6f9495df591d4",
"version" : "2.6.2"
"revision" : "b456fd404954a9e13f55aa0c88cd5a40b8399638",
"version" : "2.6.3"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
<key>ClopCLI-setapp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>2</integer>
</dict>
<key>ClopCLI.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>5</integer>
</dict>
<key>Example (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>13</integer>
<integer>10</integer>
</dict>
<key>Example (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>14</integer>
<integer>11</integer>
</dict>
<key>Example (Playground) 3.xcscheme</key>
<dict>
Expand Down Expand Up @@ -85,7 +85,7 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>9</integer>
<integer>6</integer>
</dict>
<key>FinderOptimiser copy.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -112,14 +112,14 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>11</integer>
<integer>8</integer>
</dict>
<key>SwiftDate (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>12</integer>
<integer>9</integer>
</dict>
<key>SwiftDate (Playground) 3.xcscheme</key>
<dict>
Expand Down Expand Up @@ -168,7 +168,7 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
<integer>7</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
50 changes: 42 additions & 8 deletions Clop/ClopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,10 @@ class AppDelegate: AppDelegateParent {
shouldHandle: shouldHandleVideo(event:),
cancel: cancelVideoOptimisation(path:)
) { event in
let video = Video(path: FilePath(event.path))
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

let video = Video(path: FilePath(event.path))
try? await optimiseVideo(video, debounceMS: debounceMS, source: Defaults[.videoDirs].filter { event.path.starts(with: $0) }.max(by: \.count))
}
}
Expand All @@ -690,8 +692,10 @@ class AppDelegate: AppDelegateParent {
shouldHandle: shouldHandleImage(event:),
cancel: cancelImageOptimisation(path:)
) { event in
guard let img = Image(path: FilePath(event.path), retinaDownscaled: false) else { return }
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

guard let img = Image(path: FilePath(event.path), retinaDownscaled: false) else { return }
try? await optimiseImage(img, debounceMS: debounceMS, source: Defaults[.imageDirs].filter { event.path.starts(with: $0) }.max(by: \.count))
}
}
Expand All @@ -703,8 +707,10 @@ class AppDelegate: AppDelegateParent {
shouldHandle: shouldHandlePDF(event:),
cancel: cancelPDFOptimisation(path:)
) { event in
guard let path = event.path.existingFilePath else { return }
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

guard let path = event.path.existingFilePath else { return }
try? await optimisePDF(PDF(path), debounceMS: debounceMS, source: Defaults[.pdfDirs].filter { event.path.starts(with: $0) }.max(by: \.count))
}
}
Expand Down Expand Up @@ -1012,6 +1018,38 @@ class FileOptimisationWatcher {
watching = true
}

static func waitForModificationDateToSettle(_ path: String) async {
guard let attrs = try? fm.attributesOfItem(atPath: path), let date = attrs[.modificationDate] as? Date else {
log.warning("Failed to get modification date of \(path)")
return
}

log.debug("Waiting for modification date of \(path) to settle")
log.debug("Initial modification date: \(date)")
var lastDate = date
while true {
do {
try await Task.sleep(nanoseconds: 300_000_000) // 300ms
} catch {
log.error("Failed to sleep: \(error)")
return
}

guard let attrs = try? fm.attributesOfItem(atPath: path), let date = attrs[.modificationDate] as? Date else {
log.warning("Failed to get modification date of \(path)")
return
}

guard date != lastDate else {
log.debug("Modification date of \(path) settled at \(date)")
return
}

log.debug("Modification date of \(path) is still changing: \(lastDate) -> \(date)")
lastDate = date
}
}

func hasSpuriousEvent(_ event: EonilFSEventsEvent) -> Bool {
guard withinSafeMeasureTime, !justAddedFiles.isEmpty else {
return false
Expand Down Expand Up @@ -1108,11 +1146,7 @@ class FileOptimisationWatcher {
@MainActor func proLimitsReached(url: URL? = nil) {}
#endif

#if DEBUG
let floatingResultsWindow = OSDWindow(swiftuiView: FloatingResultContainer().any, level: .floating, canScreenshot: true, allowsMouse: true)
#else
let floatingResultsWindow = OSDWindow(swiftuiView: FloatingResultContainer().any, level: .floating, canScreenshot: false, allowsMouse: true)
#endif
let floatingResultsWindow = OSDWindow(swiftuiView: FloatingResultContainer().any, level: .floating, canScreenshot: Defaults[.allowClopToAppearInScreenshots], allowsMouse: true)
var clipboardWatcher: Timer?
var pbChangeCount = NSPasteboard.general.changeCount
let THUMB_SIZE = CGSize(width: 300, height: 220)
Expand Down
Loading

0 comments on commit ee834c3

Please sign in to comment.