mirror of
https://github.com/sindresorhus/touch-bar-simulator
synced 2024-12-11 21:12:31 +00:00
Upgrade to Swift 5.1
This commit is contained in:
parent
0bd6ad734f
commit
250284d86c
9 changed files with 151 additions and 126 deletions
|
@ -13,6 +13,8 @@ whitelist_rules:
|
|||
- comma
|
||||
- compiler_protocol_init
|
||||
- conditional_returns_on_newline
|
||||
- contains_over_filter_count
|
||||
- contains_over_filter_is_empty
|
||||
- contains_over_first_not_nil
|
||||
- control_statement
|
||||
- deployment_target
|
||||
|
@ -21,8 +23,10 @@ whitelist_rules:
|
|||
- discouraged_object_literal
|
||||
- discouraged_optional_boolean
|
||||
- discouraged_optional_collection
|
||||
- duplicate_enum_cases
|
||||
- duplicate_imports
|
||||
- dynamic_inline
|
||||
- empty_collection_literal
|
||||
- empty_count
|
||||
- empty_enum_arguments
|
||||
- empty_parameters
|
||||
|
@ -48,6 +52,7 @@ whitelist_rules:
|
|||
- legacy_constant
|
||||
- legacy_constructor
|
||||
- legacy_hashing
|
||||
- legacy_multiple
|
||||
- legacy_nsgeometry_functions
|
||||
- legacy_random
|
||||
- literal_expression_end_indentation
|
||||
|
@ -63,7 +68,9 @@ whitelist_rules:
|
|||
- nimble_operator
|
||||
- no_extension_access_modifier
|
||||
- no_fallthrough_only
|
||||
- no_space_in_method_call
|
||||
- notification_center_detachment
|
||||
- nsobject_prefer_isequal
|
||||
- number_separator
|
||||
- object_literal
|
||||
- opening_brace
|
||||
|
@ -76,6 +83,8 @@ whitelist_rules:
|
|||
- private_unit_test
|
||||
- prohibited_super_call
|
||||
- protocol_property_accessors_order
|
||||
- reduce_boolean
|
||||
- reduce_into
|
||||
- redundant_discardable_let
|
||||
- redundant_nil_coalescing
|
||||
- redundant_objc_attribute
|
||||
|
@ -95,6 +104,7 @@ whitelist_rules:
|
|||
- switch_case_alignment
|
||||
- switch_case_on_newline
|
||||
- syntactic_sugar
|
||||
- todo
|
||||
- toggle_bool
|
||||
- trailing_closure
|
||||
- trailing_comma
|
||||
|
@ -105,7 +115,9 @@ whitelist_rules:
|
|||
- unavailable_function
|
||||
- unneeded_break_in_switch
|
||||
- unneeded_parentheses_in_closure_argument
|
||||
- unowned_variable_capture
|
||||
- untyped_error_in_catch
|
||||
- unused_capture_list
|
||||
- unused_closure_parameter
|
||||
- unused_control_flow_label
|
||||
- unused_enumerated
|
||||
|
@ -117,15 +129,13 @@ whitelist_rules:
|
|||
- vertical_whitespace_closing_braces
|
||||
- vertical_whitespace_opening_braces
|
||||
- void_return
|
||||
- weak_computed_property
|
||||
- weak_delegate
|
||||
- xct_specific_matcher
|
||||
- xctfail_message
|
||||
- yoda_condition
|
||||
- todo
|
||||
analyzer_rules:
|
||||
- unused_declaration
|
||||
- unused_import
|
||||
- unused_private_declaration
|
||||
force_cast: warning
|
||||
force_unwrapping: warning
|
||||
number_separator:
|
||||
|
@ -134,6 +144,18 @@ object_literal:
|
|||
image_literal: false
|
||||
discouraged_object_literal:
|
||||
color_literal: false
|
||||
type_contents_order:
|
||||
order:
|
||||
- case
|
||||
- [type_alias, associated_type, subtype]
|
||||
- type_property
|
||||
- type_method
|
||||
- ib_outlet
|
||||
- [ib_inspectable, instance_property]
|
||||
- initializer
|
||||
- subscript
|
||||
- view_life_cycle_method
|
||||
- [ib_action, other_method]
|
||||
identifier_name:
|
||||
max_length:
|
||||
warning: 100
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github "sindresorhus/Defaults" "v2.0.0"
|
||||
github "sindresorhus/Defaults" "v3.0.0"
|
||||
github "sparkle-project/Sparkle" "1.21.3"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 51;
|
||||
objectVersion = 52;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
|
@ -163,7 +163,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0820;
|
||||
LastUpgradeCheck = 0930;
|
||||
LastUpgradeCheck = 1100;
|
||||
ORGANIZATIONNAME = "Sindre Sorhus";
|
||||
TargetAttributes = {
|
||||
E3FE2CBE1E726CE800C6713A = {
|
||||
|
@ -180,10 +180,11 @@
|
|||
};
|
||||
};
|
||||
buildConfigurationList = E3FE2CBA1E726CE800C6713A /* Build configuration list for PBXProject "Touch Bar Simulator" */;
|
||||
compatibilityVersion = "Xcode 10.0";
|
||||
compatibilityVersion = "Xcode 11.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = E3FE2CB61E726CE800C6713A;
|
||||
|
@ -296,13 +297,14 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14.4;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_COMPILATION_MODE = singlefile;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VALID_ARCHS = x86_64;
|
||||
};
|
||||
name = Debug;
|
||||
|
@ -349,11 +351,12 @@
|
|||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14.4;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VALID_ARCHS = x86_64;
|
||||
};
|
||||
name = Release;
|
||||
|
@ -366,6 +369,7 @@
|
|||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = YG56YK5RN5;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)",
|
||||
|
@ -404,6 +408,7 @@
|
|||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = YG56YK5RN5;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)",
|
||||
|
|
|
@ -4,12 +4,14 @@ import Defaults
|
|||
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
lazy var window = with(TouchBarWindow()) {
|
||||
$0.alphaValue = CGFloat(defaults[.windowTransparency])
|
||||
$0.alphaValue = CGFloat(Defaults[.windowTransparency])
|
||||
$0.setUp()
|
||||
}
|
||||
|
||||
lazy var statusItem = with(NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)) {
|
||||
$0.menu = with(NSMenu()) { $0.delegate = self }
|
||||
$0.menu = with(NSMenu()) {
|
||||
$0.delegate = self
|
||||
}
|
||||
$0.button!.image = NSImage(named: "MenuBarIcon")
|
||||
$0.button!.toolTip = "Right-click or option-click for menu"
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ extension AppDelegate: NSMenuDelegate {
|
|||
}
|
||||
|
||||
private func statusItemShouldShowMenu() -> Bool {
|
||||
return !NSApp.isLeftMouseDown || NSApp.isOptionKeyDown
|
||||
!NSApp.isLeftMouseDown || NSApp.isOptionKeyDown
|
||||
}
|
||||
|
||||
func menuNeedsUpdate(_ menu: NSMenu) {
|
||||
|
@ -111,7 +113,7 @@ extension AppDelegate: NSMenuDelegate {
|
|||
private func statusItemButtonClicked() {
|
||||
// When the user explicitly wants the Touch Bar to appear then `dockBahavior` should be disabled.
|
||||
// This is also how the macOS Dock behaves.
|
||||
defaults[.dockBehavior] = false
|
||||
Defaults[.dockBehavior] = false
|
||||
|
||||
toggleView()
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import Defaults
|
|||
|
||||
extension Defaults {
|
||||
@discardableResult
|
||||
func observe<T: Codable, Weak: AnyObject>(
|
||||
static func observe<T: Codable, Weak: AnyObject>(
|
||||
_ key: Key<T>,
|
||||
tiedToLifetimeOf weaklyHeldObject: Weak,
|
||||
options: NSKeyValueObservingOptions = [.initial, .new, .old],
|
||||
|
@ -40,17 +40,17 @@ extension NSMenuItem {
|
|||
*/
|
||||
func bindState(to key: Defaults.Key<Bool>) -> Self {
|
||||
addAction { _ in
|
||||
defaults[key].toggle()
|
||||
Defaults[key].toggle()
|
||||
}
|
||||
|
||||
defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
self.isChecked = change.newValue
|
||||
}
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// TODO: The doc comments here are out of date
|
||||
// TODO: The doc comments here are out of date.
|
||||
/**
|
||||
Adds an action to this menu item that sets the value of `key` in the
|
||||
defaults system to `value`, and initializes this item's state based on
|
||||
|
@ -66,10 +66,10 @@ extension NSMenuItem {
|
|||
*/
|
||||
func bindChecked<Value: Equatable>(to key: Defaults.Key<Value>, value: Value) -> Self {
|
||||
addAction { _ in
|
||||
defaults[key] = value
|
||||
Defaults[key] = value
|
||||
}
|
||||
|
||||
defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
self.isChecked = (change.newValue == value)
|
||||
}
|
||||
|
||||
|
@ -91,10 +91,10 @@ extension NSSlider {
|
|||
*/
|
||||
func bindDoubleValue(to key: Defaults.Key<Double>) -> Self {
|
||||
addAction { sender in
|
||||
defaults[key] = sender.doubleValue
|
||||
Defaults[key] = sender.doubleValue
|
||||
}
|
||||
|
||||
defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
|
||||
self.doubleValue = change.newValue
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ private final class ToolbarSliderCell: NSSliderCell {
|
|||
var frame = knobRect.insetBy(dx: 0, dy: 6.5)
|
||||
if let shadow = self.shadow {
|
||||
// Make room on either side of the view for the shadow to spill into,
|
||||
// rather than clip on the edges
|
||||
// rather than clip on the edges.
|
||||
frame.origin.x *= ((barRect.width - shadow.shadowBlurRadius * 2) / barRect.width)
|
||||
frame.origin.x += shadow.shadowBlurRadius
|
||||
}
|
||||
|
||||
// Make the slider grey
|
||||
// Make the slider grey.
|
||||
var greySliderFrame = barRect
|
||||
greySliderFrame.origin.x -= 1
|
||||
greySliderFrame.origin.y = barRect.origin.y + 1
|
||||
|
@ -46,7 +46,7 @@ private final class ToolbarSliderCell: NSSliderCell {
|
|||
fillColor.set()
|
||||
path.fill()
|
||||
|
||||
// Border should not draw a shadow
|
||||
// Border should not draw a shadow.
|
||||
NSShadow().set()
|
||||
|
||||
// Border
|
||||
|
@ -81,7 +81,7 @@ extension NSSlider {
|
|||
// itself brighter for some reason.
|
||||
func alwaysRedisplayOnValueChanged() -> Self {
|
||||
addAction { sender in
|
||||
if (defaults[.windowTransparency] - sender.doubleValue) != 0 {
|
||||
if (Defaults[.windowTransparency] - sender.doubleValue) != 0 {
|
||||
sender.needsDisplay = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,7 @@ final class TouchBarView: NSView {
|
|||
stop()
|
||||
}
|
||||
|
||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
|
||||
return true
|
||||
}
|
||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
||||
|
||||
func start() {
|
||||
stream = SLSDFRDisplayStreamCreate(0, .main) { status, _, frameSurface, _ in
|
||||
|
@ -38,7 +36,7 @@ final class TouchBarView: NSView {
|
|||
}
|
||||
|
||||
func stop() {
|
||||
guard let stream = stream else {
|
||||
guard let stream = self.stream else {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ final class TouchBarWindow: NSPanel {
|
|||
func reposition(window: NSWindow) {
|
||||
switch self {
|
||||
case .floating:
|
||||
if let prevPosition = defaults[.lastFloatingPosition] {
|
||||
if let prevPosition = Defaults[.lastFloatingPosition] {
|
||||
window.setFrameOrigin(prevPosition)
|
||||
}
|
||||
case .dockedToTop:
|
||||
|
@ -32,18 +32,22 @@ final class TouchBarWindow: NSPanel {
|
|||
}
|
||||
}
|
||||
|
||||
override var canBecomeMain: Bool { false }
|
||||
|
||||
override var canBecomeKey: Bool { false }
|
||||
|
||||
var docking: Docking = .floating {
|
||||
didSet {
|
||||
if oldValue == .floating && docking != .floating {
|
||||
defaults[.lastFloatingPosition] = frame.origin
|
||||
Defaults[.lastFloatingPosition] = frame.origin
|
||||
}
|
||||
|
||||
if self.docking == .floating {
|
||||
if docking == .floating {
|
||||
dockBehavior = false
|
||||
}
|
||||
|
||||
// Prevent the Touch Bar from momentarily becoming visible.
|
||||
if self.docking == .floating || !dockBehavior {
|
||||
if docking == .floating || !dockBehavior {
|
||||
stopDockBehaviorTimer()
|
||||
docking.dock(window: self)
|
||||
setIsVisible(true)
|
||||
|
@ -51,7 +55,7 @@ final class TouchBarWindow: NSPanel {
|
|||
return
|
||||
}
|
||||
|
||||
// When docking is set to `dockedToTop` or `dockedToBottom` dockBehavior should start
|
||||
// When docking is set to `dockedToTop` or `dockedToBottom` dockBehavior should start.
|
||||
if dockBehavior {
|
||||
setIsVisible(false)
|
||||
docking.dock(window: self)
|
||||
|
@ -80,7 +84,14 @@ final class TouchBarWindow: NSPanel {
|
|||
|
||||
func startDockBehaviorTimer() {
|
||||
stopDockBehaviorTimer()
|
||||
dockBehaviorTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(handleDockBehavior), userInfo: nil, repeats: true)
|
||||
|
||||
dockBehaviorTimer = Timer.scheduledTimer(
|
||||
timeInterval: 0.1,
|
||||
target: self,
|
||||
selector: #selector(handleDockBehavior),
|
||||
userInfo: nil,
|
||||
repeats: true
|
||||
)
|
||||
}
|
||||
|
||||
func stopDockBehaviorTimer() {
|
||||
|
@ -88,23 +99,23 @@ final class TouchBarWindow: NSPanel {
|
|||
dockBehaviorTimer = Timer()
|
||||
}
|
||||
|
||||
var dockBehavior: Bool = defaults[.dockBehavior] {
|
||||
var dockBehavior: Bool = Defaults[.dockBehavior] {
|
||||
didSet {
|
||||
defaults[.dockBehavior] = self.dockBehavior
|
||||
if self.docking == .dockedToBottom || self.docking == .dockedToTop {
|
||||
defaults[.lastWindowDockingWithDockBehavior] = self.docking
|
||||
Defaults[.dockBehavior] = dockBehavior
|
||||
if docking == .dockedToBottom || docking == .dockedToTop {
|
||||
Defaults[.lastWindowDockingWithDockBehavior] = docking
|
||||
}
|
||||
|
||||
if dockBehavior {
|
||||
if self.docking == .dockedToBottom || self.docking == .dockedToTop {
|
||||
self.docking = defaults[.lastWindowDockingWithDockBehavior]
|
||||
if docking == .dockedToBottom || docking == .dockedToTop {
|
||||
docking = Defaults[.lastWindowDockingWithDockBehavior]
|
||||
startDockBehaviorTimer()
|
||||
} else if self.docking == .floating {
|
||||
defaults[.windowDocking] = defaults[.lastWindowDockingWithDockBehavior]
|
||||
} else if docking == .floating {
|
||||
Defaults[.windowDocking] = Defaults[.lastWindowDockingWithDockBehavior]
|
||||
}
|
||||
} else {
|
||||
stopDockBehaviorTimer()
|
||||
self.setIsVisible(true)
|
||||
setIsVisible(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,25 +130,25 @@ final class TouchBarWindow: NSPanel {
|
|||
}
|
||||
|
||||
var detectionRect: NSRect = .zero
|
||||
if self.docking == .dockedToBottom {
|
||||
if self.isVisible {
|
||||
if docking == .dockedToBottom {
|
||||
if isVisible {
|
||||
detectionRect = CGRect(
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: visibleFrame.width,
|
||||
height: self.frame.height + (screenFrame.height - visibleFrame.height - NSStatusBar.system.thickness)
|
||||
height: frame.height + (screenFrame.height - visibleFrame.height - NSStatusBar.system.thickness)
|
||||
)
|
||||
} else {
|
||||
detectionRect = CGRect(x: 0, y: 0, width: visibleFrame.width, height: 1)
|
||||
}
|
||||
} else if self.docking == .dockedToTop {
|
||||
if self.isVisible {
|
||||
} else if docking == .dockedToTop {
|
||||
if isVisible {
|
||||
detectionRect = CGRect(
|
||||
x: 0,
|
||||
// Without `+ 1`, the Touch Bar would glitch (toggling rapidly).
|
||||
y: screenFrame.height - self.frame.height - NSStatusBar.system.thickness + 1,
|
||||
y: screenFrame.height - frame.height - NSStatusBar.system.thickness + 1,
|
||||
width: visibleFrame.width,
|
||||
height: self.frame.height + NSStatusBar.system.thickness)
|
||||
height: frame.height + NSStatusBar.system.thickness)
|
||||
} else {
|
||||
detectionRect = CGRect(
|
||||
x: 0,
|
||||
|
@ -167,7 +178,7 @@ final class TouchBarWindow: NSPanel {
|
|||
showTouchBarTimer = Timer()
|
||||
showAnimationDidRun = false
|
||||
|
||||
if self.isVisible && !dismissAnimationDidRun {
|
||||
if isVisible && !dismissAnimationDidRun {
|
||||
performActionWithAnimation(action: .dismiss)
|
||||
dismissAnimationDidRun = true
|
||||
}
|
||||
|
@ -175,10 +186,10 @@ final class TouchBarWindow: NSPanel {
|
|||
}
|
||||
|
||||
func moveToStartPoint() {
|
||||
if self.docking == .dockedToTop {
|
||||
self.moveTo(x: .center, y: .top)
|
||||
} else if self.docking == .dockedToBottom {
|
||||
self.moveTo(x: .center, y: .bottom)
|
||||
if docking == .dockedToTop {
|
||||
moveTo(x: .center, y: .top)
|
||||
} else if docking == .dockedToBottom {
|
||||
moveTo(x: .center, y: .bottom)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,25 +198,25 @@ final class TouchBarWindow: NSPanel {
|
|||
|
||||
func showTouchBarWithAnimation() {
|
||||
guard
|
||||
self.docking == .dockedToTop ||
|
||||
self.docking == .dockedToBottom
|
||||
docking == .dockedToTop ||
|
||||
docking == .dockedToBottom
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
var startOrigin: CGPoint!
|
||||
let endFrame = self.frame
|
||||
self.setIsVisible(true)
|
||||
if self.docking == .dockedToTop {
|
||||
startOrigin = CGPoint(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height)
|
||||
} else if self.docking == .dockedToBottom {
|
||||
startOrigin = CGPoint(x: self.frame.origin.x, y: 0 - self.frame.height)
|
||||
let endFrame = frame
|
||||
setIsVisible(true)
|
||||
if docking == .dockedToTop {
|
||||
startOrigin = CGPoint(x: frame.origin.x, y: frame.origin.y + frame.height)
|
||||
} else if docking == .dockedToBottom {
|
||||
startOrigin = CGPoint(x: frame.origin.x, y: 0 - frame.height)
|
||||
}
|
||||
self.setFrameOrigin(startOrigin)
|
||||
setFrameOrigin(startOrigin)
|
||||
|
||||
NSAnimationContext.runAnimationGroup({ context in
|
||||
context.duration = TimeInterval(0.3)
|
||||
self.animator().setFrame(endFrame, display: false, animate: true)
|
||||
animator().setFrame(endFrame, display: false, animate: true)
|
||||
}, completionHandler: {
|
||||
self.moveToStartPoint()
|
||||
})
|
||||
|
@ -213,22 +224,22 @@ final class TouchBarWindow: NSPanel {
|
|||
|
||||
func dismissTouchBarWithAnimation() {
|
||||
guard
|
||||
self.docking == .dockedToTop ||
|
||||
self.docking == .dockedToBottom
|
||||
docking == .dockedToTop ||
|
||||
docking == .dockedToBottom
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
var endFrame = self.frame
|
||||
if self.docking == .dockedToTop {
|
||||
endFrame.origin = NSPoint(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height + NSStatusBar.system.thickness)
|
||||
} else if self.docking == .dockedToBottom {
|
||||
endFrame.origin = NSPoint(x: self.frame.origin.x, y: 0 - self.frame.height)
|
||||
var endFrame = frame
|
||||
if docking == .dockedToTop {
|
||||
endFrame.origin = NSPoint(x: frame.origin.x, y: frame.origin.y + frame.height + NSStatusBar.system.thickness)
|
||||
} else if docking == .dockedToBottom {
|
||||
endFrame.origin = NSPoint(x: frame.origin.x, y: 0 - frame.height)
|
||||
}
|
||||
|
||||
NSAnimationContext.runAnimationGroup({ context in
|
||||
context.duration = TimeInterval(0.3)
|
||||
self.animator().setFrame(endFrame, display: false, animate: true)
|
||||
animator().setFrame(endFrame, display: false, animate: true)
|
||||
}, completionHandler: {
|
||||
self.setIsVisible(false)
|
||||
self.moveToStartPoint()
|
||||
|
@ -237,38 +248,41 @@ final class TouchBarWindow: NSPanel {
|
|||
|
||||
func performActionWithAnimation(action: TouchBarAction) {
|
||||
guard
|
||||
self.docking == .dockedToTop ||
|
||||
self.docking == .dockedToBottom
|
||||
docking == .dockedToTop ||
|
||||
docking == .dockedToBottom
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
var startOrigin: CGPoint!
|
||||
var endFrame = self.frame
|
||||
var endFrame = frame
|
||||
|
||||
if action == .show {
|
||||
self.setIsVisible(true)
|
||||
if self.docking == .dockedToTop {
|
||||
startOrigin = CGPoint(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height)
|
||||
} else if self.docking == .dockedToBottom {
|
||||
startOrigin = CGPoint(x: self.frame.origin.x, y: 0 - self.frame.height)
|
||||
setIsVisible(true)
|
||||
|
||||
if docking == .dockedToTop {
|
||||
startOrigin = CGPoint(x: frame.origin.x, y: frame.origin.y + frame.height)
|
||||
} else if docking == .dockedToBottom {
|
||||
startOrigin = CGPoint(x: frame.origin.x, y: 0 - frame.height)
|
||||
}
|
||||
self.setFrameOrigin(startOrigin)
|
||||
|
||||
setFrameOrigin(startOrigin)
|
||||
} else if action == .dismiss {
|
||||
if self.docking == .dockedToTop {
|
||||
endFrame.origin = NSPoint(x: self.frame.origin.x, y: self.frame.origin.y + self.frame.height + NSStatusBar.system.thickness)
|
||||
} else if self.docking == .dockedToBottom {
|
||||
endFrame.origin = NSPoint(x: self.frame.origin.x, y: 0 - self.frame.height)
|
||||
if docking == .dockedToTop {
|
||||
endFrame.origin = NSPoint(x: frame.origin.x, y: frame.origin.y + frame.height + NSStatusBar.system.thickness)
|
||||
} else if docking == .dockedToBottom {
|
||||
endFrame.origin = NSPoint(x: frame.origin.x, y: 0 - frame.height)
|
||||
}
|
||||
}
|
||||
|
||||
NSAnimationContext.runAnimationGroup({ context in
|
||||
context.duration = TimeInterval(0.3)
|
||||
self.animator().setFrame(endFrame, display: false, animate: true)
|
||||
animator().setFrame(endFrame, display: false, animate: true)
|
||||
}, completionHandler: {
|
||||
if action == .dismiss {
|
||||
self.setIsVisible(false)
|
||||
}
|
||||
|
||||
self.moveToStartPoint()
|
||||
})
|
||||
}
|
||||
|
@ -316,14 +330,6 @@ final class TouchBarWindow: NSPanel {
|
|||
return slider
|
||||
}
|
||||
|
||||
override var canBecomeMain: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
override var canBecomeKey: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
private var defaultsObservations: [DefaultsObservation] = []
|
||||
|
||||
func setUp() {
|
||||
|
@ -337,21 +343,21 @@ final class TouchBarWindow: NSPanel {
|
|||
view.addSubview(touchBarView)
|
||||
|
||||
// TODO: These could use the `observe` method with `tiedToLifetimeOf` so we don't have to manually invalidate them.
|
||||
defaultsObservations.append(defaults.observe(.windowTransparency) { change in
|
||||
defaultsObservations.append(Defaults.observe(.windowTransparency) { change in
|
||||
self.alphaValue = CGFloat(change.newValue)
|
||||
})
|
||||
|
||||
defaultsObservations.append(defaults.observe(.windowDocking) { change in
|
||||
defaultsObservations.append(Defaults.observe(.windowDocking) { change in
|
||||
self.docking = change.newValue
|
||||
})
|
||||
|
||||
// TODO: We could maybe simplify this by creating another `Default` extension to bind a default to a KeyPath:
|
||||
// `defaults.bind(.showOnAllDesktops, to: \.showOnAllDesktop)`
|
||||
defaultsObservations.append(defaults.observe(.showOnAllDesktops) { change in
|
||||
defaultsObservations.append(Defaults.observe(.showOnAllDesktops) { change in
|
||||
self.showOnAllDesktops = change.newValue
|
||||
})
|
||||
|
||||
defaultsObservations.append(defaults.observe(.dockBehavior) { change in
|
||||
defaultsObservations.append(Defaults.observe(.dockBehavior) { change in
|
||||
self.dockBehavior = change.newValue
|
||||
})
|
||||
|
||||
|
@ -388,8 +394,8 @@ final class TouchBarWindow: NSPanel {
|
|||
backing: .buffered,
|
||||
defer: false
|
||||
)
|
||||
self.level = .assistiveTechHigh
|
||||
|
||||
self.level = .assistiveTechHigh
|
||||
self._setPreventsActivation(true)
|
||||
self.isRestorable = true
|
||||
self.hidesOnDeactivate = false
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Cocoa
|
||||
|
||||
/**
|
||||
Convenience function for initializing an object and modifying its properties
|
||||
Convenience function for initializing an object and modifying its properties.
|
||||
|
||||
```
|
||||
let label = with(NSTextField()) {
|
||||
|
@ -19,8 +19,8 @@ func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
|
|||
}
|
||||
|
||||
extension CGRect {
|
||||
func adding(padding: Double) -> CGRect {
|
||||
return CGRect(
|
||||
func adding(padding: Double) -> Self {
|
||||
Self(
|
||||
x: origin.x - CGFloat(padding),
|
||||
y: origin.y - CGFloat(padding),
|
||||
width: width + CGFloat(padding * 2),
|
||||
|
@ -29,10 +29,10 @@ extension CGRect {
|
|||
}
|
||||
|
||||
/**
|
||||
Returns a CGRect where `self` is centered in `rect`
|
||||
Returns a `CGRect` where `self` is centered in `rect`.
|
||||
*/
|
||||
func centered(in rect: CGRect, xOffset: Double = 0, yOffset: Double = 0) -> CGRect {
|
||||
return CGRect(
|
||||
func centered(in rect: Self, xOffset: Double = 0, yOffset: Double = 0) -> Self {
|
||||
Self(
|
||||
x: ((rect.width - size.width) / 2) + CGFloat(xOffset),
|
||||
y: ((rect.height - size.height) / 2) + CGFloat(yOffset),
|
||||
width: size.width,
|
||||
|
@ -42,9 +42,7 @@ extension CGRect {
|
|||
}
|
||||
|
||||
extension NSWindow {
|
||||
var toolbarView: NSView? {
|
||||
return standardWindowButton(.closeButton)?.superview
|
||||
}
|
||||
var toolbarView: NSView? { standardWindowButton(.closeButton)?.superview }
|
||||
}
|
||||
|
||||
extension NSWindow {
|
||||
|
@ -60,6 +58,7 @@ extension NSWindow {
|
|||
guard let screen = NSScreen.main else {
|
||||
return
|
||||
}
|
||||
|
||||
let visibleFrame = screen.visibleFrame
|
||||
|
||||
let x: CGFloat, y: CGFloat
|
||||
|
@ -73,7 +72,7 @@ extension NSWindow {
|
|||
}
|
||||
switch yPositioning {
|
||||
case .top:
|
||||
// Defect fix: keep docked windows below menubar area
|
||||
// Defect fix: keep docked windows below menubar area.
|
||||
// Previously, the window would obstruct menubar clicks when the menubar was set to auto-hide.
|
||||
// Now, the window stays below that area.
|
||||
let menubarThickness = NSStatusBar.system.thickness
|
||||
|
@ -96,9 +95,7 @@ extension NSView {
|
|||
|
||||
extension NSMenuItem {
|
||||
var isChecked: Bool {
|
||||
get {
|
||||
return state == .on
|
||||
}
|
||||
get { state == .on }
|
||||
set {
|
||||
state = newValue ? .on : .off
|
||||
}
|
||||
|
@ -130,7 +127,7 @@ extension NSMenuItem {
|
|||
final class AssociatedObject<T: Any> {
|
||||
subscript(index: Any) -> T? {
|
||||
get {
|
||||
return objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as! T?
|
||||
objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as! T?
|
||||
} set {
|
||||
objc_setAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque(), newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
}
|
||||
|
@ -179,7 +176,7 @@ extension TargetActionSender {
|
|||
*/
|
||||
var onAction: ((Self) -> Void)? {
|
||||
get {
|
||||
return (TargetActionSenderAssociatedKeys.trampoline[self] as? ActionTrampoline<Self>)?.action
|
||||
(TargetActionSenderAssociatedKeys.trampoline[self] as? ActionTrampoline<Self>)?.action
|
||||
}
|
||||
set {
|
||||
guard let newValue = newValue else {
|
||||
|
@ -207,13 +204,8 @@ extension TargetActionSender {
|
|||
}
|
||||
|
||||
extension NSApplication {
|
||||
var isLeftMouseDown: Bool {
|
||||
return currentEvent?.type == .leftMouseDown
|
||||
}
|
||||
|
||||
var isOptionKeyDown: Bool {
|
||||
return NSEvent.modifierFlags.contains(.option)
|
||||
}
|
||||
var isLeftMouseDown: Bool { currentEvent?.type == .leftMouseDown }
|
||||
var isOptionKeyDown: Bool { NSEvent.modifierFlags.contains(.option) }
|
||||
}
|
||||
|
||||
// TODO: Find a namespace to put this onto. I don't like free-floating functions.
|
||||
|
@ -228,7 +220,7 @@ func pressKey(keyCode: CGKeyCode, flags: CGEventFlags = []) {
|
|||
|
||||
extension NSWindow.Level {
|
||||
private static func level(for cgLevelKey: CGWindowLevelKey) -> NSWindow.Level {
|
||||
return NSWindow.Level(rawValue: Int(CGWindowLevelForKey(cgLevelKey)))
|
||||
NSWindow.Level(rawValue: Int(CGWindowLevelForKey(cgLevelKey)))
|
||||
}
|
||||
|
||||
public static let desktop = level(for: .desktopWindow)
|
||||
|
|
Loading…
Reference in a new issue