Skip to content

Commit

Permalink
🚨 Resolve all SwiftLint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Dec 1, 2023
1 parent 5749167 commit 95f88da
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1510;
TargetAttributes = {
A8E59C34297F5E9A0064D4BA = {
CreatedOnToolsVersion = 14.2;
Expand Down
2 changes: 1 addition & 1 deletion Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Loop/Extensions/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ extension Defaults.Keys {
Keybind(.topLeftQuarter, keycode: [.kVK_UpArrow, .kVK_LeftArrow]),
Keybind(.topRightQuarter, keycode: [.kVK_UpArrow, .kVK_RightArrow]),
Keybind(.bottomRightQuarter, keycode: [.kVK_DownArrow, .kVK_RightArrow]),
Keybind(.bottomLeftQuarter, keycode: [.kVK_DownArrow, .kVK_LeftArrow]),
Keybind(.bottomLeftQuarter, keycode: [.kVK_DownArrow, .kVK_LeftArrow])
])
}
2 changes: 1 addition & 1 deletion Loop/Managers/KeybindMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class KeybindMonitor {
if cgEvent.type == .flagsChanged,
let event = NSEvent(cgEvent: cgEvent),
!Defaults[.triggerKey].contains(where: { $0.baseModifier == event.keyCode.baseModifier }) {

self.checkForModifier(event, .kVK_Shift, .shift)
self.checkForModifier(event, .kVK_Command, .command)
self.checkForModifier(event, .kVK_Option, .option)
Expand Down
17 changes: 8 additions & 9 deletions Loop/Managers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,16 @@ class LoopManager {
let useTriggerDelay = Defaults[.triggerDelay] > 0.1
let useDoubleClickTrigger = Defaults[.doubleClickToTrigger]

if useDoubleClickTrigger {
if abs(self.lastTriggerKeyClick.timeIntervalSinceNow) < NSEvent.doubleClickInterval {
if useTriggerDelay {
if self.triggerDelayTimer == nil {
self.startTriggerDelayTimer(seconds: Defaults[.triggerDelay]) {
self.openLoop()
}
if useDoubleClickTrigger &&
abs(self.lastTriggerKeyClick.timeIntervalSinceNow) < NSEvent.doubleClickInterval {
if useTriggerDelay {
if self.triggerDelayTimer == nil {
self.startTriggerDelayTimer(seconds: Defaults[.triggerDelay]) {
self.openLoop()
}
} else {
self.openLoop()
}
} else {
self.openLoop()
}
} else if useTriggerDelay {
if self.triggerDelayTimer == nil {
Expand Down
2 changes: 1 addition & 1 deletion Loop/Utilities/EventMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CGEventMonitor: EventMonitor, Identifiable, Equatable {
self.eventCallback = callback

self.eventTap = CGEvent.tapCreate(
tap: .cgSessionEventTap ,
tap: .cgSessionEventTap,
place: .headInsertEventTap,
options: .defaultTap,
eventsOfInterest: eventMask.rawValue,
Expand Down
1 change: 1 addition & 0 deletions Loop/Utilities/TriggerKeycorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct TriggerKeycorder: View {
.fixedSize(horizontal: true, vertical: false)
} else {
ForEach(self.selectionKey.sorted(), id: \.self) { key in
// swiftlint:disable:next line_length
Text("\(key.isOnRightSide ? "Right" : "Left") \(Image(systemName: key.systemImage ?? "exclamationmark.circle.fill"))")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(5)
Expand Down
21 changes: 21 additions & 0 deletions Loop/Window Management/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class Window {
func setFullscreen(_ state: Bool) -> Bool {
return self.axWindow.setValue(.fullScreen, value: state)
}
@discardableResult
func toggleFullscreen() -> Bool {
if !self.isFullscreen {
return self.setFullscreen(true)
}
return self.setHidden(false)
}

var isHidden: Bool {
return self.nsRunningApplication?.isHidden ?? false
Expand All @@ -83,6 +90,13 @@ class Window {
}
return result
}
@discardableResult
func toggleHidden() -> Bool {
if !self.isHidden {
return self.setHidden(true)
}
return self.setHidden(false)
}

var isMinimized: Bool {
let result = self.axWindow.getValue(.minimized) as? NSNumber
Expand All @@ -92,6 +106,13 @@ class Window {
func setMinimized(_ state: Bool) -> Bool {
return self.axWindow.setValue(.minimized, value: state)
}
@discardableResult
func toggleMinimized() -> Bool {
if !self.isMinimized {
return self.setMinimized(true)
}
return self.setMinimized(false)
}

var position: CGPoint {
var point: CGPoint = .zero
Expand Down
34 changes: 9 additions & 25 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,25 @@ struct WindowEngine {
}

if direction == .fullscreen {
if window.isFullscreen {
window.setFullscreen(false)
} else {
window.setFullscreen(true)
}

window.toggleFullscreen()
WindowRecords.recordDirection(window, direction)
return
}
window.setFullscreen(false)

if direction == .hide {
if window.isHidden {
window.setHidden(false)
} else {
window.setHidden(true)
}
window.toggleHidden()
return
}

if direction == .minimize {
if window.isMinimized {
window.setMinimized(false)
} else {
window.setMinimized(true)
}
window.toggleMinimized()
return
}

window.setFullscreen(false)

let oldWindowFrame = window.frame
guard let screenFrame = screen.safeScreenFrame, let currentWindowFrame = WindowEngine.generateWindowFrame(
oldWindowFrame,
screenFrame,
direction,
window
) else {
guard let screenFrame = screen.safeScreenFrame,
let currentWindowFrame = WindowEngine.generateWindowFrame(window.frame, screenFrame, direction, window)
else {
return
}
var targetWindowFrame = WindowEngine.applyPadding(currentWindowFrame, direction)
Expand Down

0 comments on commit 95f88da

Please sign in to comment.