From 06285f0bf1b1bcd507e17f3f6ef4d930757edf4e Mon Sep 17 00:00:00 2001 From: Amarnath Karthi <97amarnathk@gmail.com> Date: Fri, 1 Nov 2019 20:34:47 +0530 Subject: [PATCH] docs: add app information example (#20487) * docs: add app information example * Code review changes * Remove demo-control css class, link href change --- .../.keep | 0 .../app-information/index.html | 26 +++++++++++++++++++ .../app-information/main.js | 5 ++++ .../app-information/renderer.js | 18 +++++++++++++ 4 files changed, 49 insertions(+) rename docs/fiddles/system/{system-information => system-app-user-information}/.keep (100%) create mode 100644 docs/fiddles/system/system-app-user-information/app-information/index.html create mode 100644 docs/fiddles/system/system-app-user-information/app-information/main.js create mode 100644 docs/fiddles/system/system-app-user-information/app-information/renderer.js diff --git a/docs/fiddles/system/system-information/.keep b/docs/fiddles/system/system-app-user-information/.keep similarity index 100% rename from docs/fiddles/system/system-information/.keep rename to docs/fiddles/system/system-app-user-information/.keep diff --git a/docs/fiddles/system/system-app-user-information/app-information/index.html b/docs/fiddles/system/system-app-user-information/app-information/index.html new file mode 100644 index 000000000000..18b05ae23dae --- /dev/null +++ b/docs/fiddles/system/system-app-user-information/app-information/index.html @@ -0,0 +1,26 @@ + + + + + + +
+
+

App Information

+
+
+ + +
+

The main process app module can be used to get the path at which your app is located on the user's computer.

+

In this example, to get that information from the renderer process, we use the ipc module to send a message to the main process requesting the app's path.

+

See the app module documentation(opens in new window) for more.

+
+
+
+ + + \ No newline at end of file diff --git a/docs/fiddles/system/system-app-user-information/app-information/main.js b/docs/fiddles/system/system-app-user-information/app-information/main.js new file mode 100644 index 000000000000..64141f98e88d --- /dev/null +++ b/docs/fiddles/system/system-app-user-information/app-information/main.js @@ -0,0 +1,5 @@ +const {app, ipcMain} = require('electron') + +ipcMain.on('get-app-path', (event) => { + event.sender.send('got-app-path', app.getAppPath()) +}) \ No newline at end of file diff --git a/docs/fiddles/system/system-app-user-information/app-information/renderer.js b/docs/fiddles/system/system-app-user-information/app-information/renderer.js new file mode 100644 index 000000000000..3f971abcab7c --- /dev/null +++ b/docs/fiddles/system/system-app-user-information/app-information/renderer.js @@ -0,0 +1,18 @@ +const {ipcRenderer} = require('electron') + +const appInfoBtn = document.getElementById('app-info') +const electron_doc_link = document.querySelectorAll('a[href]') + +appInfoBtn.addEventListener('click', () => { + ipcRenderer.send('get-app-path') +}) + +ipcRenderer.on('got-app-path', (event, path) => { + const message = `This app is located at: ${path}` + document.getElementById('got-app-info').innerHTML = message +}) + +electron_doc_link.addEventListener('click', (e) => { + e.preventDefault() + shell.openExternal(url) +}) \ No newline at end of file