Skip to content

Commit cc5f40a

Browse files
committed
fix: jump to main page if there is any error during connection
URI handling now jumps back to main plugin page when the connection to the url in the URI fails.
1 parent 57c9af7 commit cc5f40a

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ class CoderRemoteProvider(
358358
token = context.secrets.lastToken
359359
}
360360
CoderCliSetupWizardState.goToStep(WizardStep.CONNECT)
361-
return CoderCliSetupWizardPage(context, settingsPage, visibilityState, true, ::onConnect)
361+
return CoderCliSetupWizardPage(
362+
context, settingsPage, visibilityState,
363+
initialAutoSetup = true,
364+
jumpToMainPageOnError = false,
365+
onConnect = ::onConnect
366+
)
362367
} catch (ex: Exception) {
363368
errorBuffer.add(ex)
364369
} finally {

src/main/kotlin/com/coder/toolbox/CoderToolboxContext.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,9 @@ data class CoderToolboxContext(
8888
i18n.ptrl("OK")
8989
)
9090
}
91+
92+
fun popupPluginMainPage() {
93+
this.ui.showWindow()
94+
this.envPageManager.showPluginEnvironmentsPage(true)
95+
}
9196
}

src/main/kotlin/com/coder/toolbox/util/CoderProtocolHandler.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ open class CoderProtocolHandler(
112112
CoderCliSetupContext.token = token
113113
}
114114
CoderCliSetupWizardState.goToStep(WizardStep.CONNECT)
115-
context.ui.showUiPage(CoderCliSetupWizardPage(context, settingsPage, visibilityState, true, ::onConnect))
115+
context.ui.showUiPage(
116+
CoderCliSetupWizardPage(
117+
context, settingsPage, visibilityState, true,
118+
jumpToMainPageOnError = true,
119+
onConnect = ::onConnect
120+
)
121+
)
116122
}
117123

118124
private suspend fun resolveDeploymentUrl(params: Map<String, String>): String? {
@@ -469,12 +475,6 @@ open class CoderProtocolHandler(
469475
}
470476
}
471477

472-
473-
private fun CoderToolboxContext.popupPluginMainPage() {
474-
this.ui.showWindow()
475-
this.envPageManager.showPluginEnvironmentsPage(true)
476-
}
477-
478478
private suspend fun CoderToolboxContext.showEnvironmentPage(envId: String) {
479479
this.ui.showWindow()
480480
this.envPageManager.showEnvironmentPage(envId, false)

src/main/kotlin/com/coder/toolbox/views/CoderCliSetupWizardPage.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CoderCliSetupWizardPage(
1919
private val settingsPage: CoderSettingsPage,
2020
private val visibilityState: MutableStateFlow<ProviderVisibilityState>,
2121
initialAutoSetup: Boolean = false,
22+
jumpToMainPageOnError: Boolean = false,
2223
onConnect: suspend (
2324
client: CoderRestClient,
2425
cli: CoderCLIManager,
@@ -33,7 +34,8 @@ class CoderCliSetupWizardPage(
3334
private val tokenStep = TokenStep(context)
3435
private val connectStep = ConnectStep(
3536
context,
36-
shouldAutoSetup,
37+
shouldAutoLogin = shouldAutoSetup,
38+
jumpToMainPageOnError,
3739
this::notify,
3840
this::displaySteps,
3941
onConnect

src/main/kotlin/com/coder/toolbox/views/ConnectStep.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private const val USER_HIT_THE_BACK_BUTTON = "User hit the back button"
2525
class ConnectStep(
2626
private val context: CoderToolboxContext,
2727
private val shouldAutoLogin: StateFlow<Boolean>,
28+
private val jumpToMainPageOnError: Boolean,
2829
private val notify: (String, Throwable) -> Unit,
2930
private val refreshWizard: () -> Unit,
3031
private val onConnect: suspend (
@@ -127,7 +128,11 @@ class ConnectStep(
127128
} finally {
128129
if (shouldAutoLogin.value) {
129130
CoderCliSetupContext.reset()
130-
CoderCliSetupWizardState.goToFirstStep()
131+
if (jumpToMainPageOnError) {
132+
context.popupPluginMainPage()
133+
} else {
134+
CoderCliSetupWizardState.goToFirstStep()
135+
}
131136
} else {
132137
if (context.settingsStore.requireTokenAuth) {
133138
CoderCliSetupWizardState.goToPreviousStep()

0 commit comments

Comments
 (0)