1
1
package com.coder.gateway.views.steps
2
2
3
3
import com.coder.gateway.CoderGatewayBundle
4
+ import com.coder.gateway.CoderRemoteConnectionHandle
4
5
import com.coder.gateway.icons.CoderIcons
5
6
import com.coder.gateway.models.CoderWorkspacesWizardModel
6
7
import com.coder.gateway.models.TokenSource
@@ -20,7 +21,6 @@ import com.coder.gateway.sdk.ex.WorkspaceResponseException
20
21
import com.coder.gateway.sdk.toURL
21
22
import com.coder.gateway.sdk.v2.models.WorkspaceStatus
22
23
import com.coder.gateway.sdk.v2.models.toAgentModels
23
- import com.coder.gateway.sdk.withPath
24
24
import com.coder.gateway.services.CoderSettingsState
25
25
import com.intellij.icons.AllIcons
26
26
import com.intellij.ide.ActivityTracker
@@ -30,20 +30,15 @@ import com.intellij.ide.util.PropertiesComponent
30
30
import com.intellij.openapi.Disposable
31
31
import com.intellij.openapi.actionSystem.AnAction
32
32
import com.intellij.openapi.actionSystem.AnActionEvent
33
- import com.intellij.openapi.application.ApplicationManager
34
- import com.intellij.openapi.application.ModalityState
35
33
import com.intellij.openapi.components.service
36
34
import com.intellij.openapi.diagnostic.Logger
37
35
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
38
36
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
39
37
import com.intellij.openapi.ui.setEmptyState
40
38
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
41
39
import com.intellij.ui.AnActionButton
42
- import com.intellij.ui.AppIcon
43
40
import com.intellij.ui.RelativeFont
44
41
import com.intellij.ui.ToolbarDecorator
45
- import com.intellij.ui.components.JBTextField
46
- import com.intellij.ui.components.dialog
47
42
import com.intellij.ui.dsl.builder.AlignX
48
43
import com.intellij.ui.dsl.builder.AlignY
49
44
import com.intellij.ui.dsl.builder.BottomGap
@@ -54,7 +49,6 @@ import com.intellij.ui.dsl.builder.bindSelected
54
49
import com.intellij.ui.dsl.builder.bindText
55
50
import com.intellij.ui.dsl.builder.panel
56
51
import com.intellij.ui.table.TableView
57
- import com.intellij.util.applyIf
58
52
import com.intellij.util.ui.ColumnInfo
59
53
import com.intellij.util.ui.JBFont
60
54
import com.intellij.util.ui.JBUI
@@ -391,7 +385,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
391
385
val oldURL = localWizardModel.coderURL.toURL()
392
386
component.apply () // Force bindings to be filled.
393
387
val newURL = localWizardModel.coderURL.toURL()
394
- val pastedToken = askToken(
388
+ val pastedToken = CoderRemoteConnectionHandle . askToken(
395
389
newURL,
396
390
// If this is a new URL there is no point in trying to use the same
397
391
// token.
@@ -512,89 +506,6 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
512
506
}
513
507
}
514
508
515
- /* *
516
- * Open a dialog for providing the token. Show any existing token so the
517
- * user can validate it if a previous connection failed. If we are not
518
- * retrying and the user has not checked the existing token box then open a
519
- * browser to the auth page. If the user has checked the existing token box
520
- * then populate the dialog with the token on disk (this will overwrite any
521
- * other existing token) unless this is a retry to avoid clobbering the
522
- * token that just failed. Return the token submitted by the user.
523
- */
524
- private fun askToken (
525
- url : URL ,
526
- token : Pair <String , TokenSource >? ,
527
- isRetry : Boolean ,
528
- useExisting : Boolean ,
529
- ): Pair <String , TokenSource >? {
530
- var (existingToken, tokenSource) = token ? : Pair (" " , TokenSource .USER )
531
- val getTokenUrl = url.withPath(" /login?redirect=%2Fcli-auth" )
532
- if (! isRetry && ! useExisting) {
533
- BrowserUtil .browse(getTokenUrl)
534
- } else if (! isRetry && useExisting) {
535
- val (u, t) = CoderCLIManager .readConfig()
536
- if (url == u?.toURL() && ! t.isNullOrBlank() && t != existingToken) {
537
- logger.info(" Injecting token from CLI config" )
538
- tokenSource = TokenSource .CONFIG
539
- existingToken = t
540
- }
541
- }
542
- var tokenFromUser: String? = null
543
- ApplicationManager .getApplication().invokeAndWait({
544
- lateinit var sessionTokenTextField: JBTextField
545
- val panel = panel {
546
- row {
547
- browserLink(
548
- CoderGatewayBundle .message(" gateway.connector.view.login.token.label" ),
549
- getTokenUrl.toString()
550
- )
551
- sessionTokenTextField = textField()
552
- .applyToComponent {
553
- text = existingToken
554
- minimumSize = Dimension (520 , - 1 )
555
- }.component
556
- }.layout(RowLayout .PARENT_GRID )
557
- row {
558
- cell() // To align with the text box.
559
- cell(
560
- ComponentPanelBuilder .createCommentComponent(
561
- CoderGatewayBundle .message(
562
- if (isRetry) " gateway.connector.view.workspaces.token.rejected"
563
- else if (tokenSource == TokenSource .CONFIG ) " gateway.connector.view.workspaces.token.injected"
564
- else if (existingToken.isNotBlank()) " gateway.connector.view.workspaces.token.comment"
565
- else " gateway.connector.view.workspaces.token.none"
566
- ),
567
- false ,
568
- - 1 ,
569
- true
570
- ).applyIf(isRetry) {
571
- apply {
572
- foreground = UIUtil .getErrorForeground()
573
- }
574
- }
575
- )
576
- }.layout(RowLayout .PARENT_GRID )
577
- }
578
- AppIcon .getInstance().requestAttention(null , true )
579
- if (! dialog(
580
- CoderGatewayBundle .message(" gateway.connector.view.login.token.dialog" ),
581
- panel = panel,
582
- focusedComponent = sessionTokenTextField
583
- ).showAndGet()
584
- ) {
585
- return @invokeAndWait
586
- }
587
- tokenFromUser = sessionTokenTextField.text
588
- }, ModalityState .any())
589
- if (tokenFromUser.isNullOrBlank()) {
590
- return null
591
- }
592
- if (tokenFromUser != existingToken) {
593
- tokenSource = TokenSource .USER
594
- }
595
- return Pair (tokenFromUser!! , tokenSource)
596
- }
597
-
598
509
private fun triggerWorkspacePolling (fetchNow : Boolean ) {
599
510
poller?.cancel()
600
511
0 commit comments