Skip to content

Instantly share code, notes, and snippets.

@jh3y
Last active October 21, 2019 17:40
Show Gist options
  • Save jh3y/e25e2b15cff6b63f4f425fa4787d26fd to your computer and use it in GitHub Desktop.
Save jh3y/e25e2b15cff6b63f4f425fa4787d26fd to your computer and use it in GitHub Desktop.
Electron - Get System Information Fiddle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<div>
<h1>Get system information</h1>
<i>Supports: Win, macOS, Linux <span>|</span> Process: Both</i>
<div>
<div>
<button id="system-info">View Demo</button>
<span id="got-system-info"></span>
</div>
<p>The Node.js <code>os</code> module provides useful information about the user's operating system. It's built into Node.js and can be used in both the main and renderer proesses.</p>
<p>In the example below we require the module and then return the location of the home directory.</p>
<p>See the full <a href="https://nodejs.org/api/os.html">os documentation<span>(opens in new window)</span></a> for more.</p>
</div>
</div>
</div>
<script>
require('./renderer.js')
</script>
</body>
</html>
const { app, BrowserWindow } = require('electron')
let mainWindow = null
function createWindow () {
const windowOptions = {
width: 600,
height: 400,
title: 'Get system information',
webPreferences: {
nodeIntegration: true
}
}
mainWindow = new BrowserWindow(windowOptions)
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
}
app.on('ready', () => {
createWindow()
})
const os = require('os')
const homeDir = os.homedir()
const sysInfoBtn = document.getElementById('system-info')
sysInfoBtn.addEventListener('click', () => {
const message = `Your system home directory is: ${homeDir}`
document.getElementById('got-system-info').innerHTML = message
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment