Skip to content

Commit 4f1a38b

Browse files
author
Felix
committed
Bug Fixing for Electron version.
1 parent e627dc1 commit 4f1a38b

File tree

14 files changed

+160
-51
lines changed

14 files changed

+160
-51
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ object ChromePlatformService extends PlatformService {
8585
case "linux" | "openbsd" => ConfigStorage.DefaultLinuxUrl
8686
case _ => ""
8787
}
88+
89+
override def checkIsLatestVersion(callback: (String) => Unit): Unit = {} // Auto Chrome update
8890
}
8991

9092

electron/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

electron/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ npm start
3333
3434
### Package the native app
3535
```
36-
npm install electron-packager
36+
npm install electron-installer-dmg
37+
nom install electron-installer
3738
npm run-script package
39+
npm run-script dmg
3840
```

electron/img/logo_small.png.ico

14.7 KB
Binary file not shown.

electron/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "electron-dockerui",
3-
"version": "1.0.0",
3+
"version": "0.5.1",
44
"description": "A minimal Electron application",
55
"main": "main.js",
66
"scripts": {
77
"start": "electron .",
88
"debug": "cd .. && sbt \"project electron\" \"fastOptJS\" && cd electron && electron .",
99
"test": "sbt test",
10-
"package": "electron-packager . SimpleDockerUI --platform=darwin --arch=x64 --overwrite --icon=img/logo_small.icns --ignore='src' --ignore='target'"
10+
"package": "electron-packager . SimpleDockerUI --platform=darwin --arch=x64 --overwrite --icon=img/logo_small.icns --ignore='src' --ignore='target' --asar",
11+
"dmg": "electron-installer-dmg SimpleDockerUI-darwin-x64/SimpleDockerUI.app SimpleDockerUI --icon=img/logo_small.icns --overwrite"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -27,9 +28,12 @@
2728
},
2829
"homepage": "https://github.com/felixgborrego/docker-ui-chrome-app",
2930
"devDependencies": {
30-
"electron": "^1.4.0"
31+
"electron": "^1.4.6",
32+
"electron-installer-dmg": "^0.1.2"
3133
},
3234
"dependencies": {
33-
"docker-modem" : "^0.3.1"
35+
"docker-modem": "^0.3.1",
36+
"split-ca": "^1.0.0",
37+
"universal-analytics": "0.4.6"
3438
}
3539
}

electron/src/main/scala/util/DockerModem.scala

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ import scala.scalajs.js.annotation.ScalaJSDefined
1111
class ModemOptions(val socketPath: String,
1212
val host: String,
1313
val protocol: String,
14-
val port: String
14+
val port: String,
15+
val ca: js.UndefOr[InputData] = js.undefined,
16+
val cert: js.UndefOr[InputData] = js.undefined,
17+
val key: js.UndefOr[InputData] = js.undefined
1518
) extends js.Object
1619

1720

1821
@ScalaJSDefined
19-
class DialOptions(val path: String, val method: String, val options: js.UndefOr[InputData], val statusCodes: js.Dictionary[Boolean], val isStream: Boolean = false, val hijack: Boolean = false, val openStdin: Boolean = false) extends js.Object
22+
class DialOptions(val path: String,
23+
val method: String,
24+
val options: js.UndefOr[InputData],
25+
val statusCodes: js.Dictionary[Boolean],
26+
val isStream: Boolean = false,
27+
val hijack: Boolean = false,
28+
val openStdin: Boolean = false) extends js.Object
2029

2130
@ScalaJSDefined
2231
class DockerMessage(val json: String, val reason: String, val statusCode: String) extends js.Object
@@ -46,7 +55,24 @@ object DockerModem {
4655
log.debug(s"Url: protocol: $protocol, host: $host")
4756
val port = connection.url.drop(protocol.size).drop("://".size).dropWhile(_ != ':').drop(1)
4857
log.debug(s"Url: port: $port")
49-
new ModemOptions(socketPath = null, host = host, protocol = protocol, port = port)
58+
59+
val pathOpt = Option(g.process.env.DOCKER_CERT_PATH.asInstanceOf[String])
60+
val (envCa, envCert, envKey) =
61+
if (protocol == "https" && pathOpt.isDefined) {
62+
val path = pathOpt.get
63+
64+
log.info(s"Using Cert Path $path")
65+
val fs = g.require("fs")
66+
val splitCa = g.require("split-ca")
67+
val ca: js.UndefOr[InputData] = splitCa.apply(s"$path/ca.pem").asInstanceOf[InputData]
68+
val cert: js.UndefOr[InputData] = fs.readFileSync(s"$path/cert.pem").asInstanceOf[InputData]
69+
val key: js.UndefOr[InputData] = fs.readFileSync(s"$path/key.pem").asInstanceOf[InputData]
70+
(ca, cert, key)
71+
} else {
72+
(js.undefined, js.undefined, js.undefined)
73+
}
74+
75+
new ModemOptions(socketPath = null, host = host, protocol = protocol, port = port, ca = envCa, cert = envCert, key = envKey)
5076
}
5177
}
5278
log.debug(s"modemOptions: protocol: ${modemOptions.protocol} path: ${modemOptions.socketPath}")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package util
2+
3+
import util.logger.log
4+
5+
import scala.scalajs.js
6+
7+
// Analytics using https://www.npmjs.com/package/universal-analytics
8+
object ElectronAnalytics {
9+
10+
import js.Dynamic.{global => g}
11+
12+
val ua = g.require("universal-analytics")
13+
14+
def sendEvent(category: String, action: String, label: String): Unit = {
15+
val visitor = ua(GoogleUA, userId())
16+
visitor.event(category, action, label).send()
17+
log.info(s"sendEvent: $category, $action, $label")
18+
}
19+
20+
def sendPageView(name: String): Unit = {
21+
val visitor = ua(GoogleUA, userId())
22+
visitor.pageview(name).send()
23+
log.info(s"sendAppView: $name")
24+
}
25+
26+
def sendException(ex: String): Unit = {
27+
val visitor = ua(GoogleUA, userId())
28+
log.info(s"sendException: $ex")
29+
visitor.exception(s"sendException: $ex").send()
30+
}
31+
32+
val GoogleUA = "UA-61270183-1"
33+
34+
// TODO Use custom user id
35+
// https://www.npmjs.com/package/electron-machine-id
36+
def userId(): String = "dev-1"
37+
38+
}

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import scala.scalajs.js
1616
import scala.scalajs.js.{Dynamic, URIUtils}
1717

1818
object ElectronPlatformService extends PlatformService {
19-
override def appVersion: String = "Electron DockerUI beta"
19+
20+
override def appVersion: String = {
21+
import js.Dynamic.{global => g}
22+
val electron = g.require("electron")
23+
electron.remote.app.getVersion().asInstanceOf[String]
24+
}
25+
2026
val keyStoragePrefix = "v1_"
2127

2228
override def osName: Future[String] = Future.successful("Electron Platform")
@@ -36,15 +42,15 @@ object ElectronPlatformService extends PlatformService {
3642
}
3743

3844
override def sendAppView(name: String): Unit = {
39-
log.info(s"sendAppView: $name")
45+
ElectronAnalytics.sendPageView(name)
4046
}
4147

4248
override def sendEvent(category: String, action: String, label: String): Unit = {
43-
log.info(s"sendEvent: $category, $action, $label")
49+
ElectronAnalytics.sendEvent(category, action, label)
4450
}
4551

4652
override def sendException(ex: String): Unit = {
47-
log.info(s"sendException: $ex")
53+
ElectronAnalytics.sendException(ex)
4854
}
4955

5056
override def buildDockerClient(con: Connection): DockerClient = try {
@@ -62,10 +68,13 @@ object ElectronPlatformService extends PlatformService {
6268
log.debug(s"Default docker url $DefaultDockerURL")
6369
DefaultDockerURL
6470
}
71+
72+
override def checkIsLatestVersion(callback: (String) => Unit): Unit = CheckIsLatestVersion.check(callback)
6573
}
6674

6775
class ElectronDockerConnection(val connection: Connection) extends DockerConnection {
6876
import DockerClientConfig._
77+
6978
import js.JSConverters._
7079

7180
val info = connection.url
@@ -82,14 +91,14 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
8291
val callback: js.Function2[js.Any, js.Dynamic, Unit] =
8392
(msg: js.Any, response: js.Dynamic) => {
8493
if (msg == null) {
85-
log.debug(s"Processing dail response...")
94+
//log.debug(s"Processing dail response...")
8695
if (dialOptions.hijack) {
8796
processHijackResponse(onWebSocketCreated, response)
8897
} else if (dialOptions.isStream) {
8998
processStreamingResponse(onStreamingData, shouldAbort, response)
9099
} else {
91100
val responseText = js.Dynamic.global.JSON.stringify(response).asInstanceOf[String]
92-
log.debug(s"dial response: ${responseText.take(1000)}...")
101+
//log.debug(s"dial response: ${responseText.take(1000)}...")
93102
p.success(Response(responseText, 200))
94103
}
95104
} else {
@@ -203,7 +212,6 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
203212

204213
// TODO refactor
205214
def events(update: Seq[DockerEvent] => Unit): ConnectedStream = {
206-
log.info("[dockerClient.events] start")
207215
val since = {
208216
val t = new js.Date()
209217
t.setDate(t.getDate() - 3) // pull 3 days
@@ -225,7 +233,6 @@ class ElectronDockerConnection(val connection: Connection) extends DockerConnect
225233
update(currentStream.events)
226234
}
227235

228-
log.info(s"[dockerClient.events] start: $eventsUrl")
229236
val options = new DialOptions(path = eventsUrl, method = "GET", options = js.undefined, Map(("200", true)).toJSDictionary, isStream = true)
230237
dial(options, onStreamingData, (Unit) => isAborted)
231238

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.12
1+
sbt.version=0.13.13

src/main/scala/demo/Main.scala_

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)