Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 9, 2020
1 parent 99a88e9 commit 10b9646
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .swiftlint.yml
Expand Up @@ -86,6 +86,7 @@ whitelist_rules:
- private_action
- private_outlet
- private_unit_test
- prohibited_nan_comparison
- prohibited_super_call
- protocol_property_accessors_order
- reduce_boolean
Expand All @@ -99,6 +100,7 @@ whitelist_rules:
- redundant_type_annotation
- redundant_void_return
- required_enum_case
- return_value_from_void_function
- return_arrow_whitespace
- shorthand_operator
- sorted_first_last
Expand All @@ -115,6 +117,7 @@ whitelist_rules:
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- tuple_pattern
- unavailable_function
- unneeded_break_in_switch
- unneeded_parentheses_in_closure_argument
Expand All @@ -140,6 +143,7 @@ analyzer_rules:
- unused_declaration
- unused_import
force_cast: warning
force_try: warning
force_unwrapping: warning
number_separator:
minimum_length: 5
Expand Down
10 changes: 6 additions & 4 deletions Gifski/AppDelegate.swift
Expand Up @@ -13,10 +13,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
let notificationCenter = UNUserNotificationCenter.current()

func applicationWillFinishLaunching(_ notification: Notification) {
UserDefaults.standard.register(defaults: [
"NSApplicationCrashOnExceptions": true,
"NSFullScreenMenuItemEverywhere": false
])
UserDefaults.standard.register(
defaults: [
"NSApplicationCrashOnExceptions": true,
"NSFullScreenMenuItemEverywhere": false
]
)
}

func applicationDidFinishLaunching(_ notification: Notification) {
Expand Down
11 changes: 7 additions & 4 deletions Gifski/ConversionCompletedViewController.swift
Expand Up @@ -55,10 +55,13 @@ final class ConversionCompletedViewController: NSViewController {
view.window?.makeFirstResponder(self)

if wrapperView.isHidden {
draggableFile.layer?.animateScaleMove(
fromScale: 3,
fromY: Double(view.frame.height + draggableFile.frame.size.height)
)
if !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion {
draggableFile.layer?.animateScaleMove(
fromScale: 3,
fromY: Double(view.frame.height + draggableFile.frame.size.height)
)
}

wrapperView.fadeIn(duration: 0.5, delay: 0.15, completion: nil)
}

Expand Down
29 changes: 22 additions & 7 deletions Gifski/Tooltip.swift
Expand Up @@ -15,7 +15,8 @@ final class Tooltip: NSPopover {
showOnlyOnce: Bool = false,
closeOnClick: Bool = true,
contentInsets: NSEdgeInsets = .init(all: 15),
maxWidth: Double? = nil
maxWidth: Double? = nil,
onClick: (() -> Void)? = nil
) {
self.identifier = identifier
self.showOnlyOnce = showOnlyOnce
Expand All @@ -25,7 +26,8 @@ final class Tooltip: NSPopover {
text: text,
closeOnClick: closeOnClick,
contentInsets: contentInsets,
maxWidth: maxWidth
maxWidth: maxWidth,
onClick: onClick
)
}

Expand Down Expand Up @@ -75,19 +77,32 @@ final class Tooltip: NSPopover {
text: String,
closeOnClick: Bool,
contentInsets: NSEdgeInsets,
maxWidth: Double?
maxWidth: Double?,
onClick: (() -> Void)? = nil
) {
contentViewController = ToolTipViewController(text: text, contentInsets: contentInsets, maxWidth: maxWidth) { [weak self] in
animates = !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion
behavior = closeOnClick ? .semitransient : .applicationDefined

contentViewController = ToolTipViewController(
text: text,
contentInsets: contentInsets,
maxWidth: maxWidth
) { [weak self] in
if closeOnClick {
self?.close()
}
}

behavior = closeOnClick ? .semitransient : .applicationDefined
onClick?()
}
}
}

fileprivate final class ToolTipViewController: NSViewController {
private final class ContentView: NSView {
// This makes the tooltip dismissable by click even if the owner window is not key.
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
}

fileprivate let text: String
fileprivate let contentInsets: NSEdgeInsets
fileprivate var maxWidth: Double?
Expand Down Expand Up @@ -115,7 +130,7 @@ fileprivate final class ToolTipViewController: NSViewController {
}

override func loadView() {
let wrapperView = NSView()
let wrapperView = ContentView()
let textField = NSTextField(wrappingLabelWithString: text)
textField.isSelectable = false

Expand Down
20 changes: 14 additions & 6 deletions Gifski/util.swift
Expand Up @@ -109,11 +109,6 @@ extension NSWindow {
return window
}

@nonobjc
override convenience init() {
self.init(contentRect: NSWindow.defaultContentRect)
}

convenience init(contentRect: CGRect) {
self.init(contentRect: contentRect, styleMask: NSWindow.defaultStyleMask, backing: .buffered, defer: true)
}
Expand Down Expand Up @@ -2156,7 +2151,7 @@ extension Crashlytics {

static func recordNonFatalError(title: String? = nil, message: String) {
#if !DEBUG
sharedInstance().recordError(NSError.appError(message: message, domainPostfix: title))
sharedInstance().recordError(NSError.appError(message, domainPostfix: title))
#endif
}

Expand Down Expand Up @@ -2574,6 +2569,19 @@ extension NSViewController {
let newOrigin = CGPoint(x: window.frame.midX - viewController.view.frame.width / 2.0, y: window.frame.midY - viewController.view.frame.height / 2.0)
let newWindowFrame = CGRect(origin: newOrigin, size: viewController.view.frame.size)

guard !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion else {
window.makeFirstResponder(viewController)

DispatchQueue.main.async {
window.contentViewController = nil
window.setFrame(newWindowFrame, display: true)
window.contentViewController = viewController
completion?()
}

return
}

viewController.view.alphaValue = 0.0

// Workaround for macOS first responder quirk. Still in macOS 10.15.3.
Expand Down
5 changes: 2 additions & 3 deletions readme.md
Expand Up @@ -66,7 +66,7 @@ The GIF image format is very space inefficient. It works best with short video c

### Can I contribute localizations?

No, we're not interested in localizing the app.
We're not interested in localizing the app.

### Can you support macOS 10.13?

Expand Down Expand Up @@ -97,8 +97,7 @@ No, but there's a [cross-platform command-line tool](https://github.com/ImageOpt

## Related

- [Plash](https://github.com/sindresorhus/Plash) - Make any website your desktop wallpaper
- [More apps…](https://sindresorhus.com/apps)
- [Sindre's apps](https://sindresorhus.com/apps)

## License

Expand Down

0 comments on commit 10b9646

Please sign in to comment.