Skip to content

Commit

Permalink
add check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Nov 16, 2024
1 parent 7a2597d commit 00fe133
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 29 deletions.
61 changes: 37 additions & 24 deletions pullBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
7629FBD02A4F713300081779 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 7629FBCF2A4F713300081779 /* LaunchAtLogin */; };
768A4C5528AF253C004E557E /* BottomItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 768A4C5428AF253C004E557E /* BottomItemView.swift */; };
7695CC3E2C99F717004EAB35 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 7695CC3D2C99F717004EAB35 /* LaunchAtLogin */; };
769F4E1B2765A2B900594911 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 769F4E1A2765A2B900594911 /* AboutView.swift */; };
769F4E7B277B97B300594911 /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 769F4E7A277B97B300594911 /* Notifications.swift */; };
769F4E7D277CAFAD00594911 /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 769F4E7C277CAFAD00594911 /* StringExtensions.swift */; };
76C6AA5B2C98E809003472DA /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 76C6AA5A2C98E809003472DA /* Defaults */; };
76D5F9E428D28958009EBD80 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 76D5F9E328D28958009EBD80 /* KeychainAccess */; };
76D5F9E628D28A29009EBD80 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76D5F9E528D28A29009EBD80 /* Keychain.swift */; };
76F7DAD028A88CAB0086A3B0 /* GithubTokenValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F7DACF28A88CAB0086A3B0 /* GithubTokenValidator.swift */; };
Expand All @@ -22,7 +23,6 @@
8CECBBEA2742AAFB00A2802D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8CECBBE82742AAFB00A2802D /* Main.storyboard */; };
8CECBBF42742AB3F00A2802D /* GitHubClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CECBBF22742AB3F00A2802D /* GitHubClient.swift */; };
8CECBBF52742AB3F00A2802D /* GitHubDtos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CECBBF32742AB3F00A2802D /* GitHubDtos.swift */; };
8CECBBF82742ABDA00A2802D /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 8CECBBF72742ABDA00A2802D /* Defaults */; };
8CECBBFB2742ABE600A2802D /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 8CECBBFA2742ABE600A2802D /* Alamofire */; };
8CECBBFE2742AC0800A2802D /* DefaultsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CECBBFD2742AC0800A2802D /* DefaultsExtensions.swift */; };
8CECBC022742B3A000A2802D /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CECBC002742B3A000A2802D /* PreferencesView.swift */; };
Expand Down Expand Up @@ -55,21 +55,29 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8CECBBF82742ABDA00A2802D /* Defaults in Frameworks */,
76C6AA5B2C98E809003472DA /* Defaults in Frameworks */,
8CECBBFB2742ABE600A2802D /* Alamofire in Frameworks */,
7629FBD02A4F713300081779 /* LaunchAtLogin in Frameworks */,
7695CC3E2C99F717004EAB35 /* LaunchAtLogin in Frameworks */,
76D5F9E428D28958009EBD80 /* KeychainAccess in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
76C6AA592C98E809003472DA /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
8CECBBD62742AAF800A2802D = {
isa = PBXGroup;
children = (
8CECBBE12742AAF800A2802D /* pullBar */,
8CECBBE02742AAF800A2802D /* Products */,
76C6AA592C98E809003472DA /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -139,18 +147,18 @@
8CECBBDB2742AAF800A2802D /* Sources */,
8CECBBDC2742AAF800A2802D /* Frameworks */,
8CECBBDD2742AAF800A2802D /* Resources */,
7629FBD12A4F7AB700081779 /* Copy Launch at Login Helper */,
7695CC3F2C99F729004EAB35 /* Copy Launch at Login Helper */,
);
buildRules = (
);
dependencies = (
);
name = pullBar;
packageProductDependencies = (
8CECBBF72742ABDA00A2802D /* Defaults */,
8CECBBFA2742ABE600A2802D /* Alamofire */,
76D5F9E328D28958009EBD80 /* KeychainAccess */,
7629FBCF2A4F713300081779 /* LaunchAtLogin */,
76C6AA5A2C98E809003472DA /* Defaults */,
7695CC3D2C99F717004EAB35 /* LaunchAtLogin */,
);
productName = pullBar;
productReference = 8CECBBDF2742AAF800A2802D /* pullBar.app */;
Expand All @@ -164,7 +172,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1300;
LastUpgradeCheck = 1410;
LastUpgradeCheck = 1530;
TargetAttributes = {
8CECBBDE2742AAF800A2802D = {
CreatedOnToolsVersion = 13.0;
Expand All @@ -184,7 +192,7 @@
8CECBBF62742ABDA00A2802D /* XCRemoteSwiftPackageReference "Defaults" */,
8CECBBF92742ABE600A2802D /* XCRemoteSwiftPackageReference "Alamofire" */,
76D5F9E228D28958009EBD80 /* XCRemoteSwiftPackageReference "KeychainAccess" */,
7629FBCE2A4F713300081779 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */,
7695CC3C2C99F717004EAB35 /* XCRemoteSwiftPackageReference "LaunchAtLogin-Legacy" */,
);
productRefGroup = 8CECBBE02742AAF800A2802D /* Products */;
projectDirPath = "";
Expand All @@ -208,7 +216,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
7629FBD12A4F7AB700081779 /* Copy Launch at Login Helper */ = {
7695CC3F2C99F729004EAB35 /* Copy Launch at Login Helper */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
Expand All @@ -218,7 +226,7 @@
);
inputPaths = (
);
name = "Copy Launch at Login Helper";
name = "Copy Launch at Login Helper";
outputFileListPaths = (
);
outputPaths = (
Expand Down Expand Up @@ -303,6 +311,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -365,6 +374,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down Expand Up @@ -392,10 +402,11 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14gh;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = UV3HUS49VJ;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
Expand All @@ -405,7 +416,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.9;
MARKETING_VERSION = 1.10;
PRODUCT_BUNDLE_IDENTIFIER = debug.com.pavelmakhov.pullBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -420,12 +431,14 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = pullBar/pullBar.entitlements;
CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14gh;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = UV3HUS49VJ;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
Expand All @@ -435,7 +448,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.9;
MARKETING_VERSION = 1.10;
PRODUCT_BUNDLE_IDENTIFIER = com.pavelmakhov.pullBar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -467,9 +480,9 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
7629FBCE2A4F713300081779 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */ = {
7695CC3C2C99F717004EAB35 /* XCRemoteSwiftPackageReference "LaunchAtLogin-Legacy" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin";
repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin-Legacy";
requirement = {
branch = main;
kind = branch;
Expand Down Expand Up @@ -502,21 +515,21 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
7629FBCF2A4F713300081779 /* LaunchAtLogin */ = {
7695CC3D2C99F717004EAB35 /* LaunchAtLogin */ = {
isa = XCSwiftPackageProductDependency;
package = 7629FBCE2A4F713300081779 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */;
package = 7695CC3C2C99F717004EAB35 /* XCRemoteSwiftPackageReference "LaunchAtLogin-Legacy" */;
productName = LaunchAtLogin;
};
76C6AA5A2C98E809003472DA /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = 8CECBBF62742ABDA00A2802D /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
76D5F9E328D28958009EBD80 /* KeychainAccess */ = {
isa = XCSwiftPackageProductDependency;
package = 76D5F9E228D28958009EBD80 /* XCRemoteSwiftPackageReference "KeychainAccess" */;
productName = KeychainAccess;
};
8CECBBF72742ABDA00A2802D /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = 8CECBBF62742ABDA00A2802D /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
8CECBBFA2742ABE600A2802D /* Alamofire */ = {
isa = XCSwiftPackageProductDependency;
package = 8CECBBF92742ABE600A2802D /* XCRemoteSwiftPackageReference "Alamofire" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "de88b4e3acd0459cb33360c3cb3c9525e47d50d144b21866ea79c3fa7c6d021e",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -28,14 +29,14 @@
}
},
{
"identity" : "launchatlogin",
"identity" : "launchatlogin-legacy",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sindresorhus/LaunchAtLogin",
"location" : "https://github.com/sindresorhus/LaunchAtLogin-Legacy",
"state" : {
"branch" : "main",
"revision" : "7ad6331f9c38953eb1ce8737758e18f7607e984a"
"revision" : "9a894d799269cb591037f9f9cb0961510d4dca81"
}
}
],
"version" : 2
"version" : 3
}
2 changes: 1 addition & 1 deletion pullBar.xcodeproj/xcshareddata/xcschemes/pullBar.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1530"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
36 changes: 36 additions & 0 deletions pullBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ extension AppDelegate {
self.menu.addItem(withTitle: "Refresh", action: #selector(self.refreshMenu), keyEquivalent: "")
self.menu.addItem(.separator())
self.menu.addItem(withTitle: "Preferences...", action: #selector(self.openPrefecencesWindow), keyEquivalent: "")
// Remove for app store release
self.menu.addItem(withTitle: "Check for updates...", action: #selector(self.checkForUpdates), keyEquivalent: "")
self.menu.addItem(withTitle: "About PullBar", action: #selector(self.openAboutWindow), keyEquivalent: "")
self.menu.addItem(withTitle: "Quit", action: #selector(self.quit), keyEquivalent: "")
}
Expand Down Expand Up @@ -414,4 +416,38 @@ extension AppDelegate {
NSLog("User click Quit")
NSApplication.shared.terminate(self)
}

@objc
func checkForUpdates(_: NSStatusBarButton?) {
let currentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
ghClient.getLatestRelease { latestRelease in
if let latestRelease = latestRelease {
let versionComparison = currentVersion.compare(latestRelease.name.replacingOccurrences(of: "v", with: ""), options: .numeric)
if versionComparison == .orderedAscending {
self.downloadNewVersionDialog(link: latestRelease.assets[0].browserDownloadUrl)
} else {
self.dialogWithText(text: "You have the latest version installed!")
}
}
}
}

func dialogWithText(text: String) -> Void {
let alert = NSAlert()
alert.messageText = text
alert.alertStyle = .informational
alert.addButton(withTitle: "OK")
alert.runModal()
}
func downloadNewVersionDialog(link: String) -> Void {
let alert = NSAlert()
alert.messageText = "New version is available!"
alert.alertStyle = .informational
alert.addButton(withTitle: "Download")
alert.addButton(withTitle: "Cancel")
let pressedButton = alert.runModal()
if (pressedButton == .alertFirstButtonReturn) {
NSWorkspace.shared.open(URL(string: link)!)
}
}
}
26 changes: 26 additions & 0 deletions pullBar/GitHub/GitHubClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ public class GitHubClient {
}
}
}

func getLatestRelease(completion:@escaping (((LatestRelease?) -> Void))) -> Void {
let headers: HTTPHeaders = [
.authorization(username: githubUsername, password: githubToken),
.contentType("application/json"),
.accept("application/json")
]
AF.request("https://api.github.com/repos/menubar-apps/PullBar/releases/latest",
method: .get,
encoding: JSONEncoding.default,
headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: LatestRelease.self) { response in
switch response.result {
case .success(let latestRelease):
completion(latestRelease)
case .failure(let error):
completion(nil)
if let data = response.data {
let json = String(data: data, encoding: String.Encoding.utf8)
// print("Failure Response: \(json)")
}
sendNotification(body: error.localizedDescription)
}
}
}
}

class GithubDecoder: JSONDecoder {
Expand Down

0 comments on commit 00fe133

Please sign in to comment.