Skip to content

Commit ef3565f

Browse files
committed
Merge branch 'release/0.3.1'
2 parents c3cfecd + f011806 commit ef3565f

9 files changed

Lines changed: 147 additions & 82 deletions

File tree

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@
695695
CODE_SIGN_ENTITLEMENTS = "Copilot for Xcode/Copilot_for_Xcode.entitlements";
696696
CODE_SIGN_STYLE = Automatic;
697697
COMBINE_HIDPI_IMAGES = YES;
698-
CURRENT_PROJECT_VERSION = 9;
698+
CURRENT_PROJECT_VERSION = 11;
699699
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
700700
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
701701
ENABLE_HARDENED_RUNTIME = YES;
@@ -709,7 +709,7 @@
709709
"@executable_path/../Frameworks",
710710
);
711711
MACOSX_DEPLOYMENT_TARGET = 12.0;
712-
MARKETING_VERSION = 0.3.0;
712+
MARKETING_VERSION = 0.3.1;
713713
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE)";
714714
PRODUCT_MODULE_NAME = Copilot_for_Xcode;
715715
PRODUCT_NAME = "Copilot for Xcode Dev";
@@ -727,7 +727,7 @@
727727
CODE_SIGN_ENTITLEMENTS = "Copilot for Xcode/Copilot_for_Xcode.entitlements";
728728
CODE_SIGN_STYLE = Automatic;
729729
COMBINE_HIDPI_IMAGES = YES;
730-
CURRENT_PROJECT_VERSION = 9;
730+
CURRENT_PROJECT_VERSION = 11;
731731
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
732732
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
733733
ENABLE_HARDENED_RUNTIME = YES;
@@ -741,7 +741,7 @@
741741
"@executable_path/../Frameworks",
742742
);
743743
MACOSX_DEPLOYMENT_TARGET = 12.0;
744-
MARKETING_VERSION = 0.3.0;
744+
MARKETING_VERSION = 0.3.1;
745745
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE)";
746746
PRODUCT_NAME = "Copilot for Xcode";
747747
SWIFT_EMIT_LOC_STRINGS = YES;

Copilot for Xcode/CopilotView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct CopilotView: View {
1111
@State var userCode: String?
1212
@State var version: String?
1313
@State var isRunningAction: Bool = false
14+
@State var isUserCodeCopiedAlertPresented = false
1415

1516
var body: some View {
1617
Section {
@@ -25,6 +26,13 @@ struct CopilotView: View {
2526
Button("Refresh") { checkStatus() }
2627
if copilotStatus == .notSignedIn {
2728
Button("Sign In") { signIn() }
29+
.alert(isPresented: $isUserCodeCopiedAlertPresented) {
30+
Alert(
31+
title: Text(userCode ?? ""),
32+
message: Text("The user code is pasted into your clipboard, please paste it in the opened website to login.\nAfter that, click \"Confirm Sign-in\" to finish."),
33+
dismissButton: .default(Text("OK"))
34+
)
35+
}
2836
Button("Confirm Sign-in") { confirmSignIn() }
2937
}
3038
if copilotStatus == .ok || copilotStatus == .alreadySignedIn || copilotStatus == .notAuthorized {
@@ -89,6 +97,7 @@ struct CopilotView: View {
8997
pasteboard.setString(userCode, forType: NSPasteboard.PasteboardType.string)
9098
message = "Usercode \(userCode) already copied!"
9199
openURL(url)
100+
isUserCodeCopiedAlertPresented = true
92101
} catch {
93102
message = error.localizedDescription
94103
}

Copilot for Xcode/InstructionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Text("""
1515
1. Install Node.
1616
2. Click `Set Up Launch Agent` to set up an XPC service to run in the background.
1717
3. Refresh Copilot status or restart the app.
18-
4. Click `Sign In` to sign into your GitHub Account.
18+
4. Click `Sign In` to sign into your GitHub account.
1919
5. After submitting your user code to the verification website, click `Confirm Sign-in` to finish the sign-in.
2020
6. Go to `Settings.app > Privacy & Security > Extension > Xcode Source Editor Extension` to turn **Copilot for Xcode** on.
2121
7. Restart Xcode, the Copilot commands should be available in the menu bar.

Copilot for Xcode/LaunchAgentView.swift

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,86 @@
11
import SwiftUI
2+
import XPCShared
23

34
struct LaunchAgentView: View {
45
@State var errorMessage: String?
56
@State var isDidRemoveLaunchAgentAlertPresented = false
67
@State var isDidSetupLaunchAgentAlertPresented = false
78
@State var isDidRestartLaunchAgentAlertPresented = false
8-
9+
@AppStorage(SettingsKey.nodePath, store: .shared) var nodePath: String = ""
10+
911
var body: some View {
1012
Section {
11-
HStack {
12-
Button(action: {
13-
do {
14-
try LaunchAgentManager().setupLaunchAgent()
15-
isDidSetupLaunchAgentAlertPresented = true
16-
} catch {
17-
errorMessage = error.localizedDescription
13+
VStack(alignment: .leading, spacing: 8) {
14+
HStack {
15+
Button(action: {
16+
do {
17+
try LaunchAgentManager().setupLaunchAgent()
18+
isDidSetupLaunchAgentAlertPresented = true
19+
} catch {
20+
errorMessage = error.localizedDescription
21+
}
22+
}) {
23+
Text("Set Up Launch Agent for XPC Service")
1824
}
19-
}) {
20-
Text("Set Up Launch Agent for XPC Service")
21-
}
22-
.alert(isPresented: $isDidSetupLaunchAgentAlertPresented) {
23-
.init(
24-
title: Text("Finished Launch Agent Setup"),
25-
message: Text(
26-
"You may need to restart Xcode to make the extension work."
27-
),
28-
dismissButton: .default(Text("OK"))
29-
)
30-
}
31-
32-
Button(action: {
33-
do {
34-
try LaunchAgentManager().removeLaunchAgent()
35-
isDidRemoveLaunchAgentAlertPresented = true
36-
} catch {
37-
errorMessage = error.localizedDescription
25+
.alert(isPresented: $isDidSetupLaunchAgentAlertPresented) {
26+
.init(
27+
title: Text("Finished Launch Agent Setup"),
28+
message: Text(
29+
"You may need to restart Xcode to make the extension work."
30+
),
31+
dismissButton: .default(Text("OK"))
32+
)
3833
}
39-
}) {
40-
Text("Remove Launch Agent")
41-
}
42-
.alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) {
43-
.init(
44-
title: Text("Launch Agent Removed"),
45-
dismissButton: .default(Text("OK"))
46-
)
47-
}
48-
49-
Button(action: {
50-
LaunchAgentManager().restartLaunchAgent()
51-
isDidRestartLaunchAgentAlertPresented = true
52-
}) {
53-
Text("Restart XPC Service")
54-
}.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) {
55-
.init(
56-
title: Text("Launch Agent Restarted"),
57-
dismissButton: .default(Text("OK"))
58-
)
59-
}
6034

61-
EmptyView()
62-
.alert(isPresented: .init(
63-
get: { errorMessage != nil },
64-
set: { yes in
65-
if !yes { errorMessage = nil }
35+
Button(action: {
36+
do {
37+
try LaunchAgentManager().removeLaunchAgent()
38+
isDidRemoveLaunchAgentAlertPresented = true
39+
} catch {
40+
errorMessage = error.localizedDescription
6641
}
67-
)) {
42+
}) {
43+
Text("Remove Launch Agent")
44+
}
45+
.alert(isPresented: $isDidRemoveLaunchAgentAlertPresented) {
46+
.init(
47+
title: Text("Launch Agent Removed"),
48+
dismissButton: .default(Text("OK"))
49+
)
50+
}
51+
52+
Button(action: {
53+
LaunchAgentManager().restartLaunchAgent()
54+
isDidRestartLaunchAgentAlertPresented = true
55+
}) {
56+
Text("Restart XPC Service")
57+
}.alert(isPresented: $isDidRestartLaunchAgentAlertPresented) {
6858
.init(
69-
title: Text("Failed. Got to the GitHub page for Help"),
70-
message: Text(errorMessage ?? "Unknown Error"),
59+
title: Text("Launch Agent Restarted"),
7160
dismissButton: .default(Text("OK"))
7261
)
7362
}
63+
64+
EmptyView()
65+
.alert(isPresented: .init(
66+
get: { errorMessage != nil },
67+
set: { yes in
68+
if !yes { errorMessage = nil }
69+
}
70+
)) {
71+
.init(
72+
title: Text("Failed. Got to the GitHub page for Help"),
73+
message: Text(errorMessage ?? "Unknown Error"),
74+
dismissButton: .default(Text("OK"))
75+
)
76+
}
77+
}
78+
79+
HStack {
80+
Text("Path to Node: ")
81+
TextField("node", text: $nodePath)
82+
.textFieldStyle(.copilot)
83+
}
7484
}
7585
}.buttonStyle(.copilot)
7686
}

Copilot for Xcode/Styles.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct CopilotButtonStyle: ButtonStyle {
55
configuration.label
66
.padding(.vertical, 4)
77
.padding(.horizontal, 8)
8+
.foregroundColor(.white)
89
.background(
910
RoundedRectangle(cornerRadius: 4, style: .continuous)
1011
.fill(
@@ -24,3 +25,40 @@ struct CopilotButtonStyle: ButtonStyle {
2425
extension ButtonStyle where Self == CopilotButtonStyle {
2526
static var copilot: CopilotButtonStyle { CopilotButtonStyle() }
2627
}
28+
29+
struct CopilotTextFieldStyle: TextFieldStyle {
30+
func _body(configuration: TextField<_Label>) -> some View {
31+
configuration
32+
.colorScheme(.dark)
33+
.textFieldStyle(.plain)
34+
.foregroundColor(.white)
35+
.padding(.vertical, 4)
36+
.padding(.horizontal, 8)
37+
.background(
38+
RoundedRectangle(cornerRadius: 4, style: .continuous)
39+
.fill(.white.opacity(0.2))
40+
)
41+
.overlay {
42+
RoundedRectangle(cornerRadius: 4, style: .continuous)
43+
.stroke(.white.opacity(0.2), style: .init(lineWidth: 1))
44+
}
45+
}
46+
}
47+
48+
extension TextFieldStyle where Self == CopilotTextFieldStyle {
49+
static var copilot: CopilotTextFieldStyle { CopilotTextFieldStyle() }
50+
}
51+
52+
struct CopilotStyle_Previews: PreviewProvider {
53+
static var previews: some View {
54+
VStack(alignment: .leading, spacing: 8) {
55+
Button("Button") {}
56+
.buttonStyle(.copilot)
57+
58+
TextField("title", text: .constant("Placeholder"))
59+
.textFieldStyle(.copilot)
60+
}
61+
.padding(.all, 8)
62+
.background(Color.black)
63+
}
64+
}

Core/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
),
1414
.library(
1515
name: "Client",
16-
targets: ["CopilotModel", "Client"]
16+
targets: ["CopilotModel", "Client", "XPCShared"]
1717
),
1818
],
1919
dependencies: [
@@ -22,7 +22,7 @@ let package = Package(
2222
targets: [
2323
.target(
2424
name: "CopilotService",
25-
dependencies: ["LanguageClient", "CopilotModel"]
25+
dependencies: ["LanguageClient", "CopilotModel", "XPCShared"]
2626
),
2727
.testTarget(
2828
name: "CopilotServiceTests",

Core/Sources/CopilotService/CopilotService.swift

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import CopilotModel
22
import Foundation
33
import LanguageClient
44
import LanguageServerProtocol
5+
import XPCShared
56

67
public protocol CopilotAuthServiceType {
78
func checkStatus() async throws -> CopilotStatus
@@ -40,22 +41,25 @@ public class CopilotBaseService {
4041
try? FileManager.default
4142
.createDirectory(at: supportURL, withIntermediateDirectories: false)
4243
}
43-
let executionParams = Process.ExecutionParameters(
44-
path: "/usr/bin/env",
45-
arguments: [
46-
"node",
47-
Bundle.main.url(
48-
forResource: "agent",
49-
withExtension: "js",
50-
subdirectory: "copilot/dist"
51-
)!.path,
52-
"--stdio",
53-
],
54-
environment: [
55-
"PATH": "/usr/bin:/usr/local/bin",
56-
],
57-
currentDirectoryURL: supportURL
58-
)
44+
let executionParams = {
45+
let nodePath = UserDefaults.shared.string(forKey: SettingsKey.nodePath) ?? ""
46+
return Process.ExecutionParameters(
47+
path: "/usr/bin/env",
48+
arguments: [
49+
nodePath.isEmpty ? "node" : nodePath,
50+
Bundle.main.url(
51+
forResource: "agent",
52+
withExtension: "js",
53+
subdirectory: "copilot/dist"
54+
)!.path,
55+
"--stdio",
56+
],
57+
environment: [
58+
"PATH": "/usr/bin:/usr/local/bin",
59+
],
60+
currentDirectoryURL: supportURL
61+
)
62+
}()
5963
let localServer = LocalProcessServer(executionParameters: executionParams)
6064
localServer.logMessages = false
6165
let server = InitializingServer(server: localServer)
@@ -85,11 +89,11 @@ public class CopilotBaseService {
8589
workspaceFolders: nil
8690
)
8791
}
88-
92+
8993
server.notificationHandler = { _, respond in
9094
respond(nil)
9195
}
92-
96+
9397
return server
9498
}()
9599
}

Core/Sources/XPCShared/UserDefaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ import Foundation
33
public extension UserDefaults {
44
static var shared = UserDefaults(suiteName: "5YKZ4Y3DAW.group.com.intii.CopilotForXcode")!
55
}
6+
7+
public enum SettingsKey {
8+
public static let nodePath = "NodePath"
9+
}

EditorExtension/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<key>CFBundlePackageType</key>
1212
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1313
<key>CFBundleDisplayName</key>
14-
<string>$(EXTESNION_BUNDLE_NAME)</string>
14+
<string>$(EXTENSION_BUNDLE_NAME)</string>
1515
<key>CFBundleExecutable</key>
1616
<string>$(EXECUTABLE_NAME)</string>
1717
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)