Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 21, 2019
1 parent 986b996 commit ad95da5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Gifski/Base.lproj/MainMenu.xib
Expand Up @@ -158,7 +158,7 @@
<menuItem title="Source Code" id="LPR-FD-PrP" customClass="UrlMenuItem" customModule="Gifski" customModuleProvider="target">
<modifierMask key="keyEquivalentModifierMask"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="url" value="https://github.com/sindresorhus/gifski-app"/>
<userDefinedRuntimeAttribute type="string" keyPath="url" value="https://github.com/sindresorhus/Gifski"/>
</userDefinedRuntimeAttributes>
</menuItem>
<menuItem isSeparatorItem="YES" id="R9f-81-F3Z"/>
Expand Down
8 changes: 4 additions & 4 deletions Gifski/MainWindowController.swift
Expand Up @@ -22,7 +22,7 @@ final class MainWindowController: NSWindowController {

private lazy var timeRemainingLabel = with(Label()) {
$0.isHidden = true
$0.textColor = NSColor.secondaryLabelColor
$0.textColor = .secondaryLabelColor
$0.font = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: .regular)
}

Expand Down Expand Up @@ -155,7 +155,7 @@ final class MainWindowController: NSWindowController {
NSAlert.showModalAndReportToCrashlytics(
for: window,
message: "The video file is not supported.",
informativeText: "Please open an issue on https://github.com/sindresorhus/gifski-app or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
informativeText: "Please open an issue on https://github.com/sindresorhus/Gifski or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
debugInfo: asset.debugInfo
)

Expand All @@ -166,7 +166,7 @@ final class MainWindowController: NSWindowController {
NSAlert.showModalAndReportToCrashlytics(
for: window,
message: "The video metadata is not readable.",
informativeText: "Please open an issue on https://github.com/sindresorhus/gifski-app or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
informativeText: "Please open an issue on https://github.com/sindresorhus/Gifski or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
debugInfo: asset.debugInfo
)

Expand All @@ -181,7 +181,7 @@ final class MainWindowController: NSWindowController {
NSAlert.showModalAndReportToCrashlytics(
for: window,
message: "The video dimensions must be at least 10×10.",
informativeText: "The dimensions of your video are \(asset.dimensions?.formatted ?? "0×0").\n\nIf you think this error is a mistake, please open an issue on https://github.com/sindresorhus/gifski-app or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
informativeText: "The dimensions of your video are \(asset.dimensions?.formatted ?? "0×0").\n\nIf you think this error is a mistake, please open an issue on https://github.com/sindresorhus/Gifski or email sindresorhus@gmail.com. ZIP the video and attach it.\n\nInclude this info:\n\(asset.debugInfo)",
debugInfo: asset.debugInfo
)

Expand Down
2 changes: 1 addition & 1 deletion Gifski/Vendor/Defaults.swift
Expand Up @@ -153,7 +153,7 @@ extension UserDefaults {
}
}

/// TODO: Nest this inside `Defaults` if Swift ever supported nested protocols.
// TODO: Nest this inside `Defaults` if Swift ever supported nested protocols.
public protocol DefaultsObservation {
func invalidate()
}
Expand Down
4 changes: 2 additions & 2 deletions Gifski/VideoDropView.swift
Expand Up @@ -13,7 +13,8 @@ class DropView: SSView {
}

private let dropLabel = with(Label()) {
$0.textColor = NSColor.secondaryLabelColor
$0.textColor = .secondaryLabelColor
$0.font = NSFont.systemFont(ofSize: 14)
}

var highlightColor: NSColor {
Expand Down Expand Up @@ -53,7 +54,6 @@ class DropView: SSView {

override func didAppear() {
addSubviewToCenter(dropLabel)
dropLabel.pulsateScale()
}

override func layout() {
Expand Down
91 changes: 27 additions & 64 deletions Gifski/util.swift
Expand Up @@ -40,7 +40,7 @@ struct Meta {
"body": body
]

URL(string: "https://github.com/sindresorhus/gifski-app/issues/new")!.addingDictionaryAsQuery(query).open()
URL(string: "https://github.com/sindresorhus/Gifski/issues/new")!.addingDictionaryAsQuery(query).open()
}
}

Expand All @@ -65,43 +65,6 @@ extension NSColor {
}


extension NSView {
func pulsate(duration: TimeInterval = 2) {
let animation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))
animation.duration = duration
animation.fromValue = 1
animation.toValue = 0.9
animation.timingFunction = .easeInOut
animation.autoreverses = true
animation.repeatCount = .infinity

wantsLayer = true
layer?.add(animation, forKey: nil)
}

func pulsateScale(duration: TimeInterval = 1.5, scale: Double = 1.05) {
pulsate(duration: duration)

let multiplier = CGFloat(scale)

var tr = CATransform3DIdentity
tr = CATransform3DTranslate(tr, bounds.size.width / 2, bounds.size.height / 2, 0)
tr = CATransform3DScale(tr, multiplier, multiplier, 1)
tr = CATransform3DTranslate(tr, -bounds.size.width / 2, -bounds.size.height / 2, 0)

let animation = CABasicAnimation(keyPath: #keyPath(CALayer.transform))
animation.toValue = NSValue(caTransform3D: tr)
animation.duration = duration
animation.timingFunction = .easeInOut
animation.autoreverses = true
animation.repeatCount = .infinity

wantsLayer = true
layer?.add(animation, forKey: nil)
}
}


/// This is useful as `awakeFromNib` is not called for programatically created views
class SSView: NSView {
var didAppearWasCalled = false
Expand Down Expand Up @@ -135,7 +98,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/pull/30#discussion_r175337064
static var defaultContentRect: CGRect {
return centeredOnScreen(rect: defaultContentSize.cgRect)
}
Expand Down Expand Up @@ -457,9 +420,9 @@ extension Double {
//=> "0.01"
```
*/
var formatted: String {
return truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
}
var formatted: String {
return truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
}
}
extension CGFloat {
var formatted: String {
Expand Down Expand Up @@ -519,7 +482,7 @@ extension AVAssetTrack {
let size = naturalSize.applying(preferredTransform)
let preferredSize = CGSize(width: abs(size.width), height: abs(size.height))

// Workaround for https://github.com/sindresorhus/gifski-app/issues/76
// Workaround for https://github.com/sindresorhus/Gifski/issues/76
guard preferredSize != .zero else {
return asset?.image(at: CMTime(seconds: 0, preferredTimescale: .video))?.size
}
Expand Down Expand Up @@ -558,22 +521,22 @@ extension AVAssetTrack {
}

/// Returns a debug string with the media format. Example: `vide/avc1`
var mediaFormat: String {
var mediaFormat: String {
let descriptions = formatDescriptions as! [CMFormatDescription]

var format = [String]()
for description in descriptions {
// Get string representation of media type (vide, soun, sbtl, etc.)
let type = CMFormatDescriptionGetMediaType(description).toString()
var format = [String]()
for description in descriptions {
// Get string representation of media type (vide, soun, sbtl, etc.)
let type = CMFormatDescriptionGetMediaType(description).toString()

// Get string representation media subtype (avc1, aac, tx3g, etc.)
let subType = CMFormatDescriptionGetMediaSubType(description).toString()
let subType = CMFormatDescriptionGetMediaSubType(description).toString()

format.append("\(type)/\(subType)")
}
format.append("\(type)/\(subType)")
}

return format.joined(separator: ",")
}
}

/// Estimated file size of the track in bytes.
var estimatedFileSize: Int {
Expand All @@ -587,18 +550,18 @@ extension AVAssetTrack {
> FOURCC is short for "four character code" - an identifier for a video codec, compression format, color or pixel format used in media files.
*/
extension FourCharCode {
/// Create a String representation of a FourCC.
func toString() -> String {
let bytes: [CChar] = [
CChar((self >> 24) & 0xff),
CChar((self >> 16) & 0xff),
CChar((self >> 8) & 0xff),
CChar(self & 0xff),
0
]

return String(cString: bytes).trimmingCharacters(in: .whitespaces)
}
/// Create a String representation of a FourCC.
func toString() -> String {
let bytes: [CChar] = [
CChar((self >> 24) & 0xff),
CChar((self >> 16) & 0xff),
CChar((self >> 8) & 0xff),
CChar(self & 0xff),
0
]

return String(cString: bytes).trimmingCharacters(in: .whitespaces)
}
}


Expand Down
4 changes: 2 additions & 2 deletions license
@@ -1,7 +1,7 @@
MIT License

© 2018 Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
© 2018 Kornel Lesiński <kornel@pngquant.org> (gif.ski)
© 2019 Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
© 2019 Kornel Lesiński <kornel@pngquant.org> (gif.ski)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
5 changes: 0 additions & 5 deletions readme.md
Expand Up @@ -53,11 +53,6 @@ xcode-select --install
- [DockProgress](https://github.com/sindresorhus/DockProgress) - Show progress in your app's Dock icon


## Links

- [More Swift packages by me](https://github.com/search?q=user%3Asindresorhus+language%3Aswift)


## Maintainers

- [Sindre Sorhus](https://github.com/sindresorhus)
Expand Down

0 comments on commit ad95da5

Please sign in to comment.