Last active
March 17, 2025 14:51
-
-
Save jh3y/e25e2b15cff6b63f4f425fa4787d26fd to your computer and use it in GitHub Desktop.
Electron - Get System Information Fiddle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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