Skip to content

Commit

Permalink
Clean up #57 and some other things
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 10, 2019
1 parent c061dfa commit bb54fbb
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 58 deletions.
14 changes: 8 additions & 6 deletions Gifski.xcodeproj/project.pbxproj
Expand Up @@ -70,8 +70,8 @@

/* Begin PBXFileReference section */
5A7524AD20D085FB00F12C99 /* gifski.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = gifski.xcodeproj; path = "gifski-api/gifski.xcodeproj"; sourceTree = "<group>"; };
6D86841121FD283B0044F6FE /* ConversionCompletedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversionCompletedView.swift; sourceTree = "<group>"; };
6D86841621FD283B0044F6FE /* DraggableFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DraggableFile.swift; sourceTree = "<group>"; };
6D86841121FD283B0044F6FE /* ConversionCompletedView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ConversionCompletedView.swift; sourceTree = "<group>"; usesTabs = 1; };
6D86841621FD283B0044F6FE /* DraggableFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = DraggableFile.swift; sourceTree = "<group>"; usesTabs = 1; };
B576D24F22294F9900A9B75C /* CircularProgress+Util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "CircularProgress+Util.swift"; sourceTree = "<group>"; usesTabs = 1; };
C2040B8820435871004EE259 /* GifskiWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = GifskiWrapper.swift; sourceTree = "<group>"; usesTabs = 1; };
C2AFA91B204FFEFD00FC5A7F /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MainWindowController.swift; sourceTree = "<group>"; usesTabs = 1; };
Expand Down Expand Up @@ -178,13 +178,13 @@
E3AE62851E5CD2F300035A2F /* Gifski */ = {
isa = PBXGroup;
children = (
6D86841121FD283B0044F6FE /* ConversionCompletedView.swift */,
6D86841621FD283B0044F6FE /* DraggableFile.swift */,
E3AE62861E5CD2F300035A2F /* AppDelegate.swift */,
C2AFA91B204FFEFD00FC5A7F /* MainWindowController.swift */,
E3DF3E86203BD2B900055855 /* SavePanelAccessoryViewController.swift */,
E3DF3E87203BD2B900055855 /* SavePanelAccessoryViewController.xib */,
E3CB1DD61F7E4CBC00D79BFC /* VideoDropView.swift */,
6D86841621FD283B0044F6FE /* DraggableFile.swift */,
6D86841121FD283B0044F6FE /* ConversionCompletedView.swift */,
E339F010203820ED003B78FB /* Gifski.swift */,
C2040B8820435871004EE259 /* GifskiWrapper.swift */,
E3A940112182DCE5006981D5 /* CustomButton.swift */,
Expand Down Expand Up @@ -233,7 +233,6 @@
E3AE62821E5CD2F300035A2F = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.HardenedRuntime = {
enabled = 1;
Expand All @@ -250,7 +249,6 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = E3AE627A1E5CD2F300035A2F;
Expand Down Expand Up @@ -498,6 +496,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Gifski/Gifski.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -518,6 +517,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.Gifski;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OBJC_BRIDGING_HEADER = "Gifski/Gifski-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -533,6 +533,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Gifski/Gifski.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -553,6 +554,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.sindresorhus.Gifski;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Gifski/Gifski-Bridging-Header.h";
SWIFT_VERSION = 4.2;
USER_HEADER_SEARCH_PATHS = "";
Expand Down
6 changes: 3 additions & 3 deletions Gifski/AppDelegate.swift
Expand Up @@ -25,7 +25,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ notification: Notification) {
#if !DEBUG
Fabric.with([Crashlytics.self])
Fabric.with([Crashlytics.self])
#endif

mainWindowController.showWindow(self)
Expand Down Expand Up @@ -54,7 +54,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

let videoUrl = urls.first!

/// TODO: Simplify this. Make a function that calls the input when the app finished launching, or right away if it already has.
// TODO: Simplify this. Make a function that calls the input when the app finished launching, or right away if it already has.
if hasFinishedLaunching {
mainWindowController.convert(videoUrl)
} else {
Expand All @@ -70,7 +70,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

func application(_ application: NSApplication, willPresentError error: Error) -> Error {
#if !DEBUG
Crashlytics.sharedInstance().recordError(error)
Crashlytics.sharedInstance().recordError(error)
#endif

return error
Expand Down
6 changes: 4 additions & 2 deletions Gifski/ConversionCompletedView.swift
Expand Up @@ -46,14 +46,16 @@ final class ConversionCompletedView: SSView {
let url = fileUrl!
draggableFile.fileUrl = url
fileNameLabel.text = url.lastPathComponent
fileSizeLabel.text = url.formattedFileSize()
fileSizeLabel.text = url.fileSizeFormatted

showInFinderButton.onAction = { _ in
NSWorkspace.shared.activateFileViewerSelecting([url])
}

// TODO: CustomButton doesn't correctly respect `.sendAction()`
shareButton.sendAction(on: .leftMouseDown)
shareButton.onAction = { _ in
NSSharingService.shareContent(content: [url] as [AnyObject], button: self.shareButton)
NSSharingService.share(content: [url] as [AnyObject], from: self.shareButton)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gifski/CustomButton.swift
Expand Up @@ -232,7 +232,7 @@ open class CustomButton: NSButton {
/// Gets or sets the color generation closure for the provided key path.
///
/// - Parameter keyPath: The key path that specifies the color related property.
subscript (colorGenerator keyPath: KeyPath<CustomButton, NSColor>) -> ColorGenerator? {
subscript(colorGenerator keyPath: KeyPath<CustomButton, NSColor>) -> ColorGenerator? {
get {
return colorGenerators[keyPath]
}
Expand Down
16 changes: 7 additions & 9 deletions Gifski/DraggableFile.swift
Expand Up @@ -11,30 +11,28 @@ final class DraggableFile: NSImageView {
heightConstraint.constant = image!.size.maxSize(size: 96).height
updateConstraints()

self.layer?.animateScaleMove(fromScale: 3.0, fromY: superview!.superview!.frame.height + frame.size.height)
layer?.animateScaleMove(fromScale: 3, fromY: superview!.superview!.frame.height + frame.size.height)
}
}

override init(frame: CGRect) {
super.init(frame: frame)
heightConstraint = heightAnchor.constraint(equalToConstant: 0)

wantsLayer = true

isEditable = false
unregisterDraggedTypes()

wantsLayer = true

self.heightConstraint = heightAnchor.constraint(equalToConstant: 0)
NSLayoutConstraint.activate([
heightConstraint
])

let sh = with(NSShadow()) {
$0.shadowBlurRadius = 5.0
$0.shadowColor = NSColor(named: NSColor.Name("ShadowColor"))
shadow = with(NSShadow()) {
$0.shadowBlurRadius = 5
$0.shadowColor = NSColor(named: "ShadowColor")
$0.shadowOffset = CGSize(width: 0, height: 0)
}

shadow = sh
}

@available(*, unavailable)
Expand Down
12 changes: 6 additions & 6 deletions Gifski/Gifski.swift
Expand Up @@ -14,13 +14,13 @@ final class Gifski {
switch self {
case .invalidSettings:
return "Invalid settings"
case .generateFrameFailed(let error):
case let .generateFrameFailed(error):
return "Failed to generate frame: \(error.localizedDescription)"
case .addFrameFailed(let error):
case let .addFrameFailed(error):
return "Failed to add frame, with underlying error: \(error.localizedDescription)"
case .endAddingFramesFailed(let error):
case let .endAddingFramesFailed(error):
return "Failed to end adding frames, with underlying error: \(error.localizedDescription)"
case .writeFailed(let error):
case let .writeFailed(error):
return "Failed to write to output, with underlying error: \(error.localizedDescription)"
case .cancelled:
return "The conversion was cancelled"
Expand Down Expand Up @@ -110,7 +110,7 @@ final class Gifski {
}

switch result {
case .success(let result):
case let .success(result):
let image = result.image

guard
Expand Down Expand Up @@ -144,7 +144,7 @@ final class Gifski {
}
case .failure where result.isCancelled:
completionHandlerOnce(.cancelled)
case .failure(let error):
case let .failure(error):
completionHandlerOnce(.generateFrameFailed(error))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gifski/SavePanelAccessoryViewController.swift
Expand Up @@ -17,7 +17,7 @@ final class SavePanelAccessoryViewController: NSViewController {
let formatter = ByteCountFormatter()
formatter.zeroPadsFractionDigits = true

/// TODO: Use KVO here
// TODO: Use KVO here

let metadata = inputUrl.videoMetadata!
var currentDimensions = metadata.dimensions
Expand Down
10 changes: 5 additions & 5 deletions Gifski/Vendor/DockProgress.swift
Expand Up @@ -51,20 +51,20 @@ public final class DockProgress {

public enum ProgressStyle {
case bar
/// TODO: Make `color` optional when https://github.com/apple/swift-evolution/blob/master/proposals/0155-normalize-enum-case-representation.md is shipping in Swift
// TODO: Make `color` optional when https://github.com/apple/swift-evolution/blob/master/proposals/0155-normalize-enum-case-representation.md is shipping in Swift
case circle(radius: Double, color: NSColor)
case badge(color: NSColor, badgeValue: () -> Int)
case custom(drawHandler: (_ rect: CGRect) -> Void)
}

public static var style: ProgressStyle = .bar

/// TODO: Make the progress smoother by also animating the steps between each call to `updateDockIcon()`
// TODO: Make the progress smoother by also animating the steps between each call to `updateDockIcon()`
private static func updateDockIcon() {
/// TODO: If the `progressValue` is 1, draw the full circle, then schedule another draw in n milliseconds to hide it
let icon = (0..<1).contains(self.progressValue) ? self.draw() : appIcon
// TODO: If the `progressValue` is 1, draw the full circle, then schedule another draw in n milliseconds to hide it
let icon = (0..<1).contains(progressValue) ? draw() : appIcon
DispatchQueue.main.async {
/// TODO: Make this better by drawing in the `contentView` directly instead of using an image
// TODO: Make this better by drawing in the `contentView` directly instead of using an image
dockImageView.image = icon
NSApp.dockTile.display()
}
Expand Down
40 changes: 15 additions & 25 deletions Gifski/util.swift
Expand Up @@ -139,7 +139,7 @@ extension NSWindow {

static let defaultContentSize = CGSize(width: 480, height: 300)

/// TODO: Find a way to stack windows, so additional windows are not placed exactly on top of previous ones: https://github.com/sindresorhus/gifski-app/pull/30#discussion_r175337064
// TODO: Find a way to stack windows, so additional windows are not placed exactly on top of previous ones: https://github.com/sindresorhus/gifski-app/pull/30#discussion_r175337064
static var defaultContentRect: CGRect {
return centeredOnScreen(rect: defaultContentSize.cgRect)
}
Expand Down Expand Up @@ -312,7 +312,7 @@ extension AVAssetImageGenerator {
let isFinished: Bool
}

/// TODO: Remove this when using Swift 5 and use `CancellationError` in the cancellation case
// TODO: Remove this when using Swift 5 and use `CancellationError` in the cancellation case
enum Error: CancellableError {
case cancelled

Expand Down Expand Up @@ -851,23 +851,6 @@ extension URL {
func open() {
NSWorkspace.shared.open(self)
}

func formattedFileSize() -> String {
let formatter = ByteCountFormatter()
formatter.zeroPadsFractionDigits = true

var size: UInt64 = 0

do {
let attr = try FileManager.default.attributesOfItem(atPath: self.path)
let dict = attr as NSDictionary
size = dict.fileSize()
} catch {
print("Error: \(error)")
}

return formatter.string(fromByteCount: Int64(size))
}
}
extension String {
/*
Expand Down Expand Up @@ -1009,6 +992,10 @@ extension URL {
var fileSize: Int {
return resourceValue(forKey: .fileSizeKey) ?? 0
}

var fileSizeFormatted: String {
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file)
}
}

extension CGSize {
Expand Down Expand Up @@ -1037,11 +1024,12 @@ extension CGSize {
return aspectFit(to: CGSize(width: widthHeight, height: widthHeight))
}

// TODO: This one doesn't really make sense. `aspectFit(:widthHeight)` should do what this does already.
func maxSize(size: CGFloat) -> CGSize {
var newSize = aspectFit(to: size)

newSize.width = min(self.width, newSize.width)
newSize.height = min(self.height, newSize.height)
newSize.width = min(width, newSize.width)
newSize.height = min(height, newSize.height)

return newSize
}
Expand Down Expand Up @@ -1415,6 +1403,7 @@ extension Result {
}
}

// TODO: Find a way to reduce the number of overloads for `wrap()`.
final class Once {
private var lock = os_unfair_lock()
private var hasRun = false
Expand Down Expand Up @@ -1543,13 +1532,14 @@ extension NSImage {
}

extension NSSharingService {
class func shareContent(content: [AnyObject], button: NSButton) {
class func share(content: [AnyObject], from button: NSButton, preferredEdge: NSRectEdge = .maxX) {
let sharingServicePicker = NSSharingServicePicker(items: content)
sharingServicePicker.show(relativeTo: button.bounds, of: button, preferredEdge: .maxX)
sharingServicePicker.show(relativeTo: button.bounds, of: button, preferredEdge: preferredEdge)
}
}

extension CALayer {
// TODO: Make this one more generic by accepting a `x` parameter too.
func animateScaleMove(fromScale: CGFloat, fromY: CGFloat) {
let springAnimation = CASpringAnimation(keyPath: #keyPath(CALayer.transform))

Expand All @@ -1560,12 +1550,12 @@ extension CALayer {

springAnimation.damping = 15
springAnimation.mass = 0.9
springAnimation.initialVelocity = 1.0
springAnimation.initialVelocity = 1
springAnimation.duration = springAnimation.settlingDuration

springAnimation.fromValue = NSValue(caTransform3D: tr)
springAnimation.toValue = NSValue(caTransform3D: CATransform3DIdentity)

self.add(springAnimation, forKey: "")
add(springAnimation, forKey: "")
}
}

0 comments on commit bb54fbb

Please sign in to comment.