Skip to content

Commit 0ead064

Browse files
committed
chore: clean up whitespace and minor optimizations
1 parent 9a0ce28 commit 0ead064

3 files changed

Lines changed: 32 additions & 40 deletions

File tree

Rectangle/CycleSize.swift

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ enum CycleSize: Int, CaseIterable {
88
case oneThird = 2
99
case oneQuarter = 3
1010
case threeQuarters = 4
11-
11+
1212
static func fromBits(bits: Int) -> Set<CycleSize> {
1313
Set(
1414
Self.allCases.filter {
1515
(bits >> $0.rawValue) & 1 == 1
1616
}
1717
)
1818
}
19-
19+
2020
static var firstSize = CycleSize.oneHalf
2121
static var defaultSizes: Set<CycleSize> = [.oneHalf, .twoThirds, .oneThird]
22-
22+
2323
// The expected order of the cycle sizes is to start with the
2424
// first division, then go gradually upwards in size and wrap
2525
// around to the smaller sizes.
@@ -28,14 +28,14 @@ enum CycleSize: Int, CaseIterable {
2828
// 1/2, 2/3, 3/4, 1/4, 1/3
2929
static var sortedSizes: [CycleSize] = {
3030
let sortedSizes = Self.allCases.sorted(by: { $0.fraction < $1.fraction })
31-
31+
3232
guard let firstSizeIndex = sortedSizes.firstIndex(of: firstSize) else {
3333
return sortedSizes
3434
}
35-
35+
3636
let lessThanFistSizes = sortedSizes[0..<firstSizeIndex]
3737
let greaterThanFistSizes = sortedSizes[(firstSizeIndex + 1)..<sortedSizes.count]
38-
38+
3939
return [firstSize] + greaterThanFistSizes + lessThanFistSizes
4040
}()
4141
}
@@ -51,34 +51,24 @@ extension CycleSize {
5151
static func matching(percentValue: Float) -> CycleSize? {
5252
sortedSizes.first { $0.matches(percentValue: percentValue) }
5353
}
54-
54+
5555
var title: String {
5656
switch self {
57-
case .twoThirds:
58-
""
59-
case .oneHalf:
60-
"½"
61-
case .oneThird:
62-
""
63-
case .oneQuarter:
64-
"¼"
65-
case .threeQuarters:
66-
"¾"
57+
case .twoThirds: return ""
58+
case .oneHalf: return "½"
59+
case .oneThird: return ""
60+
case .oneQuarter: return "¼"
61+
case .threeQuarters: return "¾"
6762
}
6863
}
69-
64+
7065
var fraction: Float {
7166
switch self {
72-
case .twoThirds:
73-
2 / 3
74-
case .oneHalf:
75-
1 / 2
76-
case .oneThird:
77-
1 / 3
78-
case .oneQuarter:
79-
1 / 4
80-
case .threeQuarters:
81-
3 / 4
67+
case .twoThirds: return 2 / 3
68+
case .oneHalf: return 1 / 2
69+
case .oneThird: return 1 / 3
70+
case .oneQuarter: return 1 / 4
71+
case .threeQuarters: return 3 / 4
8272
}
8373
}
8474

@@ -90,10 +80,8 @@ extension CycleSize {
9080
abs(self.percentValue - percentValue) <= tolerance
9181
}
9282

93-
var isAlwaysEnabled: Bool {
94-
self == .firstSize
95-
}
96-
83+
var isAlwaysEnabled: Bool { self == .firstSize }
84+
9785
}
9886

9987
extension Set where Element == CycleSize {
@@ -109,15 +97,15 @@ extension Set where Element == CycleSize {
10997
class CycleSizesDefault: Default {
11098
public private(set) var key: String = "selectedCycleSizes"
11199
private var initialized = false
112-
100+
113101
var value: Set<CycleSize> {
114102
didSet {
115103
if initialized {
116104
PreferencesStore.shared.set(value.toBits(), forKey: key)
117105
}
118106
}
119107
}
120-
108+
121109
init() {
122110
let bits = PreferencesStore.shared.int(forKey: key)
123111
value = CycleSize.fromBits(bits: bits)
@@ -130,7 +118,7 @@ class CycleSizesDefault: Default {
130118
value = divisions
131119
}
132120
}
133-
121+
134122
func toCodable() -> CodableDefault {
135123
CodableDefault(int: value.toBits())
136124
}

Rectangle/SubsequentExecutionMode.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ enum SubsequentExecutionMode: Int {
1414
class SubsequentExecutionDefault: Default {
1515
public private(set) var key: String = "subsequentExecutionMode"
1616
private var initialized = false
17-
17+
1818
var value: SubsequentExecutionMode {
1919
didSet {
2020
if initialized {
2121
PreferencesStore.shared.set(value.rawValue, forKey: key)
2222
}
2323
}
2424
}
25-
25+
2626
init() {
2727
let intValue = PreferencesStore.shared.int(forKey: key)
2828
value = SubsequentExecutionMode(rawValue: intValue) ?? .resize
2929
initialized = true
3030
}
31-
31+
3232
var resizes: Bool {
3333
switch value {
3434
case .resize, .acrossAndResize, .resizeAndCycleQuadrants: return true
@@ -56,7 +56,7 @@ class SubsequentExecutionDefault: Default {
5656
value = mode
5757
}
5858
}
59-
59+
6060
func toCodable() -> CodableDefault {
6161
CodableDefault(int: value.rawValue)
6262
}

Rectangle/Utilities/MASShortcutMigration.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import Foundation
44
import MASShortcut
55

6+
/// One-time migration from the old NSData-encoded shortcut format to the
7+
/// current NSDictionary format stored via ShortcutStore.
68
enum MASShortcutMigration {
79

810
static func migrate() {
11+
guard let dataTransformer = ValueTransformer(forName: .secureUnarchiveFromDataTransformerName)
12+
else { return }
13+
914
for action in WindowAction.active {
1015
if let dataValue = PreferencesStore.shared.data(forKey: action.name),
11-
let dataTransformer = ValueTransformer(forName: .secureUnarchiveFromDataTransformerName),
1216
let shortcut = dataTransformer.transformedValue(dataValue) as? MASShortcut {
1317
ShortcutStore.setShortcut(shortcut, forKey: action.name)
1418
}

0 commit comments

Comments
 (0)