@@ -20,20 +20,28 @@ object ElectronPlatformService extends PlatformService {
2020 override def appVersion : String = {
2121 import js .Dynamic .{global => g }
2222 val electron = g.require(" electron" )
23- electron.remote.app.getVersion().asInstanceOf [String ]
23+ val version = electron.remote.app.getVersion().asInstanceOf [String ]
24+ s " $version"
2425 }
2526
26- val keyStoragePrefix = " v1_ "
27+ val keyStoragePrefix = " v2_ "
2728
28- override def osName : Future [String ] = Future .successful(" Electron Platform" )
29+ def os (): String = {
30+ import js .Dynamic .{global => g }
31+ val os = g.require(" os" )
32+ // https://nodejs.org/api/os.html#os_os_release
33+ // 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
34+ os.platform().asInstanceOf [String ]
35+ }
36+
37+ override def osName : Future [String ] = Future .successful(os())
2938
3039 override def save (key : String , value : String ): Future [Unit ] = Future .successful {
3140 dom.window.localStorage.setItem(keyStoragePrefix + key, value)
3241 }
3342
3443 override def get (key : String ): Future [String ] = Future {
3544 val value = Option (dom.window.localStorage.getItem(keyStoragePrefix + key))
36- log.debug(s " Get $key= $value" )
3745 value.getOrElse(throw new Exception (s " Key $key not found " ))
3846 }
3947
@@ -62,11 +70,22 @@ object ElectronPlatformService extends PlatformService {
6270 throw ex
6371 }
6472
65- val DefaultDockerURL = " unix:///var/run/docker.sock"
73+ val DefaultMacLinuxDockerURL = " unix:///var/run/docker.sock"
74+ val DefaultWindows = " http://localhost:2375"
75+
76+ def defaultUrl : Future [String ] = {
77+ osName.map {
78+ case " win32" =>
79+ log.debug(s " Default docker for Windows url $DefaultWindows" )
80+ DefaultWindows
81+ case " darwin" =>
82+ log.debug(s " Default docker for Mac url $DefaultMacLinuxDockerURL" )
83+ DefaultMacLinuxDockerURL
84+ case other =>
85+ log.debug(s " Default docker for ' $other' url $DefaultMacLinuxDockerURL" )
86+ DefaultMacLinuxDockerURL
87+ }
6688
67- def defaultUrl : Future [String ] = Future .successful {
68- log.debug(s " Default docker url $DefaultDockerURL" )
69- DefaultDockerURL
7089 }
7190
7291 override def checkIsLatestVersion (callback : (String ) => Unit ): Unit = CheckIsLatestVersion .check(callback)
@@ -91,19 +110,18 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
91110 val callback : js.Function2 [js.Any , js.Dynamic , Unit ] =
92111 (msg : js.Any , response : js.Dynamic ) => {
93112 if (msg == null ) {
94- // log.debug(s"Processing dail response...")
95113 if (dialOptions.hijack) {
96114 processHijackResponse(onWebSocketCreated, response)
97115 } else if (dialOptions.isStream) {
98- processStreamingResponse(onStreamingData, shouldAbort, response)
116+ def onComplete { p.success(Response (" " , 200 )) }
117+ processStreamingResponse(onStreamingData, shouldAbort, onComplete, response)
99118 } else {
100119 val responseText = js.Dynamic .global.JSON .stringify(response).asInstanceOf [String ]
101- // log.debug(s"dial response: ${responseText.take(1000)}...")
102120 p.success(Response (responseText, 200 ))
103121 }
104122 } else {
105123 log.debug(s " dial fail: $msg" )
106- p.failure(new Exception (msg.toString))
124+ p.failure(new ConnectionException (msg.toString))
107125 }
108126 ()
109127 }
@@ -113,7 +131,7 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
113131 } catch {
114132 case ex : Throwable =>
115133 log.debug(s " dial error: $ex" )
116- p.failure(ex )
134+ p.failure(ConnectionException (ex.getMessage) )
117135 }
118136 p.future
119137 }
@@ -125,18 +143,20 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
125143 onWebSocketCreated(ws)
126144 }
127145
128- def processStreamingResponse (onStreamingData : (String ) => Unit , shouldAbort : Unit => Boolean , response : Dynamic ): Unit = {
146+ def processStreamingResponse (onStreamingData : (String ) => Unit , shouldAbort : Unit => Boolean , onComplete : => Unit , response : Dynamic ): Unit = {
129147 log.debug(s " processing stream $response" )
130148 val eventEmiter = response.asInstanceOf [EventEmitter ]
131149 eventEmiter.on(" data" ) { chuck : Dynamic =>
132150 val data = chuck.toString
133- log.debug(s " dial stream data: ${data.take(1000 )}... " )
134151 onStreamingData(data)
135152 if (shouldAbort()) {
136153 log.info(" Stream aborted" )
137154 response.req.abort()
138155 }
139156 }
157+ eventEmiter.on(" end" ) { _ : Dynamic =>
158+ onComplete
159+ }
140160 }
141161
142162 def get (path : String , timeout : Int = HttpTimeOut ): Future [Response ] = {
@@ -179,8 +199,7 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
179199 )
180200 dial(options, onWebSocketCreated = onWebSocketCreated)
181201 .onFailure { case ex : Exception =>
182- log.debug(s " Unable to connect WS " )
183- log.debug(s " ${ex.toString}" )
202+ log.debug(s " Unable to connect WS - ${ex.toString}" )
184203 p.failure(ex)
185204 }
186205
@@ -194,7 +213,6 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
194213 val currentStream = EventStream ()
195214
196215 def onStreamingData (data : String ): Unit = {
197- log.debug(s " [dockerClient.pullImage] data: $data" )
198216 currentStream.data = data
199217 }
200218 val sanitizedTerm = URIUtils .encodeURIComponent(term)
@@ -203,8 +221,7 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
203221 log.info(s " [dockerClient.pullImage] start " )
204222
205223 dial(options, onStreamingData).onComplete { result =>
206- log.debug(s " Pull finished $result" )
207- currentStream.done
224+ currentStream.done = true
208225 }
209226
210227 currentStream
@@ -249,7 +266,6 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
249266 }
250267
251268 def onStreamingData (data : String ): Unit = {
252- log.debug(s " container stats update ${data.take(100 )}... " )
253269 val stats = StatsCustomParser .parse(data)
254270 updateUI(stats, stream)
255271 }
0 commit comments