Skip to content

Commit e77a82f

Browse files
author
Felix
committed
#72 Fix container url when using unix:///var/run/docker.sock
1 parent 46703f6 commit e77a82f

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

chromeapp/src/main/scala/util/ChromePlatformService.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ object ChromePlatformService extends PlatformService {
8888
}
8989

9090
override def checkIsLatestVersion(callback: (String) => Unit): Unit = {} // Auto Chrome update
91+
92+
def openExternalLink(event: Event): Unit = {} // Already in the browser
9193
}
9294

9395

electron/src/main/scala/util/ElectronPlatformService.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import model.{BasicWebSocket, Connection, DockerEvent}
66
import nodejs.raw.EventEmitter
77
import org.scalajs.dom
88
import org.scalajs.dom.ext.Ajax.InputData
9+
import org.scalajs.dom.raw.Event
910
import util.EventsCustomParser.DockerEventStream
1011
import util.PullEventsCustomParser.{EventStatus, EventStream}
1112
import util.logger.log
@@ -89,6 +90,14 @@ object ElectronPlatformService extends PlatformService {
8990
}
9091

9192
override def checkIsLatestVersion(callback: (String) => Unit): Unit = CheckIsLatestVersion.check(callback)
93+
94+
95+
def openExternalLink(event: Event): Unit = {
96+
val shell = js.Dynamic.global.require("electron").shell
97+
event.preventDefault()
98+
shell.openExternal(event.target.asInstanceOf[Dynamic].href)
99+
}
100+
92101
}
93102

94103
class ElectronDockerConnection(val connection: Connection) extends DockerConnection {

src/main/scala/model/model.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import scala.util.Try
1515

1616
case class Connection(url: String) {
1717
import util.StringUtils._
18-
def ip = substringBefore(substringAfter(url, "://"), ":")
18+
def host = substringBefore(substringAfter(url, "://"), ":").replace("/var/run/docker.sock", "localhost")
1919
}
2020

2121
case class DockerMetadata(connectionInfo: String,

src/main/scala/ui/pages/ContainerPage.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import japgolly.scalajs.react.vdom.prefix_<^._
55
import japgolly.scalajs.react.{BackendScope, ReactComponentB, ReactElement}
66
import model.stats.ContainerStats
77
import model.{BasicWebSocket, ContainerInfo, ContainerTop, FileSystemChange}
8-
import org.scalajs.dom.raw.WebSocket
8+
import org.scalajs.dom.raw.{Event, WebSocket}
99
import ui.WorkbenchRef
1010
import ui.widgets.TerminalCard.TerminalInfo
1111
import ui.widgets._
@@ -128,6 +128,10 @@ object ContainerPage {
128128
stream.abort()
129129
t.modState(s => s.copy(statsConnectedStream = None))
130130
}
131+
132+
def openExternalLink(event: Event): Unit = {
133+
PlatformService.current.openExternalLink(event)
134+
}
131135
}
132136

133137

@@ -191,7 +195,7 @@ object ContainerPageRender {
191195
vdomCommands(S, B)
192196
),
193197
InfoCard(executionInfo),
194-
InfoCard(networkInfo, InfoCard.SMALL, None, Seq.empty, vdomServiceUrl(containerInfo, P))
198+
InfoCard(networkInfo, InfoCard.SMALL, None, Seq.empty, vdomServiceUrl(B, containerInfo, P))
195199
)
196200
}
197201

@@ -221,12 +225,12 @@ object ContainerPageRender {
221225
)
222226
}
223227

224-
def vdomServiceUrl(containerInfo: ContainerInfo, P: Props) = {
225-
val ip = P.ref.connection.map(_.ip).getOrElse("")
228+
def vdomServiceUrl(B: Backend, containerInfo: ContainerInfo, P: Props) = {
229+
val host = P.ref.connection.map(_.host).getOrElse("")
226230
containerInfo.NetworkSettings.ports.map {
227-
case (external, internal) => ip + ":" + external
231+
case (external, _) => host + ":" + external
228232
}
229-
}.map(url => <.div(^.className := "panel-footer", <.a(^.href := s"http://$url", ^.target := "_blank")(url))).headOption
233+
}.map(url => <.div(^.className := "panel-footer", <.a(^.href := s"http://$url", ^.target := "_blank", ^.onClick ==> B.openExternalLink )(url))).headOption
230234

231235
def vdomCommands(state: State, B: Backend) =
232236
Some(<.div(^.className := "panel-footer",

src/main/scala/util/PlatformService.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package util
22

33
import api.DockerClient
44
import model.Connection
5+
import org.scalajs.dom.raw.Event
56
import util.logger._
67

78
import scala.concurrent.Future
@@ -29,6 +30,8 @@ trait PlatformService {
2930

3031
def checkIsLatestVersion(callback: (String => Unit)): Unit
3132

33+
def openExternalLink(event: Event): Unit
34+
3235
}
3336

3437
object PlatformService {

0 commit comments

Comments
 (0)