Skip to content

Commit

Permalink
Pause automatic optimisations and floating update button
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Oct 11, 2023
1 parent 5d41a03 commit 7be495a
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 6 deletions.
29 changes: 27 additions & 2 deletions Clop/ClopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class AppDelegate: LowtechProAppDelegate {
}

override func applicationDidFinishLaunching(_ notification: Notification) {
UM.newVersion = "2.2.2"

if !SWIFTUI_PREVIEW {
handleCLIInstall()
unarchiveBinaries()
Expand Down Expand Up @@ -449,6 +451,15 @@ class AppDelegate: LowtechProAppDelegate {
}
}
.store(in: &observers)
pub(.pauseAutomaticOptimisations)
.sink { paused in
if paused.newValue {
clipboardWatcher?.invalidate()
} else {
self.initClipboardOptimiser()
}
}
.store(in: &observers)
initMachPortListener()

#if !DEBUG
Expand Down Expand Up @@ -551,7 +562,7 @@ class AppDelegate: LowtechProAppDelegate {
}
}

if Defaults[.enableClipboardOptimiser] {
if Defaults[.enableClipboardOptimiser], !Defaults[.pauseAutomaticOptimisations] {
initClipboardOptimiser()
}

Expand Down Expand Up @@ -637,10 +648,24 @@ class FileOptimisationWatcher {
self?.paths = change.newValue
self?.startWatching()
}.store(in: &observers)

pub(maxFilesToHandleKey).sink { [weak self] change in
self?.maxFilesToHandle = change.newValue
}.store(in: &observers)

pub(.pauseAutomaticOptimisations).sink { [weak self] change in
guard let self else { return }

if change.newValue {
if watching {
EonilFSEvents.stopWatching(for: ObjectIdentifier(self))
watching = false
}
} else {
startWatching()
}
}.store(in: &observers)

startWatching()
}

Expand Down Expand Up @@ -688,7 +713,7 @@ class FileOptimisationWatcher {
watching = false
}

guard !paths.isEmpty else { return }
guard !paths.isEmpty, !Defaults[.pauseAutomaticOptimisations] else { return }

try! EonilFSEvents.startWatching(paths: paths, for: ObjectIdentifier(self)) { event in
guard !SWIFTUI_PREVIEW else { return }
Expand Down
11 changes: 11 additions & 0 deletions Clop/CompactResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ struct CompactResultList: View {
VStack(alignment: isTrailing ? .trailing : .leading, spacing: 5) {
FlipGroup(if: floatingResultsCorner.isTop) {
HStack {
if floatingResultsCorner.isTrailing {
UpdateButton(short: !showCompactImages)
Spacer()
}

if hasRunningOptimisers {
Button("Stop all") {
OM.optimisers.filter(\.running).forEach { optimiser in
Expand All @@ -328,11 +333,17 @@ struct CompactResultList: View {
OM.clearVisibleOptimisers(stop: true)
}
.help("Stop all running optimisations and dismiss all results (\(keyComboModifiers.str) esc)")

if !floatingResultsCorner.isTrailing {
Spacer()
UpdateButton(short: !showCompactImages)
}
}
.buttonStyle(FlatButton(color: .inverted.opacity(0.9), textColor: .mauvish, radius: 7, verticalPadding: 2))
.font(.medium(11))
.opacity(hovering && showList ? 1 : 0)
.focusable(false)
.frame(width: size.width, alignment: floatingResultsCorner.isTrailing ? .trailing : .leading)

let opts: [(opt: Optimiser, isLast: Bool, isEven: Bool)] = optimisers.isEmpty
? []
Expand Down
4 changes: 3 additions & 1 deletion Clop/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct MenuView: View {
@Default(.useAggresiveOptimisationPNG) var useAggresiveOptimisationPNG
@Default(.useAggresiveOptimisationMP4) var useAggresiveOptimisationMP4
@Default(.cliInstalled) var cliInstalled
@Default(.pauseAutomaticOptimisations) var pauseAutomaticOptimisations

@State var cliInstallResult: String?

Expand Down Expand Up @@ -103,6 +104,7 @@ struct MenuView: View {
}

Section("Automation") {
Toggle("Pause automatic optimisations", isOn: $pauseAutomaticOptimisations)
if !cliInstalled {
Button("Install command-line integration") {
do {
Expand Down Expand Up @@ -145,7 +147,7 @@ struct MenuView: View {
focus()
}

Button(um.newVersion != nil ? "v\(um.newVersion!) available" : "Check for updates") {
Button(um.newVersion != nil ? "v\(um.newVersion!) update available" : "Check for updates") {
checkForUpdates()
}
Button("Quit") {
Expand Down
37 changes: 35 additions & 2 deletions Clop/FloatingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Defaults
import Lowtech
import LowtechIndie
import LowtechPro
import SwiftUI

Expand Down Expand Up @@ -61,6 +62,26 @@ struct FloatingResultList: View {
}
}
}

struct UpdateButton: View {
var short = false
@ObservedObject var um: UpdateManager = UM
@State var hovering = false

var body: some View {
if let updateVersion = um.newVersion {
Button(short ? "v\(updateVersion) available" : "v\(updateVersion) update available") {
checkForUpdates()
}
.buttonStyle(FlatButton(color: .inverted.opacity(0.9), textColor: .mauvish, radius: 7, verticalPadding: 2))
.font(.medium(11))
.opacity(hovering ? 1 : 0.5)
.focusable(false)
.onHover { hovering = $0 }
}
}
}

struct FloatingResultContainer: View {
@ObservedObject var om = OM
@ObservedObject var dragManager = DM
Expand All @@ -72,8 +93,18 @@ struct FloatingResultContainer: View {
var body: some View {
let optimisers = om.optimisers.filter(!\.hidden).sorted(by: \.startedAt, order: .reverse)
VStack(alignment: floatingResultsCorner.isTrailing ? .trailing : .leading, spacing: 10) {
if !isPreview, dragManager.dragging, floatingResultsCorner.isTop {
DropZoneView()
.transition(
.asymmetric(insertion: .scale.animation(.fastSpring), removal: .identity)
)
.padding(.bottom, 10)
}

if optimisers.isNotEmpty {
if (alwaysShowCompactResults && !isPreview) || optimisers.count > 5 || om.compactResults {
let compact = (alwaysShowCompactResults && !isPreview) || optimisers.count > 5 || om.compactResults

if compact {
CompactResultList(optimisers: optimisers, progress: om.progress, doneCount: om.doneCount, failedCount: om.failedCount, visibleCount: om.visibleCount).preview(isPreview)
.padding(.horizontal, 10)
.padding(.vertical, 15)
Expand All @@ -82,10 +113,12 @@ struct FloatingResultContainer: View {
}
} else {
FloatingResultList(optimisers: optimisers).preview(isPreview)
UpdateButton().padding(floatingResultsCorner.isTrailing ? .trailing : .leading, 54)
}

}

if !isPreview, dragManager.dragging {
if !isPreview, dragManager.dragging, !floatingResultsCorner.isTop {
DropZoneView()
.transition(
.asymmetric(insertion: .scale.animation(.fastSpring), removal: .identity)
Expand Down
2 changes: 2 additions & 0 deletions Clop/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ extension Defaults.Keys {
static let enabledKeys = Key<[SauceKey]>("enabledKeys", default: DEFAULT_GLOBAL_KEYS)

static let savedCropSizes = Key<[CropSize]>("savedCropSizes", default: DEFAULT_CROP_SIZES)
static let pauseAutomaticOptimisations = Key<Bool>("pauseAutomaticOptimisations", default: false)

static let syncSettingsCloud = Key<Bool>("syncSettingsCloud", default: true)
}
Expand Down Expand Up @@ -162,6 +163,7 @@ let SETTINGS_TO_SYNC: [Defaults._AnyKey] = [
.optimiseVideoClipboard,
.pdfDirs,
.quickResizeKeys,
.savedCropSizes,
.shortcutToRunOnImage,
.shortcutToRunOnVideo,
.shortcutToRunOnPdf,
Expand Down
2 changes: 1 addition & 1 deletion Clop/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct DirListView: View {
`*.jpg`
` `
`# Ignore all folders and subfolders (like a non-recursive option)`
`*/`
`*/*`
` `
`# Exclude all files in a "DontOptimise" directory`
`DontOptimise/`
Expand Down
5 changes: 5 additions & 0 deletions ReleaseNotes/2.2.2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Features

* Add **Pause automatic optimisations** option in the menubar
* Add support for `--long-edge` flag to `clop crop` command

```bash
Expand All @@ -9,6 +10,10 @@
Example: `clop crop --long-edge --size 1920` will crop a landscape 2400x1350 image to 1920x1080, and a portrait 1350x2400 image to 1080x1920
```
## Improvements
* Show when an update is available as a subtle button below the floating results
## Fixes
- Fix downscaling and cropping on Intel
Expand Down

0 comments on commit 7be495a

Please sign in to comment.