Skip to content

Commit af5f368

Browse files
committed
feat: Checking for updates using the leightweight updater from SwiftUtilities
1 parent ab1d565 commit af5f368

3 files changed

Lines changed: 76 additions & 12 deletions

File tree

XcodeFormat.xcodeproj/project.pbxproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
052C390F28EDFBE20034E743 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 052C390E28EDFBE20034E743 /* PreferencesWindowController.swift */; };
4848
052C391428EDFC380034E743 /* PreferencesWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 052C391628EDFC380034E743 /* PreferencesWindowController.xib */; };
4949
0532485F28EC9D5900FD02F4 /* NSApplication+LaunchServices.m in Sources */ = {isa = PBXBuildFile; fileRef = 0532485D28EC9D5900FD02F4 /* NSApplication+LaunchServices.m */; };
50+
0567243B2FE2A10E00FFAFE9 /* SwiftUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 056724382FE2A10000FFAFE9 /* SwiftUtilities.framework */; };
51+
0567243C2FE2A11400FFAFE9 /* SwiftUtilities.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 056724382FE2A10000FFAFE9 /* SwiftUtilities.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5052
05744ECE28EC2E5000A88503 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05744ECD28EC2E5000A88503 /* URL.swift */; };
5153
05744ECF28EC2E5000A88503 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05744ECD28EC2E5000A88503 /* URL.swift */; };
5254
05744ED328EC2ED400A88503 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05744ED228EC2ED400A88503 /* Data.swift */; };
@@ -105,6 +107,20 @@
105107
remoteGlobalIDString = 050E0F2728EB49210080C562;
106108
remoteInfo = EditorExtension;
107109
};
110+
056724372FE2A10000FFAFE9 /* PBXContainerItemProxy */ = {
111+
isa = PBXContainerItemProxy;
112+
containerPortal = 056724322FE2A10000FFAFE9 /* SwiftUtilities.xcodeproj */;
113+
proxyType = 2;
114+
remoteGlobalIDString = 05C527822DD8E36300843626;
115+
remoteInfo = SwiftUtilities;
116+
};
117+
056724392FE2A10000FFAFE9 /* PBXContainerItemProxy */ = {
118+
isa = PBXContainerItemProxy;
119+
containerPortal = 056724322FE2A10000FFAFE9 /* SwiftUtilities.xcodeproj */;
120+
proxyType = 2;
121+
remoteGlobalIDString = 05C5278B2DD8E36300843626;
122+
remoteInfo = SwiftUtilitiesTests;
123+
};
108124
/* End PBXContainerItemProxy section */
109125

110126
/* Begin PBXCopyFilesBuildPhase section */
@@ -148,6 +164,7 @@
148164
dstPath = "";
149165
dstSubfolderSpec = 10;
150166
files = (
167+
0567243C2FE2A11400FFAFE9 /* SwiftUtilities.framework in Copy Frameworks */,
151168
);
152169
name = "Copy Frameworks";
153170
runOnlyForDeploymentPostprocessing = 0;
@@ -255,6 +272,7 @@
255272
0532485A28EC9D5800FD02F4 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
256273
0532485D28EC9D5900FD02F4 /* NSApplication+LaunchServices.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSApplication+LaunchServices.m"; sourceTree = "<group>"; };
257274
0532485E28EC9D5900FD02F4 /* NSApplication+LaunchServices.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSApplication+LaunchServices.h"; sourceTree = "<group>"; };
275+
056724322FE2A10000FFAFE9 /* SwiftUtilities.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftUtilities.xcodeproj; path = Submodules/SwiftUtilities/SwiftUtilities.xcodeproj; sourceTree = "<group>"; };
258276
05744ECD28EC2E5000A88503 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
259277
05744ED228EC2ED400A88503 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
260278
05744ED528EC2EDB00A88503 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
@@ -287,6 +305,7 @@
287305
isa = PBXFrameworksBuildPhase;
288306
buildActionMask = 2147483647;
289307
files = (
308+
0567243B2FE2A10E00FFAFE9 /* SwiftUtilities.framework in Frameworks */,
290309
0527679428EC1B970019311B /* CryptoKit.framework in Frameworks */,
291310
A4F982ADB6427070FC3F083D /* ArgumentParser in Frameworks */,
292311
);
@@ -318,6 +337,7 @@
318337
isa = PBXGroup;
319338
children = (
320339
050E0F7828EBDF720080C562 /* README.md */,
340+
056724322FE2A10000FFAFE9 /* SwiftUtilities.xcodeproj */,
321341
050E0EBE28EB3C8B0080C562 /* xcconfig */,
322342
050E0F5C28EB659F0080C562 /* Shared */,
323343
050E0E3E28EB307B0080C562 /* XcodeFormat */,
@@ -583,6 +603,15 @@
583603
path = Shared;
584604
sourceTree = "<group>";
585605
};
606+
056724332FE2A10000FFAFE9 /* Products */ = {
607+
isa = PBXGroup;
608+
children = (
609+
056724382FE2A10000FFAFE9 /* SwiftUtilities.framework */,
610+
0567243A2FE2A10000FFAFE9 /* SwiftUtilitiesTests.xctest */,
611+
);
612+
name = Products;
613+
sourceTree = "<group>";
614+
};
586615
05C2595F28EC8A5C008BDDDE /* Extensions */ = {
587616
isa = PBXGroup;
588617
children = (
@@ -715,6 +744,12 @@
715744
);
716745
productRefGroup = 050E0E3D28EB307B0080C562 /* Products */;
717746
projectDirPath = "";
747+
projectReferences = (
748+
{
749+
ProductGroup = 056724332FE2A10000FFAFE9 /* Products */;
750+
ProjectRef = 056724322FE2A10000FFAFE9 /* SwiftUtilities.xcodeproj */;
751+
},
752+
);
718753
projectRoot = "";
719754
targets = (
720755
050E0E3B28EB307B0080C562 /* Xcode Format */,
@@ -724,6 +759,23 @@
724759
};
725760
/* End PBXProject section */
726761

762+
/* Begin PBXReferenceProxy section */
763+
056724382FE2A10000FFAFE9 /* SwiftUtilities.framework */ = {
764+
isa = PBXReferenceProxy;
765+
fileType = wrapper.framework;
766+
path = SwiftUtilities.framework;
767+
remoteRef = 056724372FE2A10000FFAFE9 /* PBXContainerItemProxy */;
768+
sourceTree = BUILT_PRODUCTS_DIR;
769+
};
770+
0567243A2FE2A10000FFAFE9 /* SwiftUtilitiesTests.xctest */ = {
771+
isa = PBXReferenceProxy;
772+
fileType = wrapper.cfbundle;
773+
path = SwiftUtilitiesTests.xctest;
774+
remoteRef = 056724392FE2A10000FFAFE9 /* PBXContainerItemProxy */;
775+
sourceTree = BUILT_PRODUCTS_DIR;
776+
};
777+
/* End PBXReferenceProxy section */
778+
727779
/* Begin PBXResourcesBuildPhase section */
728780
050E0E3A28EB307B0080C562 /* Resources */ = {
729781
isa = PBXResourcesBuildPhase;

XcodeFormat/Classes/ApplicationDelegate.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
******************************************************************************/
2424

2525
import Cocoa
26-
import GitHubUpdates
26+
import SwiftUtilities
2727

2828
/// The application delegate and menu-bar agent entry point.
2929
///
@@ -44,35 +44,35 @@ import GitHubUpdates
4444
public class ApplicationDelegate: NSObject, NSApplicationDelegate
4545
{
4646
/// Controller for the About window.
47-
private let aboutWindowController = AboutWindowController()
47+
private let aboutWindowController = AboutWindowController()
4848

4949
/// Controller for the Credits window.
50-
private let creditsWindowController = CreditsWindowController()
50+
private let creditsWindowController = CreditsWindowController()
5151

5252
/// Controller for the Configurations management window.
5353
private let configurationsWindowController = ConfigurationsWindowController()
5454

5555
/// Controller for the Preferences window.
56-
private let preferencesWindowController = PreferencesWindowController()
56+
private let preferencesWindowController = PreferencesWindowController()
5757

5858
/// Menu shown by the status-bar item, loaded from the main nib.
59-
@IBOutlet private var menu: NSMenu!
60-
61-
/// GitHub-based updater that checks for and installs new releases.
62-
@IBOutlet private var updater: GitHubUpdater!
59+
@IBOutlet private var menu: NSMenu!
6360

6461
/// Timer that periodically re-downloads the stored configurations.
65-
private var downloadTimer: Timer?
62+
private var downloadTimer: Timer?
6663

6764
/// The menu-bar status item, recreated whenever its style changes.
68-
private var statusItem: NSStatusItem?
65+
private var statusItem: NSStatusItem?
6966

7067
/// KVO token observing changes to the stored configuration list.
71-
private var configurationsObserver: NSKeyValueObservation?
68+
private var configurationsObserver: NSKeyValueObservation?
7269

7370
/// KVO token observing changes to the selected configuration.
7471
private var selectedConfigurationsObserver: NSKeyValueObservation?
7572

73+
/// GitHub-based updater that checks for and installs new releases.
74+
private var updater = GitHubUpdater( owner: "macmade", repository: "XcodeFormat" )
75+
7676
/// Whether the status item shows the active configuration's name.
7777
///
7878
/// Backed by `UserDefaults`; changing it persists the value and rebuilds
@@ -162,7 +162,7 @@ public class ApplicationDelegate: NSObject, NSApplicationDelegate
162162

163163
DispatchQueue.main.asyncAfter( deadline: .now() + .seconds( 2 ) )
164164
{
165-
self.updater.checkForUpdatesInBackground()
165+
self.updater?.checkForUpdatesInBackground()
166166
}
167167

168168
self.downloadTimer = Timer.scheduledTimer( withTimeInterval: 3600, repeats: true )
@@ -440,4 +440,13 @@ public class ApplicationDelegate: NSObject, NSApplicationDelegate
440440

441441
NSWorkspace.shared.open( url )
442442
}
443+
444+
/// Checks whether a new release is available on GitHub and opens the release page in
445+
///
446+
/// - Parameter sender: The control that triggered the action.
447+
@IBAction
448+
public func checkForUpdates( _ sender: Any? )
449+
{
450+
self.updater?.checkForUpdates()
451+
}
443452
}

XcodeFormat/UI/Base.lproj/MainMenu.xib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@
709709
</menuItem>
710710
<menuItem title="Check for Updates..." id="LhN-1W-uwb">
711711
<modifierMask key="keyEquivalentModifierMask"/>
712+
<connections>
713+
<action selector="checkForUpdates:" target="Voe-Tx-rLC" id="53G-1d-b9l"/>
714+
</connections>
712715
</menuItem>
713716
<menuItem isSeparatorItem="YES" id="IkI-vw-vU1"/>
714717
<menuItem title="About Xcode Format..." id="KU9-Wy-x5J">

0 commit comments

Comments
 (0)