Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 6, 2023
1 parent 052e4ab commit e30362b
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 86 deletions.
8 changes: 5 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
only_rules:
- accessibility_trait_for_button
- array_init
- blanket_disable_command
- block_based_kvo
- class_delegate_protocol
- closing_brace
Expand All @@ -21,13 +22,15 @@ only_rules:
- control_statement
- custom_rules
- deployment_target
- direct_return
- discarded_notification_center_observer
- discouraged_assert
- discouraged_direct_init
- discouraged_none_name
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- duplicate_conditions
- duplicate_enum_cases
- duplicate_imports
- duplicated_key_in_dictionary_literal
Expand All @@ -53,7 +56,7 @@ only_rules:
- implicit_getter
- implicit_return
- inclusive_language
- inert_defer
- invalid_swiftlint_command
- is_disjoint
- joined_default_parameter
- last_where
Expand Down Expand Up @@ -132,7 +135,6 @@ only_rules:
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
Expand Down Expand Up @@ -178,7 +180,7 @@ identifier_name:
- 'y2'
- 'z2'
deployment_target:
macOS_deployment_target: '11'
macOS_deployment_target: '12'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
Expand Down
9 changes: 5 additions & 4 deletions Gifski.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@
E3AE627B1E5CD2F300035A2F /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1400;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "Sindre Sorhus";
TargetAttributes = {
0E79251A2329BDBE00058B94 = {
Expand Down Expand Up @@ -808,7 +809,7 @@
repositoryURL = "https://github.com/sindresorhus/Defaults";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.1.0;
minimumVersion = 7.2.0;
};
};
E3339E982395768F00303839 /* XCRemoteSwiftPackageReference "CircularProgress" */ = {
Expand All @@ -824,15 +825,15 @@
repositoryURL = "https://github.com/sindresorhus/DockProgress";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.0.1;
minimumVersion = 4.1.0;
};
};
E3C874A8252CFE5B00AB1099 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 10.5.0;
minimumVersion = 10.9.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
2 changes: 1 addition & 1 deletion Gifski.xcodeproj/xcshareddata/xcschemes/Gifski.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1430"
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 5 additions & 3 deletions Gifski/ConversionCompletedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ final class ConversionCompletedViewController: NSViewController {
setUpDropView()
setUp()

NSApp.requestUserAttention(.informationalRequest)

if !NSApp.isActive || view.window?.isVisible == false {
let notification = UNMutableNotificationContent()
notification.title = "Conversion Completed"
Expand Down Expand Up @@ -71,7 +73,7 @@ final class ConversionCompletedViewController: NSViewController {
return
}

self.tooltip.show(from: self.draggableFile, preferredEdge: .maxY)
tooltip.show(from: draggableFile, preferredEdge: .maxY)
}

SSApp.requestReviewAfterBeingCalledThisManyTimes([5, 100, 1000])
Expand Down Expand Up @@ -156,8 +158,8 @@ final class ConversionCompletedViewController: NSViewController {
return
}

self.copyButton.title = "Copy"
self.copyButton.isEnabled = true
copyButton.title = "Copy"
copyButton.isEnabled = true
}
}

Expand Down
72 changes: 36 additions & 36 deletions Gifski/EditVideoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,24 @@ final class EditVideoViewController: NSViewController {
return
}

let oldOrNewSelectedIndex = selectedIndex ?? self.predefinedSizesDropdown.indexOfSelectedItem
let oldOrNewSelectedIndex = selectedIndex ?? predefinedSizesDropdown.indexOfSelectedItem

if
let size = self.predefinedSizes?[safe: oldOrNewSelectedIndex],
let size = predefinedSizes?[safe: oldOrNewSelectedIndex],
case .custom = size
{
// We don't care if it's newly selected index or not, if it's custom, set its size
self.updateSelectedItemAsCustomWithSize()
updateSelectedItemAsCustomWithSize()
} else if
let selectedIndex,
let size = self.predefinedSizes?[safe: selectedIndex],
let size = predefinedSizes?[safe: selectedIndex],
case .dimensions(let dimensions) = size
{
// But we care if it's newly selected index for dimensions, we don't want to recalculate
// if we don't have to
self.resizableDimensions.change(dimensionsType: dimensions.currentDimensions.type)
self.resizableDimensions.resize(to: dimensions.currentDimensions.value)
self.dimensionsUpdated()
resizableDimensions.change(dimensionsType: dimensions.currentDimensions.type)
resizableDimensions.resize(to: dimensions.currentDimensions.value)
dimensionsUpdated()
}
}

Expand All @@ -290,15 +290,15 @@ final class EditVideoViewController: NSViewController {
guard
let self,
let selectedIndex,
let item = self.dimensionsTypeDropdown.item(at: selectedIndex),
let item = dimensionsTypeDropdown.item(at: selectedIndex),
let dimensionsType = DimensionsType(rawValue: item.title)
else {
return
}

self.resizableDimensions.change(dimensionsType: dimensionsType)
self.dimensionsUpdated()
self.updateTextFieldsMinMax()
resizableDimensions.change(dimensionsType: dimensionsType)
dimensionsUpdated()
updateTextFieldsMinMax()
}

if resizableDimensions.currentDimensions.value.width > 640 {
Expand All @@ -316,19 +316,19 @@ final class EditVideoViewController: NSViewController {
return
}

let frameRate = self.frameRateSlider.integerValue
let frameRate = frameRateSlider.integerValue
Defaults[.outputFPS] = frameRate
self.frameRateLabel.stringValue = "\(frameRate)"
self.estimatedFileSizeModel.updateEstimate()
frameRateLabel.stringValue = "\(frameRate)"
estimatedFileSizeModel.updateEstimate()
}

qualitySlider.onAction = { [weak self] _ in
guard let self else {
return
}

Defaults[.outputQuality] = self.qualitySlider.doubleValue
self.estimatedFileSizeModel.updateEstimate()
Defaults[.outputQuality] = qualitySlider.doubleValue
estimatedFileSizeModel.updateEstimate()
}

// We round it so that `29.970` becomes `30` for practical reasons.
Expand Down Expand Up @@ -416,7 +416,7 @@ final class EditVideoViewController: NSViewController {
)

alert.showsSuppressionButton = true
alert.runModal(for: self.view.window)
alert.runModal(for: view.window)

if alert.suppressionButton?.state == .on {
Defaults[.suppressKeyframeWarning] = true
Expand All @@ -436,8 +436,8 @@ final class EditVideoViewController: NSViewController {
return
}

self.resizableDimensions.resize(usingWidth: Double(width))
self.dimensionsUpdated()
resizableDimensions.resize(usingWidth: Double(width))
dimensionsUpdated()
}

heightTextField.onBlur = { [weak self] height in
Expand All @@ -450,8 +450,8 @@ final class EditVideoViewController: NSViewController {
return
}

self.resizableDimensions.resize(usingHeight: Double(height))
self.dimensionsUpdated()
resizableDimensions.resize(usingHeight: Double(height))
dimensionsUpdated()
}

updateTextFieldsMinMax()
Expand All @@ -463,11 +463,11 @@ final class EditVideoViewController: NSViewController {
return
}

self.loopCountTextField.stringValue = "\(loopCount)"
self.loopCountStepper.intValue = Int32(loopCount)
loopCountTextField.stringValue = "\(loopCount)"
loopCountStepper.intValue = Int32(loopCount)

if loopCount > 0 {
self.loopCheckbox.state = .off
loopCheckbox.state = .off
}
}

Expand All @@ -477,11 +477,11 @@ final class EditVideoViewController: NSViewController {
}

let validLoopCount = loopCount.clamped(to: Constants.loopCountRange)
self.loopCountTextField.stringValue = "\(validLoopCount)"
self.loopCountStepper.intValue = Int32(validLoopCount)
loopCountTextField.stringValue = "\(validLoopCount)"
loopCountStepper.intValue = Int32(validLoopCount)

if validLoopCount > 0 {
self.loopCheckbox.state = .off
loopCheckbox.state = .off
}
}

Expand All @@ -490,11 +490,11 @@ final class EditVideoViewController: NSViewController {
return
}

if self.loopCheckbox.state == .on {
self.loopCountTextField.stringValue = "0"
self.loopCountStepper.intValue = 0
if loopCheckbox.state == .on {
loopCountTextField.stringValue = "0"
loopCountStepper.intValue = 0
} else {
self.showConversionCompletedAnimationWarningIfNeeded()
showConversionCompletedAnimationWarningIfNeeded()
}
}

Expand All @@ -514,10 +514,10 @@ final class EditVideoViewController: NSViewController {
return
}

self.modifiedAsset = self.asset?.firstVideoTrack?.extractToNewAssetAndChangeSpeed(to: $0.newValue)
self.playerViewController.currentItem = AVPlayerItem(asset: self.modifiedAsset)
self.estimatedFileSizeModel.updateEstimate()
self.updateFrameRateSlider(isInit: false)
modifiedAsset = asset?.firstVideoTrack?.extractToNewAssetAndChangeSpeed(to: $0.newValue)
playerViewController.currentItem = AVPlayerItem(asset: modifiedAsset)
estimatedFileSizeModel.updateEstimate()
updateFrameRateSlider(isInit: false)
}
.store(in: &cancellables)

Expand All @@ -527,7 +527,7 @@ final class EditVideoViewController: NSViewController {
return
}

self.loopCountTextField.stringValue = "\(self.loopCountStepper.intValue)"
loopCountTextField.stringValue = "\(loopCountStepper.intValue)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions Gifski/EstimatedFileSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ final class EstimatedFileSizeModel: ObservableObject {
// We add 10% extra because it's better to estimate slightly too much than too little.
let fileSize = (Double(data.count) * gifski.sizeMultiplierForEstimation) * 1.1

self.estimatedFileSize = Int(fileSize).formatted(.byteCount(style: .file))
estimatedFileSize = Int(fileSize).formatted(.byteCount(style: .file))
case .failure(let error):
switch error {
case .cancelled:
break
case .notEnoughFrames:
self.estimatedFileSize = self.estimatedFileSizeNaive
estimatedFileSize = estimatedFileSizeNaive
default:
Crashlytics.recordNonFatalError(error: error)
self.error = error
Expand Down
8 changes: 2 additions & 6 deletions Gifski/ExtendedAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class ExtendedAttributes {
func all() throws -> [String] {
try checkIfFileURL()

let list: [String] = try url.withUnsafeFileSystemRepresentation { fileSystemPath in
return try url.withUnsafeFileSystemRepresentation { fileSystemPath in
let length = listxattr(fileSystemPath, nil, 0, 0)

guard length >= 0 else {
Expand All @@ -127,14 +127,10 @@ final class ExtendedAttributes {
throw System.Errno.fromErrno
}

let list = data.split(separator: 0).compactMap {
return data.split(separator: 0).compactMap {
String(data: Data($0), encoding: .utf8)
}

return list
}

return list
}

func debug() {
Expand Down
8 changes: 4 additions & 4 deletions Gifski/GIFGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ final class GIFGenerator {
}
}

self.gifski = Gifski(
gifski = Gifski(
dimensions: conversion.dimensions,
quality: conversion.quality,
loop: conversion.loop
)

self.gifski?.onProgress = { [weak self] in
gifski?.onProgress = { [weak self] in
self?.progress.completedUnitCount += 1
}

Expand Down Expand Up @@ -123,7 +123,7 @@ final class GIFGenerator {
return
}

let frameResult = self.processFrame(
let frameResult = processFrame(
for: imageResult,
at: startTime,
frameRate: fps,
Expand All @@ -135,7 +135,7 @@ final class GIFGenerator {
switch frameResult {
case .success(let finished):
if finished {
guard let gifski = self.gifski else {
guard let gifski else {
completionHandler(.failure(.cancelled))
return
}
Expand Down
4 changes: 2 additions & 2 deletions Gifski/Gifski.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class Gifski {
return 0
}

self.onProgress?()
onProgress?()

return self.wrapper == nil ? 0 : 1
}
Expand All @@ -69,7 +69,7 @@ final class Gifski {
return 0
}

self.data.append(bufferPointer, count: bufferLength)
data.append(bufferPointer, count: bufferLength)

return 0
}
Expand Down

0 comments on commit e30362b

Please sign in to comment.