concept UI in category electron

appears as: UI, UI, The UI
Electron in Action

This is an excerpt from Manning's book Electron in Action.

  • Renderer processes display the UI and respond to user events.
  • Our main process is a lot like any other Node process. It has access to all of Node’s built-in libraries as well as a special set of modules provided by Electron, which we explore over the course of this book. But, like any other Node process, our main process does not have a DOM (Document Object Model) and cannot render a UI. The main process is responsible for interacting with the operating system, managing state, and coordinating with all the other processes in our application. It is not in charge of rendering HTML and CSS. That’s the job of the renderer processes. One of the primary reasons we signed up for this whole Electron adventure is that we wanted to create a GUI for Node processes.

    2.4. Implementing the UI

    We start by updating our index.html with the markup that we need for the UI.

    Listing 2.12. Adding the markup for the UI of the application: ./app/index.html
    <h1>Bookmarker</h1>
    
    <div class="error-message"></div>
    
    <section class="add-new-link">
      <form class="new-link-form">
        <input type="url" class="new-link-url" placeholder="URL"size="100"
         required>
        <input type="submit" class="new-link-submit" value="Submit" disabled>
      </form>
    </section>
    
    <section class="links"></section>
    
    <section class="controls">
      <button class="clear-storage">Clear Storage</button>
    </section>
    Figure 4.1. Our application will trigger the Open File dialog box when it starts. By the end of the chapter, this functionality will be replaced by the ability to trigger the dialog box from the UI.
    Cross-Platform Desktop Applications: Using Node, Electron, and NW.js

    This is an excerpt from Manning's book Cross-Platform Desktop Applications: Using Node, Electron, and NW.js.

    Figure 2.2. NW.js running a bare-minimum app. The app displays the contents of the index.html file, which means it’s working as expected so far. Later in the chapter, you’ll replace this simple HTML with the UI that makes up the app.
    Listing 2.12. Rendering the template instances in the UI via the app.js file
    'use strict'; const async = require('async'); const fs = require('fs'); const osenv = require('osenv'); const path = require('path'); function getUsersHomeFolder() { return osenv.home(); } function getFilesInFolder(folderPath, cb) { fs.readdir(folderPath, cb); } function inspectAndDescribeFile(filePath, cb) { let result = { file: path.basename(filePath), path: filePath, type: '' }; fs.stat(filePath, (err, stat) => { if (err) { cb(err); } else { if (stat.isFile()) { result.type = 'file'; } if (stat.isDirectory()) { result.type = 'directory'; } cb(err, result); } }); } function inspectAndDescribeFiles(folderPath, files, cb) { async.map(files, (file, asyncCb) => { let resolvedFilePath = path.resolve(folderPath, file); inspectAndDescribeFile(resolvedFilePath, asyncCb); }, cb); } function displayFile(file) { #1 const mainArea = document.getElementById('main-area'); const template = document.querySelector('#item-template'); let clone = document.importNode(template.content, true); #2 clone.querySelector('img').src = `images/${file.type}.svg`; #3 clone.querySelector('.filename').innerText = file.file; #3 mainArea.appendChild(clone); #4 } function displayFiles(err, files) { if (err) { return alert('Sorry, we could not display your files'); } files.forEach(displayFile); #5 } function main() { let folderPath = getUsersHomeFolder(); getFilesInFolder(folderPath, (err, files) => { if (err) { return alert('Sorry, we could not load your home folder'); } inspectAndDescribeFiles(folderPath, files, displayFiles); }); } main(); #1 - Adds new function called displayFile that handles rendering template instance #2 - Creates copy of template instance #3 - Alters instance to include file’s name and icon #4 - Appends template instance to "main-area" div element #5 - Passes files to the displayFile function in the displayFiles function

    2.3.2. Showing the user’s files and folders in the UI

    In the preceding section, we started off by creating the UI elements first and then populated the user’s personal folder path in the UI element. For this feature, we’ll work on getting ahold of a list of the user’s files and folders first and then figure out from there how we display them in the UI of the application. For a quick reminder, figure 2.9 shows the UI element we’re looking to implement.

    The UI of an app is one of the most important things to get right, as it’s the first thing people see when using your app. People can and will judge whether to use an app based purely on how the UI looks. But it’s not only about the UI; you also have to think about the user experience.