From 7fa60df4da84c8abd7c2e9a4da3be5f7be18805a Mon Sep 17 00:00:00 2001 From: Stef Kors Date: Fri, 1 Nov 2024 13:08:01 +0100 Subject: [PATCH] fixes --- .swiftlint.yml | 3 +- .../LaunchPadWidget/WrappingHStack.swift | 2 + GitLab.xcodeproj/project.pbxproj | 10 + GitLab/PopoverResize.swift | 247 ------------------ GitLab/UserDefaultsStorage.swift | 13 - .../Models/NetworkManagerGitLab.swift | 2 +- .../SwiftData/LaunchpadState.swift | 2 +- 7 files changed, 16 insertions(+), 263 deletions(-) delete mode 100644 GitLab/PopoverResize.swift delete mode 100644 GitLab/UserDefaultsStorage.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index cd06bb6..f90e7b9 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -11,4 +11,5 @@ disabled_rules: - file_length - nesting - redundant_string_enum_value - - identifier_name \ No newline at end of file + - identifier_name + - type_name \ No newline at end of file diff --git a/DesktopWidgetTool/LaunchPadWidget/WrappingHStack.swift b/DesktopWidgetTool/LaunchPadWidget/WrappingHStack.swift index 63f4bb7..26a5e49 100644 --- a/DesktopWidgetTool/LaunchPadWidget/WrappingHStack.swift +++ b/DesktopWidgetTool/LaunchPadWidget/WrappingHStack.swift @@ -110,12 +110,14 @@ public struct WrappingHStack: Layout { extension WrappingHStack { struct Row { + // swiftlint:disable:next large_tuple var elements: [(index: Int, size: CGSize, xOffset: CGFloat)] = [] var yOffset: CGFloat = .zero var width: CGFloat = .zero var height: CGFloat = .zero } + // swiftlint:disable:next function_body_length private func arrangeRows(proposal: ProposedViewSize, subviews: Subviews, cache: inout Cache) -> [Row] { diff --git a/GitLab.xcodeproj/project.pbxproj b/GitLab.xcodeproj/project.pbxproj index a6caae0..ba936eb 100644 --- a/GitLab.xcodeproj/project.pbxproj +++ b/GitLab.xcodeproj/project.pbxproj @@ -1318,6 +1318,7 @@ buildRules = ( ); dependencies = ( + 8A858F162CD4FAF90024795D /* PBXTargetDependency */, ); name = DesktopWidgetToolExtension; packageProductDependencies = ( @@ -1963,6 +1964,10 @@ target = 8A5FC0F526EFD08E004136AB /* GitLab */; targetProxy = 8A5FC11726EFD08F004136AB /* PBXContainerItemProxy */; }; + 8A858F162CD4FAF90024795D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + productRef = 8A858F152CD4FAF90024795D /* SwiftLintBuildToolPlugin */; + }; 8AD9D9E92CD4F0B600BE229B /* PBXTargetDependency */ = { isa = PBXTargetDependency; productRef = 8AD9D9E82CD4F0B600BE229B /* SwiftLintBuildToolPlugin */; @@ -2705,6 +2710,11 @@ package = 8AF80DD82A5581B700819B80 /* XCRemoteSwiftPackageReference "CachedAsyncImage" */; productName = CachedAsyncImage; }; + 8A858F152CD4FAF90024795D /* SwiftLintBuildToolPlugin */ = { + isa = XCSwiftPackageProductDependency; + package = 8AD9D9E72CD4F05600BE229B /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */; + productName = "plugin:SwiftLintBuildToolPlugin"; + }; 8AD9D9E82CD4F0B600BE229B /* SwiftLintBuildToolPlugin */ = { isa = XCSwiftPackageProductDependency; package = 8AD9D9E72CD4F05600BE229B /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */; diff --git a/GitLab/PopoverResize.swift b/GitLab/PopoverResize.swift deleted file mode 100644 index 0ac93ed..0000000 --- a/GitLab/PopoverResize.swift +++ /dev/null @@ -1,247 +0,0 @@ -// -// PopoverResize.swift -// PopoverResize -// -// Created by David Boyd on 10/26/18. -// Copyright © 2018 David Boyd. All rights reserved. -// source: https://github.com/dboydor/PopoverResize/blob/master/PopoverResize/PopoverResize/PopoverResize.swift - -import Cocoa - -public class PopoverResize: NSPopover { - let SIDES_HIT = CGFloat(4) - let BOTTOM_HIT = CGFloat(4) - let CORNER_HIT = CGFloat(10) - - private enum Region { - case None - case Left - case LeftBottom - case Bottom - case Right - case RightBottom - } - - private var min: NSSize - private var max: NSSize - private var bottomHeight = CGFloat(20) - private var region: Region = .None - private var down: NSPoint? - private var size: NSSize? - private var trackLeft: NSView.TrackingRectTag? - private var trackRight: NSView.TrackingRectTag? - private var trackLeftBottom: NSView.TrackingRectTag? - private var trackRightBottom: NSView.TrackingRectTag? - private var trackBottom: NSView.TrackingRectTag? - private var sizeChanged: ((_ size: NSSize) -> Void)? - - private let cursorLeftRight = PopoverResize.getCursor("resizeeastwest") - private let cursorLeftBottom = PopoverResize.getCursor("resizenortheastsouthwest") - private let cursorRightBottom = PopoverResize.getCursor("resizenorthwestsoutheast") - private let cursorUpDown = PopoverResize.getCursor("resizenorthsouth") - - // min: the mimimum size the popover is allowed to be - // max: the maximum size the popover is allowed to be - // heightFromBottom: Set this to limit the draggable handle region - // to a height starting from the bottom of the popover - // If 0, then it uses the entire height of popover - public init(min: NSSize, max: NSSize, heightFromBottom: CGFloat = 0) { - self.min = min - self.max = max - self.bottomHeight = heightFromBottom - - // If not defined, use the screen height minus magic # - if self.max.height == 0 { - self.max.height = CGFloat(NSScreen.screens[0].frame.height - 110) - } - - super.init() - } - - required public init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - deinit { - clearTrackers() - } - - // Call this to get notified anytime the popover is resized - public func resized(_ sizeChanged: @escaping (_ size: NSSize) -> Void) { - self.sizeChanged = sizeChanged - } - - public func setContentViewController(_ controller: NSViewController, initialSize: NSSize? = nil) { - contentViewController = controller - - if let size = initialSize { - contentSize = size - } else { - contentSize = NSSize(width: controller.view.bounds.width, height: controller.view.bounds.height) - } - - if bottomHeight == 0 { - bottomHeight = contentSize.height - } - - setTrackers() - } - - override public func mouseEntered(with event: NSEvent) { - if region == .None { - if event.trackingNumber == trackLeft { - region = .Left - } else if event.trackingNumber == trackRight { - region = .Right - } else if event.trackingNumber == trackLeftBottom { - region = .LeftBottom - } else if event.trackingNumber == trackRightBottom { - region = .RightBottom - } else if event.trackingNumber == trackBottom { - region = .Bottom - } else { - region = .None - } - - setCursor() - } - } - - override public func mouseExited(with event: NSEvent) { - if down == nil { - region = .None - setCursor() - } - } - - override public func mouseDown(with event: NSEvent) { - self.size = contentSize - self.down = NSEvent.mouseLocation - - // print("REGION: \(String(describing: region))") - // print("DOWN: \(String(describing: down))") - // print("SIZE: \(String(describing: self.contentSize))") - } - - override public func mouseDragged(with event: NSEvent) { - if region == .None { - return - } - - guard let size = size else { return } - guard let down = down else { return } - - let location = NSEvent.mouseLocation - - var movedX = (location.x - down.x) * 2 - let movedY = location.y - down.y - // print("MOVE x: \(movedX), y: \(movedY)") - - if region == .Left || region == .LeftBottom { - movedX = -movedX - } - - var newWidth = size.width + movedX - if newWidth < min.width { - newWidth = min.width - } else if newWidth > max.width { - newWidth = max.width - } - - var newHeight = size.height - movedY - if newHeight < min.height { - newHeight = min.height - } else if newHeight > max.height { - newHeight = max.height - } - - switch region { - case .Left: fallthrough - case .Right: - contentSize = NSSize(width: newWidth, height: contentSize.height) - case .LeftBottom: fallthrough - case .RightBottom: - contentSize = NSSize(width: newWidth, height: newHeight) - case .Bottom: - contentSize = NSSize(width: contentSize.width, height: newHeight) - default: - () - } - - setCursor() - } - - override public func mouseUp(with event: NSEvent) { - if region != .None { - region = .None - setCursor() - setTrackers() - down = nil - - if let onChanged = sizeChanged { - onChanged(NSSize(width: contentSize.width, height: contentSize.height)) - } - } - } - - private func setCursor() { - switch region { - case .Left: fallthrough - case .Right: - cursorLeftRight.set() - - case .LeftBottom: - cursorLeftBottom.set() - - case .RightBottom: - cursorRightBottom.set() - - case .Bottom: - cursorUpDown.set() - - default: - NSCursor.arrow.set() - } - } - - private func setTrackers() { - clearTrackers() - - if let view = contentViewController?.view { - var bounds = NSRect(x: 0, y: CORNER_HIT, width: SIDES_HIT, height: bottomHeight - CORNER_HIT) - trackLeft = view.addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false) - - bounds = NSRect(x: contentSize.width - SIDES_HIT, y: CORNER_HIT, width: SIDES_HIT, height: bottomHeight - CORNER_HIT) - trackRight = view.addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false) - - bounds = NSRect(x: 0, y: 0, width: CORNER_HIT, height: CORNER_HIT) - trackLeftBottom = view.addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false) - - bounds = NSRect(x: contentSize.width - CORNER_HIT, y: 0, width: CORNER_HIT, height: CORNER_HIT) - trackRightBottom = view.addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false) - - bounds = NSRect(x: CORNER_HIT, y: 0, width: contentSize.width - CORNER_HIT * 2, height: BOTTOM_HIT) - trackBottom = view.addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false) - } - } - - private func clearTrackers() { - if let view = contentViewController?.view, let left = trackLeft, let right = trackRight, let leftBottom = trackLeftBottom, let rightBottom = trackRightBottom, let bottom = trackBottom { - view.removeTrackingRect(left) - view.removeTrackingRect(right) - view.removeTrackingRect(rightBottom) - view.removeTrackingRect(leftBottom) - view.removeTrackingRect(bottom) - } - } - - private static func getCursor(_ name: String) -> NSCursor { - let path = Bundle(for: self).bundlePath - - let image = NSImage(byReferencingFile: path + "/Resources/resources/\(name)_cursor.pdf") - let info = NSDictionary(contentsOfFile: path + "/Resources/resources/\(name)_info.plist") - // let cursor = NSCursor(image: image!, hotSpot: NSPoint(x: (info!.value(forKey: "hotx")! as AnyObject).doubleValue!, y: (info!.value(forKey: "hoty")! as AnyObject).doubleValue!)) - - return NSCursor.arrow - } -} diff --git a/GitLab/UserDefaultsStorage.swift b/GitLab/UserDefaultsStorage.swift deleted file mode 100644 index 9d20218..0000000 --- a/GitLab/UserDefaultsStorage.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// UserDefaultsStorage.swift -// GitLab -// -// Created by Stef Kors on 21/10/2021. -// - -import Foundation -import Defaults - -extension Defaults.Keys { - static let apiToken = Key("apiToken", default: "") -} diff --git a/Shared/UserInterface/Models/NetworkManagerGitLab.swift b/Shared/UserInterface/Models/NetworkManagerGitLab.swift index 4d9d175..1c958a7 100644 --- a/Shared/UserInterface/Models/NetworkManagerGitLab.swift +++ b/Shared/UserInterface/Models/NetworkManagerGitLab.swift @@ -68,7 +68,7 @@ class NetworkManagerGitLab { } func fetch(with account: Account) async throws { - /// Parallel? + // Parallel? // await fetchLatestBranchPush() // try await fetchAuthoredMergeRequests(with: account) // try await fetchReviewRequestedMergeRequests(with: account) diff --git a/Shared/UserInterface/SwiftData/LaunchpadState.swift b/Shared/UserInterface/SwiftData/LaunchpadState.swift index 3c22dee..0c58bd0 100644 --- a/Shared/UserInterface/SwiftData/LaunchpadState.swift +++ b/Shared/UserInterface/SwiftData/LaunchpadState.swift @@ -26,7 +26,7 @@ import SwiftData var url: URL var hasUpdatedSinceLaunch: Bool - static func ==(lhs: LaunchpadRepo, rhs: LaunchpadRepo) -> Bool { + static func == (lhs: LaunchpadRepo, rhs: LaunchpadRepo) -> Bool { return lhs.id == rhs.id }