Skip to content

Commit bd5baf6

Browse files
matheusdalexlyp
authored andcommitted
Read version from binaries and display in about window (#688)
1 parent 0b860dc commit bd5baf6

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

app/main.development.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,40 @@ const launchDCRWallet = () => {
390390
return dcrwPID;
391391
};
392392

393+
const readExesVersion = () => {
394+
let spawn = require("child_process").spawnSync;
395+
let args = ["--version"];
396+
let exes = ["dcrd", "dcrwallet", "dcrctl"];
397+
let versions = {
398+
decrediton: app.getVersion()
399+
};
400+
401+
for (let exe of exes) {
402+
let exePath = path.join(execPath, "bin", "dcrd");
403+
404+
let proc = spawn(exePath, args, { encoding: "utf8" });
405+
if (proc.error) {
406+
logger.log("error", `Error trying to read version of ${exe}: ${proc.error}`);
407+
continue;
408+
}
409+
410+
let versionLine = proc.stdout.toString();
411+
if (!versionLine) {
412+
logger.log("error", `Empty version line when reading version of ${exe}`);
413+
continue;
414+
}
415+
416+
let decodedLine = versionLine.match(/\w+ version ([^\s]+)/);
417+
if (decodedLine !== null) {
418+
versions[exe] = decodedLine[1];
419+
} else {
420+
logger.log("error", `Unable to decode version line ${versionLine}`);
421+
}
422+
}
423+
424+
return versions;
425+
};
426+
393427
app.on("ready", async () => {
394428
await installExtensions();
395429
// Write application config files.
@@ -592,6 +626,7 @@ app.on("ready", async () => {
592626
versionWin.loadURL(`file://${__dirname}/version/version.html`);
593627

594628
versionWin.once("ready-to-show", () => {
629+
versionWin.webContents.send("exes-versions", readExesVersion());
595630
versionWin.show();
596631
});
597632
}

app/version/version.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<title>About</title>
6+
<script src="version.js"></script>
67
<style>
78
body {
89
background-color: #0c1e3e;
@@ -39,10 +40,10 @@
3940
<svg height="250px" width="250px" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"><defs><style>.cls-1{fill:#2ed8a3;}.cls-2{fill:#2972ff;}</style></defs><title>decred - symbol -primary - positive</title><g id="_Group_" data-name="&lt;Group&gt;"><g id="_Group_2" data-name="&lt;Group&gt;"><g id="_Group_3" data-name="&lt;Group&gt;"><path id="_Path_" data-name="&lt;Path&gt;" class="cls-1" d="M231.88,278.06H306.1a50,50,0,0,0,0-100H282.45l-50.57-43.9H306.1a93.92,93.92,0,0,1,35.37,180.92L400,365.86H333Z"/></g><g id="_Group_4" data-name="&lt;Group&gt;"><path id="_Path_2" data-name="&lt;Path&gt;" class="cls-2" d="M268.12,221.95H193.9a50,50,0,0,0,0,100h23.64l50.57,43.9H193.9a93.92,93.92,0,0,1-35.38-180.92L100,134.14h67Z"/></g></g></g></svg>
4041
</div>
4142
<div class="version-area">
42-
<h1>Decrediton <span class="smaller">v1.1.0</span></h1>
43-
<h3><a target="_blank" href="https://github.com/decred/decred-binaries/releases/tag/v1.1.0">What's New</a></h3>
44-
<h3>dcrd <span class="smaller">v1.1.0</span></h3>
45-
<h3>dcrwallet <span class="smaller">v1.1.0</span></h3>
43+
<h1>Decrediton <span class="smaller" id="decreditonVersion"></span></h1>
44+
<h3><a target="_blank" id="whatsNewLink">What's New</a></h3>
45+
<h3>dcrd <span class="smaller" id="dcrdVersion"></span></h3>
46+
<h3>dcrwallet <span class="smaller" id="dcrwalletVersion"></span></h3>
4647
</div>
4748
</body>
4849
</html>

app/version/version.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
let ipcRenderer = require("electron").ipcRenderer;
3+
ipcRenderer.on("exes-versions", function (event, versions) {
4+
document.getElementById("decreditonVersion").innerHTML = versions["decrediton"];
5+
document.getElementById("dcrdVersion").innerHTML = versions["dcrd"];
6+
document.getElementById("dcrwalletVersion").innerHTML = versions["dcrwallet"];
7+
document.getElementById("whatsNewLink").href =
8+
`https://github.com/decred/decred-binaries/releases/tag/v${versions["decrediton"]}`;
9+
});

0 commit comments

Comments
 (0)