@@ -6,23 +6,13 @@ import com.coder.gateway.icons.CoderIcons
6
6
import com.coder.gateway.models.CoderWorkspacesWizardModel
7
7
import com.coder.gateway.models.WorkspaceAgentModel
8
8
import com.coder.gateway.models.WorkspaceAgentStatus
9
- import com.coder.gateway.models.WorkspaceAgentStatus.FAILED
10
- import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING
11
- import com.coder.gateway.models.WorkspaceAgentStatus.STOPPED
9
+ import com.coder.gateway.models.WorkspaceAgentStatus.*
12
10
import com.coder.gateway.models.WorkspaceVersionStatus
13
- import com.coder.gateway.sdk.Arch
14
- import com.coder.gateway.sdk.CoderCLIManager
15
- import com.coder.gateway.sdk.CoderRestClientService
16
- import com.coder.gateway.sdk.CoderSemVer
17
- import com.coder.gateway.sdk.OS
18
- import com.coder.gateway.sdk.TemplateIconDownloader
11
+ import com.coder.gateway.sdk.*
19
12
import com.coder.gateway.sdk.ex.AuthenticationResponseException
20
13
import com.coder.gateway.sdk.ex.TemplateResponseException
21
14
import com.coder.gateway.sdk.ex.WorkspaceResponseException
22
- import com.coder.gateway.sdk.getOS
23
- import com.coder.gateway.sdk.toURL
24
15
import com.coder.gateway.sdk.v2.models.Workspace
25
- import com.coder.gateway.sdk.withPath
26
16
import com.intellij.ide.ActivityTracker
27
17
import com.intellij.ide.BrowserUtil
28
18
import com.intellij.ide.IdeBundle
@@ -51,30 +41,16 @@ import com.intellij.util.ui.JBUI
51
41
import com.intellij.util.ui.ListTableModel
52
42
import com.intellij.util.ui.table.IconTableCellRenderer
53
43
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
54
- import kotlinx.coroutines.CoroutineScope
55
- import kotlinx.coroutines.Dispatchers
56
- import kotlinx.coroutines.Job
57
- import kotlinx.coroutines.cancel
58
- import kotlinx.coroutines.delay
59
- import kotlinx.coroutines.isActive
60
- import kotlinx.coroutines.launch
61
- import kotlinx.coroutines.withContext
44
+ import kotlinx.coroutines.*
62
45
import java.awt.Component
63
46
import java.awt.Dimension
64
47
import java.awt.event.MouseEvent
65
48
import java.awt.event.MouseListener
66
49
import java.awt.event.MouseMotionListener
67
50
import java.awt.font.TextAttribute
68
51
import java.awt.font.TextAttribute.UNDERLINE_ON
69
- import java.nio.file.Files
70
- import java.nio.file.Path
71
- import java.nio.file.Paths
72
52
import java.net.SocketTimeoutException
73
- import javax.swing.Icon
74
- import javax.swing.JCheckBox
75
- import javax.swing.JTable
76
- import javax.swing.JTextField
77
- import javax.swing.ListSelectionModel
53
+ import javax.swing.*
78
54
import javax.swing.table.DefaultTableCellRenderer
79
55
import javax.swing.table.TableCellRenderer
80
56
@@ -395,45 +371,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
395
371
if (! url.isNullOrBlank() && ! token.isNullOrBlank()) {
396
372
return url to token
397
373
}
398
- return readConfig()
399
- }
400
-
401
- /* *
402
- * Return the URL and token from the CLI config.
403
- */
404
- private fun readConfig (): Pair <String ?, String ?> {
405
- val configDir = getConfigDir()
406
- logger.info(" Reading config from $configDir " )
407
- try {
408
- val url = Files .readString(configDir.resolve(" url" ))
409
- val token = Files .readString(configDir.resolve(" session" ))
410
- return url to token
411
- } catch (e: Exception ) {
412
- return null to null // Probably has not configured the CLI yet.
413
- }
414
- }
415
-
416
- /* *
417
- * Return the config directory used by the CLI.
418
- */
419
- private fun getConfigDir (): Path {
420
- var dir = System .getenv(" CODER_CONFIG_DIR" )
421
- if (! dir.isNullOrBlank()) {
422
- return Path .of(dir)
423
- }
424
- // The Coder CLI uses https://github.com/kirsle/configdir so this should
425
- // match how it behaves.
426
- return when (getOS()) {
427
- OS .WINDOWS -> Paths .get(System .getenv(" APPDATA" ), " coderv2" )
428
- OS .MAC -> Paths .get(System .getenv(" HOME" ), " Library/Application Support/coderv2" )
429
- else -> {
430
- dir = System .getenv(" XDG_CONFIG_HOME" )
431
- if (! dir.isNullOrBlank()) {
432
- return Paths .get(dir, " coderv2" )
433
- }
434
- return Paths .get(System .getenv(" HOME" ), " .config/coderv2" )
435
- }
436
- }
374
+ return CoderCLIManager .readConfig()
437
375
}
438
376
439
377
private fun updateWorkspaceActions () {
@@ -554,7 +492,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
554
492
if (openBrowser && ! localWizardModel.useExistingToken) {
555
493
BrowserUtil .browse(getTokenUrl)
556
494
} else if (localWizardModel.useExistingToken) {
557
- val (url, token) = readConfig()
495
+ val (url, token) = CoderCLIManager . readConfig()
558
496
if (url == localWizardModel.coderURL && ! token.isNullOrBlank()) {
559
497
logger.info(" Injecting valid token from CLI config" )
560
498
localWizardModel.token = token
0 commit comments