@Libman

I don't think so. In the future Google's ChromeOS will be a succeful OS (We 
know they're working on it):

  * focusing on app
  * easy to install
  * cheap to operate
  * looks beautiful
  * seamless connection to the network



Electron is not a simple adhesive, but a careful design:

> **Electron enables you to create desktop applications with pure JavaScript by 
> providing a runtime with rich native (operating system) APIs. This doesn’t 
> mean Electron is a JavaScript binding to graphical user interface (GUI) 
> libraries. Instead, Electron uses web pages as its GUI, so you could also see 
> it as a minimal Chromium browser, controlled by JavaScript.**
> 
> **In Electron, the process that runs package.json’s main script is called the 
> main process. Since Electron uses Chromium for displaying web pages, 
> Chromium’s multi-process architecture is also used. Each web page in Electron 
> runs in its own process, which is called the renderer process.**
> 
> **In order to keep Electron small (file size) and sustainable (the spread of 
> dependencies and APIs) the project limits the scope of the core project. 
> Electron uses just the rendering library from Chromium rather than all of 
> Chromium.**

As for JavaScript, Douglas Crockford said:

> **JavaScript is the world's most misunderstood programming language.**

JavaScript is becoming better than ever. I mean such as ECMAScript6 (Module, 
Class, generator, Promise) ECMAScript7 (async await). In addition, you can also 
choose excellent TypeScript:
    
    
    import { PackageDb } from './db'
    import { exec } from '../common/osproc'
    import { spawn } from 'child_process'
    
    export enum MessageQueueKind {
      uninstalling = 0, installing = 1
    }
    
    export interface MessageQueueEntry {
      packageId: number
      packageName: string
      kind: MessageQueueKind
    }
    
    export class PackageMessageQueue {
      private entries: Array<MessageQueueEntry>
      private running: boolean
      private distro: string
      private password: string
      private passwordOK: boolean
      private db: PackageDb
      
      constructor(dbfile: string, distro: string) {
        this.entries = []
        this.running = false
        this.distro = distro
        this.password = ''
        this.passwordOK = false
        this.db = new PackageDb(dbfile)
      }
      
      public setPassword(password: string): void {
        this.password = password
      }
      
      public async isPasswordOK() {
        if (!this.passwordOK) {
          this.passwordOK = await this.checkPassword()
        }
        return this.passwordOK
      }
      
      private spawn(cmd: string): Promise<void> {
        return new Promise<void>(function (complete, fail) {
          var prc = spawn(cmd, [], {
            shell: true,
            stdio: 'inherit'
          })
          prc.on('close', (code) => code == 0 ? complete() : fail(new 
Error('could not exec \'' + cmd + '\'')))
          prc.on('error', () => fail())
        })
      }
      
      private async checkPassword(): Promise<boolean> {
        try {
          console.log(`echo '${this.password}' | sudo -S sh -c 'whoami'`)
          var [output] = await exec(`echo '${this.password}' | sudo -S sh -c 
'whoami'`)
          if (output.replace(/\r?\n?$/, '') === 'root') {
            return true
          }
        } catch (e) {
          console.log('PackageMessageQueue.checkPassword:', e)
        }
        return false
      }
      
      public execIfNotRunning() {
        if (!this.running) {
          this.exec()
        }
      }
      
      public isInQueue(packageId: number): boolean {
        for (var entry of this.entries) {
          if (entry.packageId === packageId) {
            return true
          }
        }
        return false
      }
      
      // ...
    }
    

Reply via email to