Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Click2Minimize.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@
21B199F72CFF981D00EA628D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21B199F62CFF981D00EA628D /* Assets.xcassets */; };
21B19A052CFF9D1300EA628D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B19A042CFF9D1300EA628D /* AppDelegate.swift */; };
21E5E2E72D009E7E00B51E70 /* Accessibility.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21E5E2E62D009E7E00B51E70 /* Accessibility.framework */; };
816C361CF78711EBFC97B87F /* AppDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C11438E82C3C853894AB4E8 /* AppDelegateTests.swift */; };
D5358AE1C3C83734B390B92B /* VersionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CCF5FFE7142D4190FBC7661 /* VersionUtils.swift */; };
F9EC359B0F3F94185E9FB8D0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ACC42A7C7EBAFC4E6231F75D /* Foundation.framework */; };
FE117B6AFA749D8719079B80 /* VersionUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5ADA2223A0723822559052 /* VersionUtilsTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
47DB7498FD274ABC7F818A59 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 21B199E72CFF981C00EA628D /* Project object */;
proxyType = 1;
remoteGlobalIDString = 21B199EE2CFF981C00EA628D;
remoteInfo = Click2Minimize;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0E5ADA2223A0723822559052 /* VersionUtilsTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = VersionUtilsTests.swift; sourceTree = "<group>"; };
21498BA72D00A20600EE1BF3 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
21B199EF2CFF981C00EA628D /* Click2Minimize.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Click2Minimize.app; sourceTree = BUILT_PRODUCTS_DIR; };
21B199F62CFF981D00EA628D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
21B199FB2CFF981D00EA628D /* Click2Minimize.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Click2Minimize.entitlements; sourceTree = "<group>"; };
21B19A042CFF9D1300EA628D /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
21B19A082D009C6E00EA628D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
21E5E2E62D009E7E00B51E70 /* Accessibility.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accessibility.framework; path = System/Library/Frameworks/Accessibility.framework; sourceTree = SDKROOT; };
6C11438E82C3C853894AB4E8 /* AppDelegateTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AppDelegateTests.swift; sourceTree = "<group>"; };
6CCF5FFE7142D4190FBC7661 /* VersionUtils.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = VersionUtils.swift; sourceTree = "<group>"; };
97A11A7B86DAD2506D525DBD /* Click2MinimizeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Click2MinimizeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
ACC42A7C7EBAFC4E6231F75D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -32,6 +51,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D61BE9125588D13B66450B72 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F9EC359B0F3F94185E9FB8D0 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand All @@ -41,13 +68,15 @@
21B199F12CFF981C00EA628D /* Click2Minimize */,
21B199F02CFF981C00EA628D /* Products */,
21E5E2E52D009E7E00B51E70 /* Frameworks */,
47C333C2BA2D559B49198778 /* Click2MinimizeTests */,
);
sourceTree = "<group>";
};
21B199F02CFF981C00EA628D /* Products */ = {
isa = PBXGroup;
children = (
21B199EF2CFF981C00EA628D /* Click2Minimize.app */,
97A11A7B86DAD2506D525DBD /* Click2MinimizeTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -60,6 +89,7 @@
21B19A042CFF9D1300EA628D /* AppDelegate.swift */,
21B199F62CFF981D00EA628D /* Assets.xcassets */,
21B199FB2CFF981D00EA628D /* Click2Minimize.entitlements */,
6CCF5FFE7142D4190FBC7661 /* VersionUtils.swift */,
);
path = Click2Minimize;
sourceTree = "<group>";
Expand All @@ -68,13 +98,50 @@
isa = PBXGroup;
children = (
21E5E2E62D009E7E00B51E70 /* Accessibility.framework */,
95B74B3F4CA940FC0509CA4F /* iOS */,
);
name = Frameworks;
sourceTree = "<group>";
};
47C333C2BA2D559B49198778 /* Click2MinimizeTests */ = {
isa = PBXGroup;
children = (
6C11438E82C3C853894AB4E8 /* AppDelegateTests.swift */,
0E5ADA2223A0723822559052 /* VersionUtilsTests.swift */,
);
name = Click2MinimizeTests;
path = Click2MinimizeTests;
sourceTree = "<group>";
};
95B74B3F4CA940FC0509CA4F /* iOS */ = {
isa = PBXGroup;
children = (
ACC42A7C7EBAFC4E6231F75D /* Foundation.framework */,
);
name = iOS;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
03C56BB04D96A92C79A68142 /* Click2MinimizeTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 497F588E278ABCD66DE3EBD8 /* Build configuration list for PBXNativeTarget "Click2MinimizeTests" */;
buildPhases = (
3D7F8EB82CB3CEC4D58C272D /* Sources */,
D61BE9125588D13B66450B72 /* Frameworks */,
BBD107D3AE072610616DB155 /* Resources */,
);
buildRules = (
);
dependencies = (
B0AE561055DC427E24D819E7 /* PBXTargetDependency */,
);
name = Click2MinimizeTests;
productName = Click2MinimizeTests;
productReference = 97A11A7B86DAD2506D525DBD /* Click2MinimizeTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
21B199EE2CFF981C00EA628D /* Click2Minimize */ = {
isa = PBXNativeTarget;
buildConfigurationList = 21B199FE2CFF981D00EA628D /* Build configuration list for PBXNativeTarget "Click2Minimize" */;
Expand Down Expand Up @@ -121,6 +188,8 @@
projectRoot = "";
targets = (
21B199EE2CFF981C00EA628D /* Click2Minimize */,
03C56BB04D96A92C79A68142 /* Click2MinimizeTests */,
03C56BB04D96A92C79A68142 /* Click2MinimizeTests */,
);
};
/* End PBXProject section */
Expand All @@ -134,6 +203,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
BBD107D3AE072610616DB155 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -143,11 +219,30 @@
files = (
21498BA82D00A20600EE1BF3 /* ContentView.swift in Sources */,
21B19A052CFF9D1300EA628D /* AppDelegate.swift in Sources */,
D5358AE1C3C83734B390B92B /* VersionUtils.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
3D7F8EB82CB3CEC4D58C272D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
816C361CF78711EBFC97B87F /* AppDelegateTests.swift in Sources */,
FE117B6AFA749D8719079B80 /* VersionUtilsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
B0AE561055DC427E24D819E7 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = Click2Minimize;
target = 21B199EE2CFF981C00EA628D /* Click2Minimize */;
targetProxy = 47DB7498FD274ABC7F818A59 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
21B199FC2CFF981D00EA628D /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -335,6 +430,21 @@
};
name = Release;
};
88DD887C5C5AD0488AFA814D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
SDKROOT = iphoneos;
};
name = Debug;
};
FA459D670F76238C2B0B4175 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -356,6 +466,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
497F588E278ABCD66DE3EBD8 /* Build configuration list for PBXNativeTarget "Click2MinimizeTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FA459D670F76238C2B0B4175 /* Release */,
88DD887C5C5AD0488AFA814D /* Debug */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 21B199E72CFF981C00EA628D /* Project object */;
Expand Down
15 changes: 1 addition & 14 deletions Click2Minimize/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
if let releaseInfo = try? JSONDecoder().decode(Release.self, from: data) {
// Compare with current version and prompt user if an update is available
if self.isNewerVersion(releaseInfo.tag_name, currentVersion: self.currentVersion) {
if VersionUtils.isNewerVersion(releaseInfo.tag_name, currentVersion: self.currentVersion) {
DispatchQueue.main.async {
self.promptUserToUpdate(releaseInfo)
}
Expand All @@ -397,19 +397,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
task.resume()
}

private func isNewerVersion(_ newVersion: String, currentVersion: String) -> Bool {
let newVersionComponents = newVersion.split(separator: ".").map { Int($0) ?? 0 }
let currentVersionComponents = currentVersion.split(separator: ".").map { Int($0) ?? 0 }

for (new, current) in zip(newVersionComponents, currentVersionComponents) {
if new > current {
return true
} else if new < current {
return false
}
}
return newVersionComponents.count > currentVersionComponents.count
}

private func promptUserToUpdate(_ releaseInfo: Release) {
let alert = NSAlert()
Expand Down
17 changes: 17 additions & 0 deletions Click2Minimize/VersionUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation

struct VersionUtils {
static func isNewerVersion(_ newVersion: String, currentVersion: String) -> Bool {
let newVersionComponents = newVersion.split(separator: ".").map { Int($0) ?? 0 }
let currentVersionComponents = currentVersion.split(separator: ".").map { Int($0) ?? 0 }

for (new, current) in zip(newVersionComponents, currentVersionComponents) {
if new > current {
return true
} else if new < current {
return false
}
}
return newVersionComponents.count > currentVersionComponents.count
}
}
24 changes: 24 additions & 0 deletions Click2MinimizeTests/AppDelegateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import XCTest
@testable import Click2Minimize

final class AppDelegateTests: XCTestCase {

func testSetupAppDict() {
let appDelegate = AppDelegate()
appDelegate.setupAppDict()

XCTAssertEqual(appDelegate.appDict["Visual Studio Code"], "Code")
XCTAssertEqual(appDelegate.appDict["Rosetta Stone Learn Languages"], "Rosetta Stone")
XCTAssertNil(appDelegate.appDict["Nonexistent App"])
}

func testDockItemInitialization() {
let rect = NSRect(x: 10, y: 20, width: 30, height: 40)
let appID = "TestApp"

let dockItem = AppDelegate.DockItem(rect: rect, appID: appID)

XCTAssertEqual(dockItem.rect, rect)
XCTAssertEqual(dockItem.appID, appID)
}
}
27 changes: 27 additions & 0 deletions Click2MinimizeTests/VersionUtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import XCTest
@testable import Click2Minimize

final class VersionUtilsTests: XCTestCase {

func testIsNewerVersion() {
// Newer versions
XCTAssertTrue(VersionUtils.isNewerVersion("1.0.1", currentVersion: "1.0.0"))
XCTAssertTrue(VersionUtils.isNewerVersion("1.1.0", currentVersion: "1.0.0"))
XCTAssertTrue(VersionUtils.isNewerVersion("2.0.0", currentVersion: "1.0.0"))
XCTAssertTrue(VersionUtils.isNewerVersion("1.0.0.1", currentVersion: "1.0.0"))

// Older versions
XCTAssertFalse(VersionUtils.isNewerVersion("1.0.0", currentVersion: "1.0.1"))
XCTAssertFalse(VersionUtils.isNewerVersion("1.0.0", currentVersion: "1.1.0"))
XCTAssertFalse(VersionUtils.isNewerVersion("1.0.0", currentVersion: "2.0.0"))
XCTAssertFalse(VersionUtils.isNewerVersion("1.0.0", currentVersion: "1.0.0.1"))

// Equal versions
XCTAssertFalse(VersionUtils.isNewerVersion("1.0.0", currentVersion: "1.0.0"))
XCTAssertFalse(VersionUtils.isNewerVersion("2.1.3", currentVersion: "2.1.3"))

// Edge cases
XCTAssertFalse(VersionUtils.isNewerVersion("1.0", currentVersion: "1.0.0"))
XCTAssertTrue(VersionUtils.isNewerVersion("1.0.0", currentVersion: "1.0"))
}
}
Binary file removed dist/Click2Minimize.dmg
Binary file not shown.