Skip to content

Commit

Permalink
Stop file size estimation when starting the conversion
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
sindresorhus committed Jan 25, 2021
1 parent cf635ab commit 03b2f19
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Gifski/ConversionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ final class ConversionViewController: NSViewController {

stopConversion { [weak self] in
// It's safe to force-unwrap as there's no scenario where it will be nil.
self?.push(viewController: AppDelegate.shared.previousEditViewController!)
let viewController = AppDelegate.shared.previousEditViewController!
viewController.isConverting = false

self?.push(viewController: viewController)
}
}

Expand Down
24 changes: 23 additions & 1 deletion Gifski/EditVideoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ final class EditVideoViewController: NSViewController {
AppDelegate.shared.previousEditViewController = self
}

var isConverting = false

@IBAction
private func convert(_ sender: Any) {
isConverting = true

cancelFileSizeEstimation()

let convert = ConversionViewController(conversion: conversionSettings)
push(viewController: convert)
}
Expand Down Expand Up @@ -476,9 +482,25 @@ final class EditVideoViewController: NSViewController {
return formatter.string(fromByteCount: Int64(fileSize))
}

private func _estimateFileSize() {
private func cancelFileSizeEstimation() {
// TODO: Deinit doesn't seem to be called.
self.gifski?.cancel()
self.gifski = nil

if estimatedSizeLabel.stringValue.contains("Calculating") {
setEstimatedFileSize(getNaiveEstimate().attributedString)
}
}

private func _estimateFileSize() {
self.gifski?.cancel()
self.gifski = nil

setEstimatedFileSize(getNaiveEstimate().attributedString)

guard !isConverting else {
return
}

let gifski = Gifski()
self.gifski = gifski
Expand Down
2 changes: 1 addition & 1 deletion Gifski/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class MainWindowController: NSWindowController {
message: "Feedback Welcome 🙌🏻",
informativeText:
"""
If you have any feedback, bug report, or feature request, there's a feedback button in the “Help” menu. We respond to all submissions.
If you have any feedback, bug reports, or feature requests, there's a feedback button in the “Help” menu. We respond to all submissions.
""",
buttonTitles: [
"Get Started"
Expand Down

0 comments on commit 03b2f19

Please # to comment.