Skip to content

Commit 20f1b1b

Browse files
committed
Add app path demo
1 parent 064aac7 commit 20f1b1b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const ipc = require('electron').ipcRenderer
2+
3+
const appInfoBtn = document.getElementById('app-info')
4+
5+
appInfoBtn.addEventListener('click', function () {
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}`
11+
document.getElementById('got-app-info').innerHTML = message
12+
})

sections/system/app-sys-information.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ <h3>With a few Node.js and Electron modules you can gather information about the
1111
</div>
1212
</header>
1313

14+
<div class="demo">
15+
<div class="demo-wrapper">
16+
<button id="app-info-demo-toggle" class="js-container-target demo-toggle-button">Get app information
17+
<div class="demo-meta u-avoid-clicks">Supports: Win, OS X, Linux <span class="demo-meta-divider">|</span> Process: Both</div>
18+
</button>
19+
<div class="demo-box">
20+
<div class="demo-controls">
21+
<button class="demo-button" id="app-info">View Demo</button>
22+
<span class="demo-response" id="got-app-info"></span>
23+
</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 rendrer 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+
1435
<div class="demo">
1536
<div class="demo-wrapper">
1637
<button id="app-info-demo-toggle" class="js-container-target demo-toggle-button">Get version information
@@ -82,6 +103,7 @@ <h5>Renderer Process</h5>
82103
</div>
83104

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

0 commit comments

Comments
 (0)