Skip to content

Commit 06285f0

Browse files
97amarnathkcodebytere
authored andcommitted
docs: add app information example (electron#20487)
* docs: add app information example * Code review changes * Remove demo-control css class, link href change
1 parent eaf2c61 commit 06285f0

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
File renamed without changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
</head>
6+
<body>
7+
<div>
8+
<div>
9+
<h1>App Information</h1>
10+
<div>
11+
<div>
12+
<button id="app-info">View Demo</button>
13+
<span id="got-app-info"></span>
14+
</div>
15+
<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>
16+
<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>
17+
<p>See the <a id="electron-docs" href="https://electronjs.org/docs/api/app">app module documentation<span class="u-visible-to-screen-reader">(opens in new window)</span></a> for more.</p>
18+
</div>
19+
</div>
20+
</div>
21+
<script>
22+
// You can also require other files to run in this process
23+
require('./renderer.js')
24+
</script>
25+
</body>
26+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const {app, ipcMain} = require('electron')
2+
3+
ipcMain.on('get-app-path', (event) => {
4+
event.sender.send('got-app-path', app.getAppPath())
5+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {ipcRenderer} = require('electron')
2+
3+
const appInfoBtn = document.getElementById('app-info')
4+
const electron_doc_link = document.querySelectorAll('a[href]')
5+
6+
appInfoBtn.addEventListener('click', () => {
7+
ipcRenderer.send('get-app-path')
8+
})
9+
10+
ipcRenderer.on('got-app-path', (event, path) => {
11+
const message = `This app is located at: ${path}`
12+
document.getElementById('got-app-info').innerHTML = message
13+
})
14+
15+
electron_doc_link.addEventListener('click', (e) => {
16+
e.preventDefault()
17+
shell.openExternal(url)
18+
})

0 commit comments

Comments
 (0)