Skip to content

Commit 8ac7fa1

Browse files
committed
Merge pull request electron#144 from electron/app-demo
Add App Path Demo
2 parents d2b198f + e89120d commit 8ac7fa1

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const app = require('electron').app
2+
const ipc = require('electron').ipcMain
3+
4+
ipc.on('get-app-path', function (event) {
5+
event.sender.send('got-app-path', app.getAppPath())
6+
})
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
var appInfoBtn = document.getElementById('app-info')
1+
const ipc = require('electron').ipcRenderer
22

3-
var electronVersion = process.versions.electron
3+
const appInfoBtn = document.getElementById('app-info')
44

55
appInfoBtn.addEventListener('click', function () {
6-
var message = 'This app is using Electron version: ' + electronVersion
6+
ipc.send('get-app-path')
7+
})
8+
9+
ipc.on('got-app-path', function (event, path) {
10+
let message = `This app is located at: ${path}`
711
document.getElementById('got-app-info').innerHTML = message
812
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var versionInfoBtn = document.getElementById('version-info')
2+
3+
var electronVersion = process.versions.electron
4+
5+
versionInfoBtn.addEventListener('click', function () {
6+
var message = 'This app is using Electron version: ' + electronVersion
7+
document.getElementById('got-version-info').innerHTML = message
8+
})

sections/system/app-sys-information.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,32 @@ <h3>With a few Node.js and Electron modules you can gather information about the
2121
<button class="demo-button" id="app-info">View Demo</button>
2222
<span class="demo-response" id="got-app-info"></span>
2323
</div>
24+
<p>The main process <code>app</code> module can be used to get the path at which your app is located on the user's computer.</p>
25+
<p>In this example, to get that information from the renderer process, we use the <code>ipc</code> module to send a message to the main process requesting the app's path.</p>
26+
<p>See the <a class="u-exlink" href="http://electron.atom.io/docs/latest/api/app">app module documentation</a> for more.</p>
27+
<h5>Renderer Process</h5>
28+
<pre><code data-path="renderer-process/system/app-information.js"></pre></code>
29+
<h5>Main Process</h5>
30+
<pre><code data-path="main-process/system/app-information.js"></pre></code>
31+
</div>
32+
</div>
33+
</div>
34+
35+
<div class="demo">
36+
<div class="demo-wrapper">
37+
<button id="app-info-demo-toggle" class="js-container-target demo-toggle-button">Get version information
38+
<div class="demo-meta u-avoid-clicks">Supports: Win, OS X, Linux <span class="demo-meta-divider">|</span> Process: Both</div>
39+
</button>
40+
<div class="demo-box">
41+
<div class="demo-controls">
42+
<button class="demo-button" id="version-info">View Demo</button>
43+
<span class="demo-response" id="got-version-info"></span>
44+
</div>
2445
<p>The <code>process</code> module is built into Node.js (therefore you can use this in both the main and renderer processes) and in Electron apps this object has a few more useful properties on it.</p>
2546
<p>The example below gets the version of Electron in use by the app.</p>
2647
<p>See the <a class="u-exlink" href="http://electron.atom.io/docs/latest/api/process">process documentation</a> for more.</p>
2748
<h5>Renderer Process</h5>
28-
<pre><code data-path="renderer-process/system/app-information.js"></pre></code>
49+
<pre><code data-path="renderer-process/system/version-information.js"></pre></code>
2950

3051
<div class="demo-protip">
3152
<h2>ProTip</h2>
@@ -83,6 +104,7 @@ <h5>Renderer Process</h5>
83104

84105
<script type="text/javascript">
85106
require('./renderer-process/system/app-information')
107+
require('./renderer-process/system/version-information')
86108
require('./renderer-process/system/sys-information')
87109
require('./renderer-process/system/screen-information')
88110
</script>

0 commit comments

Comments
 (0)