@@ -15,10 +15,10 @@ struct CopilotView: View {
1515 }
1616
1717 @Environment ( \. openURL) var openURL
18+ @Environment ( \. toast) var toast
1819 @StateObject var settings = Settings ( )
1920
2021 @State var copilotStatus : GitHubCopilotAccountStatus ?
21- @State var message : String ?
2222 @State var userCode : String ?
2323 @State var version : String ?
2424 @State var isRunningAction : Bool = false
@@ -47,16 +47,18 @@ struct CopilotView: View {
4747 Text ( " Run Node with " )
4848 }
4949
50- Text (
51- " You may have to restart the helper app to apply the changes. To do so, simply close the helper app by clicking on the menu bar icon that looks like a steer wheel, it will automatically restart as needed. "
52- )
53- . foregroundColor ( . secondary)
50+ VStack { // workaround a layout issue of SwiftUI
51+ Text (
52+ " You may have to restart the helper app to apply the changes. To do so, simply close the helper app by clicking on the menu bar icon that looks like a steer wheel, it will automatically restart as needed. "
53+ )
54+ . foregroundColor ( . secondary)
55+ }
5456 }
5557
5658 VStack ( alignment: . leading) {
5759 Text ( " Copilot Version: \( version ?? " Loading.. " ) " )
5860 Text ( " Status: \( copilotStatus? . description ?? " Loading.. " ) " )
59-
61+
6062 HStack ( alignment: . center) {
6163 Button ( " Refresh " ) { checkStatus ( ) }
6264 if copilotStatus == . notSignedIn {
@@ -92,17 +94,6 @@ struct CopilotView: View {
9294 }
9395 }
9496 Spacer ( )
95- } . overlay ( alignment: . topTrailing) {
96- if let message {
97- Text ( message)
98- . padding ( . horizontal, 4 )
99- . padding ( . vertical, 2 )
100- . background (
101- RoundedRectangle ( cornerRadius: 4 )
102- . fill ( Color . red)
103- )
104- . frame ( maxWidth: 200 , alignment: . topTrailing)
105- }
10697 } . onAppear {
10798 if isPreview { return }
10899 checkStatus ( )
@@ -118,8 +109,17 @@ struct CopilotView: View {
118109 copilotStatus = try await service. checkStatus ( )
119110 version = try await service. getVersion ( )
120111 isRunningAction = false
112+
113+ if copilotStatus != . ok {
114+ toast (
115+ Text (
116+ " GitHub Copilot status is not \" ok \" . Please check if you have a valid GitHub Copilot subscription. "
117+ ) ,
118+ . error
119+ )
120+ }
121121 } catch {
122- message = error. localizedDescription
122+ toast ( Text ( error. localizedDescription) , . error )
123123 }
124124 }
125125 }
@@ -133,17 +133,17 @@ struct CopilotView: View {
133133 let ( uri, userCode) = try await service. signInInitiate ( )
134134 self . userCode = userCode
135135 guard let url = URL ( string: uri) else {
136- message = " Verification URI is incorrect. "
136+ toast ( Text ( " Verification URI is incorrect. " ) , . error )
137137 return
138138 }
139139 let pasteboard = NSPasteboard . general
140140 pasteboard. declareTypes ( [ NSPasteboard . PasteboardType. string] , owner: nil )
141141 pasteboard. setString ( userCode, forType: NSPasteboard . PasteboardType. string)
142- message = " Usercode \( userCode) already copied! "
142+ toast ( Text ( " Usercode \( userCode) already copied! " ) , . info )
143143 openURL ( url)
144144 isUserCodeCopiedAlertPresented = true
145145 } catch {
146- message = error. localizedDescription
146+ toast ( Text ( error. localizedDescription) , . error )
147147 }
148148 }
149149 }
@@ -155,14 +155,14 @@ struct CopilotView: View {
155155 do {
156156 let service = try getService ( )
157157 guard let userCode else {
158- message = " Usercode is empty. "
158+ toast ( Text ( " Usercode is empty. " ) , . error )
159159 return
160160 }
161161 let ( username, status) = try await service. signInConfirm ( userCode: userCode)
162162 self . settings. username = username
163163 copilotStatus = status
164164 } catch {
165- message = error. localizedDescription
165+ toast ( Text ( error. localizedDescription) , . error )
166166 }
167167 }
168168 }
@@ -175,7 +175,7 @@ struct CopilotView: View {
175175 let service = try getService ( )
176176 copilotStatus = try await service. signOut ( )
177177 } catch {
178- message = error. localizedDescription
178+ toast ( Text ( error. localizedDescription) , . error )
179179 }
180180 }
181181 }
@@ -200,12 +200,6 @@ struct CopilotView_Previews: PreviewProvider {
200200 static var previews : some View {
201201 VStack ( alignment: . leading, spacing: 8 ) {
202202 CopilotView ( copilotStatus: . notSignedIn, version: " 1.0.0 " )
203-
204- CopilotView (
205- copilotStatus: . alreadySignedIn,
206- message: " Error "
207- )
208-
209203 CopilotView ( copilotStatus: . alreadySignedIn, isRunningAction: true )
210204 }
211205 . frame ( height: 800 )
0 commit comments