Skip to content

Commit b2cd72f

Browse files
Add version check against GitHub releases
1 parent f46c558 commit b2cd72f

File tree

7 files changed

+133
-14
lines changed

7 files changed

+133
-14
lines changed

HA Menu.xcodeproj/project.pbxproj

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 52;
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
4904FBB923D35A6700575D29 /* FeedKit in Frameworks */ = {isa = PBXBuildFile; productRef = 4904FBB823D35A6700575D29 /* FeedKit */; };
1011
491F529D217CBF5200105921 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 491F529C217CBF5200105921 /* AppDelegate.swift */; };
1112
491F52A1217CBF5400105921 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 491F52A0217CBF5400105921 /* Assets.xcassets */; };
1213
491F52A4217CBF5400105921 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 491F52A2217CBF5400105921 /* Main.storyboard */; };
@@ -94,6 +95,7 @@
9495
buildActionMask = 2147483647;
9596
files = (
9697
49BDE9DC237DA0FA0087F729 /* ServiceManagement.framework in Frameworks */,
98+
4904FBB923D35A6700575D29 /* FeedKit in Frameworks */,
9799
);
98100
runOnlyForDeploymentPostprocessing = 0;
99101
};
@@ -236,6 +238,9 @@
236238
dependencies = (
237239
);
238240
name = "HA Menu";
241+
packageProductDependencies = (
242+
4904FBB823D35A6700575D29 /* FeedKit */,
243+
);
239244
productName = "HA Menu";
240245
productReference = 491F5299217CBF5200105921 /* HA Menu.app */;
241246
productType = "com.apple.product-type.application";
@@ -335,6 +340,9 @@
335340
Base,
336341
);
337342
mainGroup = 491F5290217CBF5200105921;
343+
packageReferences = (
344+
4904FBB723D35A6700575D29 /* XCRemoteSwiftPackageReference "FeedKit" */,
345+
);
338346
productRefGroup = 491F529A217CBF5200105921 /* Products */;
339347
projectDirPath = "";
340348
projectRoot = "";
@@ -583,15 +591,15 @@
583591
CODE_SIGN_IDENTITY = "Apple Development";
584592
CODE_SIGN_STYLE = Automatic;
585593
COMBINE_HIDPI_IMAGES = YES;
586-
CURRENT_PROJECT_VERSION = 15;
594+
CURRENT_PROJECT_VERSION = 16;
587595
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
588596
ENABLE_HARDENED_RUNTIME = YES;
589597
INFOPLIST_FILE = "HA Menu/Info.plist";
590598
LD_RUNPATH_SEARCH_PATHS = (
591599
"$(inherited)",
592600
"@executable_path/../Frameworks",
593601
);
594-
MARKETING_VERSION = 2.0.2;
602+
MARKETING_VERSION = 2.0.3;
595603
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
596604
PRODUCT_NAME = "$(TARGET_NAME)";
597605
SWIFT_VERSION = 5.0;
@@ -606,15 +614,15 @@
606614
CODE_SIGN_IDENTITY = "Apple Development";
607615
CODE_SIGN_STYLE = Automatic;
608616
COMBINE_HIDPI_IMAGES = YES;
609-
CURRENT_PROJECT_VERSION = 15;
617+
CURRENT_PROJECT_VERSION = 16;
610618
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
611619
ENABLE_HARDENED_RUNTIME = YES;
612620
INFOPLIST_FILE = "HA Menu/Info.plist";
613621
LD_RUNPATH_SEARCH_PATHS = (
614622
"$(inherited)",
615623
"@executable_path/../Frameworks",
616624
);
617-
MARKETING_VERSION = 2.0.2;
625+
MARKETING_VERSION = 2.0.3;
618626
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu";
619627
PRODUCT_NAME = "$(TARGET_NAME)";
620628
SWIFT_VERSION = 5.0;
@@ -711,15 +719,15 @@
711719
CODE_SIGN_IDENTITY = "Apple Development";
712720
CODE_SIGN_STYLE = Automatic;
713721
COMBINE_HIDPI_IMAGES = YES;
714-
CURRENT_PROJECT_VERSION = 15;
722+
CURRENT_PROJECT_VERSION = 16;
715723
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
716724
ENABLE_HARDENED_RUNTIME = YES;
717725
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
718726
LD_RUNPATH_SEARCH_PATHS = (
719727
"$(inherited)",
720728
"@executable_path/../Frameworks",
721729
);
722-
MARKETING_VERSION = 2.0.2;
730+
MARKETING_VERSION = 2.0.3;
723731
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
724732
PRODUCT_NAME = "$(TARGET_NAME)";
725733
SKIP_INSTALL = YES;
@@ -735,15 +743,15 @@
735743
CODE_SIGN_IDENTITY = "Apple Development";
736744
CODE_SIGN_STYLE = Automatic;
737745
COMBINE_HIDPI_IMAGES = YES;
738-
CURRENT_PROJECT_VERSION = 15;
746+
CURRENT_PROJECT_VERSION = 16;
739747
DEVELOPMENT_TEAM = VZ3Z8BPWPW;
740748
ENABLE_HARDENED_RUNTIME = YES;
741749
INFOPLIST_FILE = "HA Menu Launcher/Info.plist";
742750
LD_RUNPATH_SEARCH_PATHS = (
743751
"$(inherited)",
744752
"@executable_path/../Frameworks",
745753
);
746-
MARKETING_VERSION = 2.0.2;
754+
MARKETING_VERSION = 2.0.3;
747755
PRODUCT_BUNDLE_IDENTIFIER = "org.codechimp.HA-Menu-Launcher";
748756
PRODUCT_NAME = "$(TARGET_NAME)";
749757
SKIP_INSTALL = YES;
@@ -800,6 +808,25 @@
800808
defaultConfigurationName = Release;
801809
};
802810
/* End XCConfigurationList section */
811+
812+
/* Begin XCRemoteSwiftPackageReference section */
813+
4904FBB723D35A6700575D29 /* XCRemoteSwiftPackageReference "FeedKit" */ = {
814+
isa = XCRemoteSwiftPackageReference;
815+
repositoryURL = "https://github.com/nmdias/FeedKit.git";
816+
requirement = {
817+
kind = upToNextMajorVersion;
818+
minimumVersion = 9.0.0;
819+
};
820+
};
821+
/* End XCRemoteSwiftPackageReference section */
822+
823+
/* Begin XCSwiftPackageProductDependency section */
824+
4904FBB823D35A6700575D29 /* FeedKit */ = {
825+
isa = XCSwiftPackageProductDependency;
826+
package = 4904FBB723D35A6700575D29 /* XCRemoteSwiftPackageReference "FeedKit" */;
827+
productName = FeedKit;
828+
};
829+
/* End XCSwiftPackageProductDependency section */
803830
};
804831
rootObject = 491F5291217CBF5200105921 /* Project object */;
805832
}

HA Menu.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HA Menu.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "[email protected]",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "[email protected]",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"scale" : "3x"
16+
}
17+
],
18+
"info" : {
19+
"version" : 1,
20+
"author" : "xcode"
21+
}
22+
}
Loading
Loading

HA Menu/MenuItemController.swift

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import Cocoa
11+
import FeedKit
1112

1213
final class MenuItemController: NSObject, NSMenuDelegate {
1314

@@ -19,8 +20,10 @@ final class MenuItemController: NSObject, NSMenuDelegate {
1920

2021
var preferences: Preferences
2122

23+
let menuItemTypeInfo = 997
2224
let menuItemTypeError = 999
2325

26+
let releaseFeedURL = URL(string: "https://hamenu.codechimp.org/releases.atom")!
2427

2528
override init() {
2629
preferences = Preferences()
@@ -35,11 +38,9 @@ final class MenuItemController: NSObject, NSMenuDelegate {
3538
// button.action = #selector(self.statusBarButtonClicked(sender:))
3639
statusButton.sendAction(on: [.leftMouseUp, .rightMouseUp])
3740
}
38-
41+
3942
buildStaticMenu()
4043

41-
updateDynamicMenuItems()
42-
4344
statusItem.menu = menu
4445

4546
menu.delegate = self
@@ -91,6 +92,7 @@ final class MenuItemController: NSObject, NSMenuDelegate {
9192
func updateDynamicMenuItems() {
9293
removeDynamicMenuItems()
9394
getStates()
95+
checkForUpdate()
9496
}
9597

9698
func getStates() {
@@ -111,7 +113,6 @@ final class MenuItemController: NSObject, NSMenuDelegate {
111113
URLSession.shared.dataTask(with: request) {data, response, error in
112114

113115
if let httpResponse = response as? HTTPURLResponse {
114-
print(httpResponse.statusCode)
115116

116117
if httpResponse.statusCode != 200 {
117118
var errorMessage: String
@@ -303,6 +304,14 @@ final class MenuItemController: NSObject, NSMenuDelegate {
303304
} while dynamicItem != nil
304305
}
305306

307+
// Info
308+
repeat {
309+
dynamicItem = self.menu.item(withTag: self.menuItemTypeInfo)
310+
if (dynamicItem != nil) {
311+
self.menu.removeItem(dynamicItem!)
312+
}
313+
} while dynamicItem != nil
314+
306315
// Errors
307316
repeat {
308317
dynamicItem = self.menu.item(withTag: self.menuItemTypeError)
@@ -421,4 +430,49 @@ final class MenuItemController: NSObject, NSMenuDelegate {
421430

422431
return request
423432
}
433+
434+
func checkForUpdate() {
435+
let parser = FeedParser(URL: releaseFeedURL)
436+
437+
parser.parseAsync { [weak self] (result) in
438+
guard let self = self else { return }
439+
switch result {
440+
case .success(let feed):
441+
442+
if let latestId = (feed.atomFeed?.entries?.first?.id!) {
443+
let idArray = latestId.components(separatedBy: "/")
444+
let latestVersion = idArray.last
445+
446+
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
447+
448+
if (latestVersion != appVersion) {
449+
DispatchQueue.main.async {
450+
// Add a seperator before static menu items
451+
self.menu.insertItem(NSMenuItem.separator(), at: 0)
452+
453+
let menuItem = NSMenuItem(title: "A new version is available", action: #selector(self.openAppWebsite(sender:)), keyEquivalent: "")
454+
menuItem.target = self
455+
456+
menuItem.tag = self.menuItemTypeInfo // Tag defines what type of item it is
457+
menuItem.image = NSImage(named: "InfoImage")
458+
459+
self.menu.insertItem(menuItem, at: 0) }
460+
}
461+
}
462+
else {
463+
print("Unable to get release feed")
464+
}
465+
466+
case .failure(let error):
467+
// Silently ignore
468+
print(error)
469+
}
470+
}
471+
}
472+
473+
@objc func openAppWebsite(sender: NSMenuItem) {
474+
if let url = URL(string: "https://hamenu.codechimp.org/releases") {
475+
NSWorkspace.shared.open(url)
476+
}
477+
}
424478
}

0 commit comments

Comments
 (0)