From 971c0d6e95c0590e5c05902e9397788604ccdcfb Mon Sep 17 00:00:00 2001 From: hatimhtm <106043141+hatimhtm@users.noreply.github.com> Date: Sat, 21 Mar 2026 10:45:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20[code=20health=20improvement]=20?= =?UTF-8?q?Refactor=20getDockRects=20to=20use=20a=20helper=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- Click2Minimize/AppDelegate.swift | 59 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/Click2Minimize/AppDelegate.swift b/Click2Minimize/AppDelegate.swift index 55a4109..a806a99 100644 --- a/Click2Minimize/AppDelegate.swift +++ b/Click2Minimize/AppDelegate.swift @@ -289,32 +289,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { return } - if result.descriptorType == typeAEList { - for index in 1...result.numberOfItems { - if let item = result.atIndex(index) { - // Each item is an array containing position, size, and app ID - if let positionDescriptor = item.atIndex(1), - let sizeDescriptor = item.atIndex(2), - let appIDDescriptor = item.atIndex(3) { - - // Extract position values - let positionX = positionDescriptor.atIndex(1)?.doubleValue ?? 0 - let positionY = positionDescriptor.atIndex(2)?.doubleValue ?? 0 - - // Extract size values - let sizeWidth = sizeDescriptor.atIndex(1)?.doubleValue ?? 0 - let sizeHeight = sizeDescriptor.atIndex(2)?.doubleValue ?? 0 - - // Extract app ID (name) - let appID = appIDDescriptor.stringValue ?? "Unknown" - - let rect = NSRect(x: positionX, y: positionY, width: sizeWidth, height: sizeHeight) - let dockItem = DockItem(rect: rect, appID: appID) - dockItems.append(dockItem) - } - } - } - } + let parsedItems = self.parseDockItems(from: result) + dockItems.append(contentsOf: parsedItems) } promise(.success(dockItems)) @@ -322,6 +298,37 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + private func parseDockItems(from descriptor: NSAppleEventDescriptor) -> [DockItem] { + var items: [DockItem] = [] + + guard descriptor.descriptorType == typeAEList else { + return items + } + + for index in 1...descriptor.numberOfItems { + guard let item = descriptor.atIndex(index), + let positionDescriptor = item.atIndex(1), + let sizeDescriptor = item.atIndex(2), + let appIDDescriptor = item.atIndex(3) else { continue } + + // Extract position values + let positionX = positionDescriptor.atIndex(1)?.doubleValue ?? 0 + let positionY = positionDescriptor.atIndex(2)?.doubleValue ?? 0 + + // Extract size values + let sizeWidth = sizeDescriptor.atIndex(1)?.doubleValue ?? 0 + let sizeHeight = sizeDescriptor.atIndex(2)?.doubleValue ?? 0 + + // Extract app ID (name) + let appID = appIDDescriptor.stringValue ?? "Unknown" + + let rect = NSRect(x: positionX, y: positionY, width: sizeWidth, height: sizeHeight) + items.append(DockItem(rect: rect, appID: appID)) + } + + return items + } + func registerLoginItem() { do { if SMAppService.mainApp.status == .enabled {