Skip to content

Commit

Permalink
Allow pausing/stopping auto optimisations with the P hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Jul 25, 2024
1 parent 5627853 commit df2c5e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
31 changes: 29 additions & 2 deletions Clop/ClopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,17 @@ class AppDelegate: AppDelegateParent {
opt.restoreOriginal()
}
case .p:
pauseForNextClipboardEvent = true
showNotice("**Paused**\nNext clipboard event will be ignored")
if Defaults[.pauseAutomaticOptimisations] {
Defaults[.pauseAutomaticOptimisations] = false
pauseForNextClipboardEvent = false
showNotice("**Running** • Paused • Stopped\nClop is listening for clipboard and file events")
} else if pauseForNextClipboardEvent {
Defaults[.pauseAutomaticOptimisations] = true
showNotice("Running • Paused • **Stopped**\nAll automatic optimisations are stopped")
} else {
pauseForNextClipboardEvent = true
showNotice("Running • **Paused** • Stopped\nNext clipboard event will be ignored")
}
case .c:
Task.init { try? await optimiseLastClipboardItem() }
case .a:
Expand Down Expand Up @@ -696,6 +705,12 @@ class AppDelegate: AppDelegateParent {
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

if pauseForNextClipboardEvent {
log.debug("Skipping video \(event.path) because Clop was paused")
pauseForNextClipboardEvent = false
return
}

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 @@ -711,6 +726,12 @@ class AppDelegate: AppDelegateParent {
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

if pauseForNextClipboardEvent {
log.debug("Skipping image \(event.path) because Clop was paused")
pauseForNextClipboardEvent = false
return
}

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 @@ -726,6 +747,12 @@ class AppDelegate: AppDelegateParent {
Task.init {
await FileOptimisationWatcher.waitForModificationDateToSettle(event.path)

if pauseForNextClipboardEvent {
log.debug("Skipping PDF \(event.path) because Clop was paused")
pauseForNextClipboardEvent = false
return
}

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
2 changes: 1 addition & 1 deletion Clop/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ struct KeysSettingsView: View {
keyToggle(.space, actionName: "QuickLook", description: "Preview the latest image or video")
keyToggle(.r, actionName: "Rename", description: "Rename the file of the latest image or video")
keyToggle(.z, actionName: "Restore original", description: "Revert optimisations and downscaling actions done on the latest image or video")
keyToggle(.p, actionName: "Pause for next copy", description: "Don't apply optimisations on the next copied image")
keyToggle(.p, actionName: "Pause optimisations", description: "Pause or stop automatic optimisations")
keyToggle(.c, actionName: "Optimise current clipboard", description: "Apply optimisations on the copied image, URL or path")
keyToggle(.a, actionName: "Optimise aggressively", description: "Apply aggressive optimisations on the copied image, URL or path")
}.padding(.leading, 20)
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes/2.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- Update `ffmpeg` to version 7.0
- Allow configuring the location where Clop stores temporary files and backups and when to clean up files
- Allow disabling floating results UI
- The global `Ctrl-Shift-P` hotkey can now toggle between:
- **Running**: Clop is listening to clipboard and file events
- **Paused**: Clop is paused for the next clipboard/file event and will resume automatically
- **Stopped**: All automatic optimisations are stopped until manually resumed by user

## Improvements

Expand Down

0 comments on commit df2c5e7

Please sign in to comment.