Mohan pd.
Mohan pd. Author of The Coders Blog. Also a professional fullstack javascript developer working with various tech company and client around world.

Making system alert sound via Electron app.

Sep 11, 2019 · 1 min
Making system alert sound via Electron app.

Electron export shell modules which help developers to interact with a desktop environment. Shell functions are available in both Main and Renderer processes but it is recommended to use it from the Main process so that we can better control its use.

Let make a system alert sound using shell modules. In this article, we will use a shell.beep method which prompts the OS to make the system beep.

Here is a simple code to make a beep in main.js file.

const {
    shell
} = require('electron')
function createWindow() {
    // Create the browser window.
    mainWindow = new BrowserWindow({
        width: 800,
        height: 600
    })
    // and load the index.html of the app.
    mainWindow.loadURL(url.format({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file:',
        slashes: true
    }))
    // Open the DevTools.
    // mainWindow.webContents.openDevTools()
    // Emitted when the window is closed.
    mainWindow.on('closed', function() {
        // Dereference the window object, usually you would store windows
        // in an array if your app supports multi windows, this is the time
        // when you should delete the corresponding element.
        mainWindow = null
    })
    shell.beep()
}