Skip to content

Commit 8ef075b

Browse files
committed
Add a helper target to handle reloading launch agent
1 parent 6727623 commit 8ef075b

File tree

7 files changed

+301
-31
lines changed

7 files changed

+301
-31
lines changed

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
C8189B1C2938972F00C9DCDA /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8189B1B2938972F00C9DCDA /* ContentView.swift */; };
2121
C8189B1E2938973000C9DCDA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C8189B1D2938973000C9DCDA /* Assets.xcassets */; };
2222
C8189B212938973000C9DCDA /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C8189B202938973000C9DCDA /* Preview Assets.xcassets */; };
23+
C8216B73298036EC00AD38C7 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8216B72298036EC00AD38C7 /* main.swift */; };
24+
C8216B782980370100AD38C7 /* ReloadLaunchAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8216B772980370100AD38C7 /* ReloadLaunchAgent.swift */; };
25+
C8216B7D2980374300AD38C7 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = C8216B7C2980374300AD38C7 /* ArgumentParser */; };
26+
C8216B802980378300AD38C7 /* Helper in Embed XPCService */ = {isa = PBXBuildFile; fileRef = C8216B70298036EC00AD38C7 /* Helper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
2327
C832A47C2940C73E000989F2 /* copilot in Copy LanguageServer for Dev */ = {isa = PBXBuildFile; fileRef = C832A47B2940C71D000989F2 /* copilot */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
2428
C832A47D2940C74E000989F2 /* copilot in CopyFiles */ = {isa = PBXBuildFile; fileRef = C832A47B2940C71D000989F2 /* copilot */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
2529
C83B2B7A293D9C8C00C5ACCD /* LaunchAgentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83B2B79293D9C8C00C5ACCD /* LaunchAgentManager.swift */; };
@@ -51,6 +55,13 @@
5155
remoteGlobalIDString = C814588B2939EFDC00135263;
5256
remoteInfo = EditorExtension;
5357
};
58+
C8216B7E2980377E00AD38C7 /* PBXContainerItemProxy */ = {
59+
isa = PBXContainerItemProxy;
60+
containerPortal = C8189B0E2938972F00C9DCDA /* Project object */;
61+
proxyType = 1;
62+
remoteGlobalIDString = C8216B6F298036EC00AD38C7;
63+
remoteInfo = Helper;
64+
};
5465
C8520304293CF0D400460097 /* PBXContainerItemProxy */ = {
5566
isa = PBXContainerItemProxy;
5667
containerPortal = C8189B0E2938972F00C9DCDA /* Project object */;
@@ -81,12 +92,22 @@
8192
);
8293
runOnlyForDeploymentPostprocessing = 1;
8394
};
95+
C8216B6E298036EC00AD38C7 /* CopyFiles */ = {
96+
isa = PBXCopyFilesBuildPhase;
97+
buildActionMask = 2147483647;
98+
dstPath = /usr/share/man/man1/;
99+
dstSubfolderSpec = 0;
100+
files = (
101+
);
102+
runOnlyForDeploymentPostprocessing = 1;
103+
};
84104
C8520306293CF0EF00460097 /* Embed XPCService */ = {
85105
isa = PBXCopyFilesBuildPhase;
86106
buildActionMask = 2147483647;
87107
dstPath = "";
88108
dstSubfolderSpec = 6;
89109
files = (
110+
C8216B802980378300AD38C7 /* Helper in Embed XPCService */,
90111
C8520307293CF13600460097 /* CopilotForXcodeXPCService in Embed XPCService */,
91112
);
92113
name = "Embed XPCService";
@@ -151,6 +172,9 @@
151172
C8189B222938973000C9DCDA /* Copilot_for_Xcode.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Copilot_for_Xcode.entitlements; sourceTree = "<group>"; };
152173
C8189B282938979000C9DCDA /* Core */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Core; sourceTree = "<group>"; };
153174
C81E867D296FE4420026E908 /* Version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
175+
C8216B70298036EC00AD38C7 /* Helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Helper; sourceTree = BUILT_PRODUCTS_DIR; };
176+
C8216B72298036EC00AD38C7 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
177+
C8216B772980370100AD38C7 /* ReloadLaunchAgent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadLaunchAgent.swift; sourceTree = "<group>"; };
154178
C832A47B2940C71D000989F2 /* copilot */ = {isa = PBXFileReference; lastKnownFileType = folder; name = copilot; path = copilot.vim/copilot; sourceTree = "<group>"; };
155179
C83B2B79293D9C8C00C5ACCD /* LaunchAgentManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchAgentManager.swift; sourceTree = "<group>"; };
156180
C83B2B7B293D9FB400C5ACCD /* CopilotView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopilotView.swift; sourceTree = "<group>"; };
@@ -198,6 +222,14 @@
198222
);
199223
runOnlyForDeploymentPostprocessing = 0;
200224
};
225+
C8216B6D298036EC00AD38C7 /* Frameworks */ = {
226+
isa = PBXFrameworksBuildPhase;
227+
buildActionMask = 2147483647;
228+
files = (
229+
C8216B7D2980374300AD38C7 /* ArgumentParser in Frameworks */,
230+
);
231+
runOnlyForDeploymentPostprocessing = 0;
232+
};
201233
/* End PBXFrameworksBuildPhase section */
202234

203235
/* Begin PBXGroup section */
@@ -254,6 +286,7 @@
254286
C8189B182938972F00C9DCDA /* Copilot for Xcode */,
255287
C81458922939EFDC00135263 /* EditorExtension */,
256288
C81458B6293A015C00135263 /* XPCService */,
289+
C8216B71298036EC00AD38C7 /* Helper */,
257290
C814588D2939EFDC00135263 /* Frameworks */,
258291
C8189B172938972F00C9DCDA /* Products */,
259292
);
@@ -265,6 +298,7 @@
265298
C8189B162938972F00C9DCDA /* Copilot for Xcode Dev.app */,
266299
C814588C2939EFDC00135263 /* Copilot.appex */,
267300
C81458B5293A015C00135263 /* CopilotForXcodeXPCService */,
301+
C8216B70298036EC00AD38C7 /* Helper */,
268302
);
269303
name = Products;
270304
sourceTree = "<group>";
@@ -297,6 +331,15 @@
297331
path = "Preview Content";
298332
sourceTree = "<group>";
299333
};
334+
C8216B71298036EC00AD38C7 /* Helper */ = {
335+
isa = PBXGroup;
336+
children = (
337+
C8216B72298036EC00AD38C7 /* main.swift */,
338+
C8216B772980370100AD38C7 /* ReloadLaunchAgent.swift */,
339+
);
340+
path = Helper;
341+
sourceTree = "<group>";
342+
};
300343
/* End PBXGroup section */
301344

302345
/* Begin PBXNativeTarget section */
@@ -356,6 +399,7 @@
356399
buildRules = (
357400
);
358401
dependencies = (
402+
C8216B7F2980377E00AD38C7 /* PBXTargetDependency */,
359403
C8520305293CF0D400460097 /* PBXTargetDependency */,
360404
C814589A2939EFDC00135263 /* PBXTargetDependency */,
361405
);
@@ -367,6 +411,26 @@
367411
productReference = C8189B162938972F00C9DCDA /* Copilot for Xcode Dev.app */;
368412
productType = "com.apple.product-type.application";
369413
};
414+
C8216B6F298036EC00AD38C7 /* Helper */ = {
415+
isa = PBXNativeTarget;
416+
buildConfigurationList = C8216B74298036EC00AD38C7 /* Build configuration list for PBXNativeTarget "Helper" */;
417+
buildPhases = (
418+
C8216B6C298036EC00AD38C7 /* Sources */,
419+
C8216B6D298036EC00AD38C7 /* Frameworks */,
420+
C8216B6E298036EC00AD38C7 /* CopyFiles */,
421+
);
422+
buildRules = (
423+
);
424+
dependencies = (
425+
);
426+
name = Helper;
427+
packageProductDependencies = (
428+
C8216B7C2980374300AD38C7 /* ArgumentParser */,
429+
);
430+
productName = Helper;
431+
productReference = C8216B70298036EC00AD38C7 /* Helper */;
432+
productType = "com.apple.product-type.tool";
433+
};
370434
/* End PBXNativeTarget section */
371435

372436
/* Begin PBXProject section */
@@ -386,6 +450,9 @@
386450
C8189B152938972F00C9DCDA = {
387451
CreatedOnToolsVersion = 14.1;
388452
};
453+
C8216B6F298036EC00AD38C7 = {
454+
CreatedOnToolsVersion = 14.1;
455+
};
389456
};
390457
};
391458
buildConfigurationList = C8189B112938972F00C9DCDA /* Build configuration list for PBXProject "Copilot for Xcode" */;
@@ -397,13 +464,17 @@
397464
Base,
398465
);
399466
mainGroup = C8189B0D2938972F00C9DCDA;
467+
packageReferences = (
468+
C8216B792980373800AD38C7 /* XCRemoteSwiftPackageReference "swift-argument-parser" */,
469+
);
400470
productRefGroup = C8189B172938972F00C9DCDA /* Products */;
401471
projectDirPath = "";
402472
projectRoot = "";
403473
targets = (
404474
C8189B152938972F00C9DCDA /* Copilot for Xcode */,
405475
C814588B2939EFDC00135263 /* EditorExtension */,
406476
C81458B4293A015C00135263 /* XPCService */,
477+
C8216B6F298036EC00AD38C7 /* Helper */,
407478
);
408479
};
409480
/* End PBXProject section */
@@ -471,6 +542,15 @@
471542
);
472543
runOnlyForDeploymentPostprocessing = 0;
473544
};
545+
C8216B6C298036EC00AD38C7 /* Sources */ = {
546+
isa = PBXSourcesBuildPhase;
547+
buildActionMask = 2147483647;
548+
files = (
549+
C8216B73298036EC00AD38C7 /* main.swift in Sources */,
550+
C8216B782980370100AD38C7 /* ReloadLaunchAgent.swift in Sources */,
551+
);
552+
runOnlyForDeploymentPostprocessing = 0;
553+
};
474554
/* End PBXSourcesBuildPhase section */
475555

476556
/* Begin PBXTargetDependency section */
@@ -479,6 +559,11 @@
479559
target = C814588B2939EFDC00135263 /* EditorExtension */;
480560
targetProxy = C81458992939EFDC00135263 /* PBXContainerItemProxy */;
481561
};
562+
C8216B7F2980377E00AD38C7 /* PBXTargetDependency */ = {
563+
isa = PBXTargetDependency;
564+
target = C8216B6F298036EC00AD38C7 /* Helper */;
565+
targetProxy = C8216B7E2980377E00AD38C7 /* PBXContainerItemProxy */;
566+
};
482567
C8520305293CF0D400460097 /* PBXTargetDependency */ = {
483568
isa = PBXTargetDependency;
484569
target = C81458B4293A015C00135263 /* XPCService */;
@@ -757,6 +842,32 @@
757842
};
758843
name = Release;
759844
};
845+
C8216B75298036EC00AD38C7 /* Debug */ = {
846+
isa = XCBuildConfiguration;
847+
buildSettings = {
848+
CODE_SIGN_STYLE = Automatic;
849+
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
850+
ENABLE_HARDENED_RUNTIME = YES;
851+
MACOSX_DEPLOYMENT_TARGET = 12.0;
852+
PRODUCT_NAME = "$(TARGET_NAME)";
853+
SKIP_INSTALL = YES;
854+
SWIFT_VERSION = 5.0;
855+
};
856+
name = Debug;
857+
};
858+
C8216B76298036EC00AD38C7 /* Release */ = {
859+
isa = XCBuildConfiguration;
860+
buildSettings = {
861+
CODE_SIGN_STYLE = Automatic;
862+
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
863+
ENABLE_HARDENED_RUNTIME = YES;
864+
MACOSX_DEPLOYMENT_TARGET = 12.0;
865+
PRODUCT_NAME = "$(TARGET_NAME)";
866+
SKIP_INSTALL = YES;
867+
SWIFT_VERSION = 5.0;
868+
};
869+
name = Release;
870+
};
760871
/* End XCBuildConfiguration section */
761872

762873
/* Begin XCConfigurationList section */
@@ -796,9 +907,34 @@
796907
defaultConfigurationIsVisible = 0;
797908
defaultConfigurationName = Release;
798909
};
910+
C8216B74298036EC00AD38C7 /* Build configuration list for PBXNativeTarget "Helper" */ = {
911+
isa = XCConfigurationList;
912+
buildConfigurations = (
913+
C8216B75298036EC00AD38C7 /* Debug */,
914+
C8216B76298036EC00AD38C7 /* Release */,
915+
);
916+
defaultConfigurationIsVisible = 0;
917+
defaultConfigurationName = Release;
918+
};
799919
/* End XCConfigurationList section */
800920

921+
/* Begin XCRemoteSwiftPackageReference section */
922+
C8216B792980373800AD38C7 /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = {
923+
isa = XCRemoteSwiftPackageReference;
924+
repositoryURL = "https://github.com/apple/swift-argument-parser.git";
925+
requirement = {
926+
kind = upToNextMajorVersion;
927+
minimumVersion = 1.0.0;
928+
};
929+
};
930+
/* End XCRemoteSwiftPackageReference section */
931+
801932
/* Begin XCSwiftPackageProductDependency section */
933+
C8216B7C2980374300AD38C7 /* ArgumentParser */ = {
934+
isa = XCSwiftPackageProductDependency;
935+
package = C8216B792980373800AD38C7 /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
936+
productName = ArgumentParser;
937+
};
802938
C8821759294187E100A22FD3 /* Client */ = {
803939
isa = XCSwiftPackageProductDependency;
804940
productName = Client;

Copilot for Xcode.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Copilot for Xcode/LaunchAgentView.swift

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ struct LaunchAgentView: View {
1414
VStack(alignment: .leading, spacing: 8) {
1515
HStack {
1616
Button(action: {
17-
do {
18-
try LaunchAgentManager().setupLaunchAgent()
19-
isDidSetupLaunchAgentAlertPresented = true
20-
} catch {
21-
errorMessage = error.localizedDescription
17+
Task {
18+
do {
19+
try await LaunchAgentManager().setupLaunchAgent()
20+
isDidSetupLaunchAgentAlertPresented = true
21+
} catch {
22+
errorMessage = error.localizedDescription
23+
}
2224
}
2325
}) {
2426
Text("Set Up Launch Agent for XPC Service")
@@ -27,18 +29,20 @@ struct LaunchAgentView: View {
2729
.init(
2830
title: Text("Finished Launch Agent Setup"),
2931
message: Text(
30-
"You may need to restart Xcode to make the extension work."
32+
"Please refresh the Copilot status. (The first refresh may fail)"
3133
),
3234
dismissButton: .default(Text("OK"))
3335
)
3436
}
3537

3638
Button(action: {
37-
do {
38-
try LaunchAgentManager().removeLaunchAgent()
39-
isDidRemoveLaunchAgentAlertPresented = true
40-
} catch {
41-
errorMessage = error.localizedDescription
39+
Task {
40+
do {
41+
try await LaunchAgentManager().removeLaunchAgent()
42+
isDidRemoveLaunchAgentAlertPresented = true
43+
} catch {
44+
errorMessage = error.localizedDescription
45+
}
4246
}
4347
}) {
4448
Text("Remove Launch Agent")
@@ -51,8 +55,14 @@ struct LaunchAgentView: View {
5155
}
5256

5357
Button(action: {
54-
LaunchAgentManager().restartLaunchAgent()
55-
isDidRestartLaunchAgentAlertPresented = true
58+
Task {
59+
do {
60+
try await LaunchAgentManager().restartLaunchAgent()
61+
isDidRestartLaunchAgentAlertPresented = true
62+
} catch {
63+
errorMessage = error.localizedDescription
64+
}
65+
}
5666
}) {
5767
Text("Restart XPC Service")
5868
}.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) {
@@ -62,15 +72,13 @@ struct LaunchAgentView: View {
6272
)
6373
}
6474

65-
EmptyView()
75+
Spacer()
6676
.alert(isPresented: .init(
6777
get: { errorMessage != nil },
68-
set: { yes in
69-
if !yes { errorMessage = nil }
70-
}
78+
set: { _ in errorMessage = nil }
7179
)) {
7280
.init(
73-
title: Text("Failed. Got to the GitHub page for Help"),
81+
title: Text("Failed"),
7482
message: Text(errorMessage ?? "Unknown Error"),
7583
dismissButton: .default(Text("OK"))
7684
)

0 commit comments

Comments
 (0)