From df2c5e7d017f59ec2e269b592b30116636f3149e Mon Sep 17 00:00:00 2001 From: Alin Panaitiu Date: Thu, 25 Jul 2024 23:49:53 +0300 Subject: [PATCH] Allow pausing/stopping auto optimisations with the P hotkey --- Clop/ClopApp.swift | 31 +++++++++++++++++++++++++++++-- Clop/SettingsView.swift | 2 +- ReleaseNotes/2.6.0.md | 4 ++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Clop/ClopApp.swift b/Clop/ClopApp.swift index ef92e42..aee3a4b 100644 --- a/Clop/ClopApp.swift +++ b/Clop/ClopApp.swift @@ -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: @@ -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)) } @@ -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)) } @@ -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)) } diff --git a/Clop/SettingsView.swift b/Clop/SettingsView.swift index fa33550..9a510f2 100644 --- a/Clop/SettingsView.swift +++ b/Clop/SettingsView.swift @@ -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) diff --git a/ReleaseNotes/2.6.0.md b/ReleaseNotes/2.6.0.md index 6d93868..2a19f5e 100644 --- a/ReleaseNotes/2.6.0.md +++ b/ReleaseNotes/2.6.0.md @@ -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