From 10b9646c8884719346847c99d406ee10b51fec44 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 25 Feb 2020 00:41:58 +0700 Subject: [PATCH] Minor tweaks --- .swiftlint.yml | 4 +++ Gifski/AppDelegate.swift | 10 ++++--- .../ConversionCompletedViewController.swift | 11 ++++--- Gifski/Tooltip.swift | 29 ++++++++++++++----- Gifski/util.swift | 20 +++++++++---- readme.md | 5 ++-- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index f55532ed..3d7b4bc0 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -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 @@ -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 @@ -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 @@ -140,6 +143,7 @@ analyzer_rules: - unused_declaration - unused_import force_cast: warning +force_try: warning force_unwrapping: warning number_separator: minimum_length: 5 diff --git a/Gifski/AppDelegate.swift b/Gifski/AppDelegate.swift index 7b21a9bf..818d55c2 100644 --- a/Gifski/AppDelegate.swift +++ b/Gifski/AppDelegate.swift @@ -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) { diff --git a/Gifski/ConversionCompletedViewController.swift b/Gifski/ConversionCompletedViewController.swift index 85a626f5..2d2e9542 100644 --- a/Gifski/ConversionCompletedViewController.swift +++ b/Gifski/ConversionCompletedViewController.swift @@ -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) } diff --git a/Gifski/Tooltip.swift b/Gifski/Tooltip.swift index c19cd880..06134c7b 100644 --- a/Gifski/Tooltip.swift +++ b/Gifski/Tooltip.swift @@ -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 @@ -25,7 +26,8 @@ final class Tooltip: NSPopover { text: text, closeOnClick: closeOnClick, contentInsets: contentInsets, - maxWidth: maxWidth + maxWidth: maxWidth, + onClick: onClick ) } @@ -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? @@ -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 diff --git a/Gifski/util.swift b/Gifski/util.swift index 7caa527d..a344a0b8 100644 --- a/Gifski/util.swift +++ b/Gifski/util.swift @@ -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) } @@ -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 } @@ -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. diff --git a/readme.md b/readme.md index 33f9d727..cda3d3ed 100644 --- a/readme.md +++ b/readme.md @@ -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? @@ -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