concept application in category electron

appears as: pplications, pplication, n application, application, The application, applications, Applications, An application, Application
Electron in Action

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

  • This combination allows you to build applications that can access the filesystem and compiled modules, as well as render a UI and use web APIs.
  • Electron is used by applications large and small such as Atom, Microsoft’s Visual Studio Code, and Slack.
  • 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>

    In the previous chapter, we created an application that lived in the menu bar on macOS or the system tray on Windows. Out of the box, Electron’s tray module allows you to set a menu to display when the user clicks the tray icon. This is the same type of menu used in the application and context menus that we built in Fire Sale. This menu also has the same limitations: it is limited to text, is hard to modify, and provides limited functionality.

    Being able to build applications that live in the system tray or menu bar allows us to build entire classes of applications that we couldn’t build in the browser. It’s unfortunate that we have these restrictions, but—luckily—we can work around them. In this chapter, we explore a clever way to get around the limitations of the tray module using a third-party library conveniently called menubar.

    In this chapter, we’ll rebuild Clipmaster from the ground up into a completely new application. This time it has a much more pleasant UI, shown in figure 10.1, compared to its predecessor. We add the ability to remove a clipping from the list or publish it to the web using an example API so that it can be shared publicly. Finally, we add some interactivity to our notifications and global shortcuts to trigger the application’s functionality using predetermined keystrokes.

    Figure 10.1. This is what the application will look like at the end of the chapter.
    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.

    Listing 2.2. The main.js file for the Electron app
    'use strict'; const electron = require('electron'); #1 const app = electron.app; const BrowserWindow = electron.BrowserWindow; let mainWindow = null; #2 app.on('window-all-closed',() => { #3 if (process.platform !== 'darwin') app.quit(); }); app.on('ready', () => { #4 mainWindow = new BrowserWindow(); mainWindow.loadURL(`file://${app.getAppPath()}/index.html`); mainWindow.on('closed', () => { mainWindow = null; }); }); #1 - Electron is loaded via npm #2 - mainWindow variable keeps application’s main window in JavaScript context, so garbage collection, which would close application window, doesn’t remove it #3 - Mimics UX of Windows and Linux applications — closing only application window for app quits app; on Mac OS, closing application window doesn’t close app #4 - When app is ready to run, tells main window to load index.html, and when that window is closed, sets mainWindow variable to null

    The Electron version of the application starts off very much in the same fashion. You’ll begin by creating a folder named lorikeet-electron. You can do this by running this command in the Terminal/Command Prompt:

    mkdir lorikeet-electron

    This will create a folder named lorikeet-electron. This is the main application folder for the application, and inside it will be the application’s files. Now you’ll create the next file needed by the application, the package.json file. In your terminal or via your text editor, create a file named package.json inside the lorikeet-electron folder: