Skip to main content

Getting started with Electron Pt 1.

Electron is a fun and easy way to create desktop application from an mostly web based code. Of course websites aren't the most performance way to create an user-interface ( in terms of technical aspects such as memory, cpu consumption) but it's an extremely powerful experience rich way of doing that.




There are a lot of apps these days that work similarly: slack, visual studio code. These desktop version they are enriched with features that merely a browser cannot fulfill by itself.


1. Checkout the code from github
2. cd directory && npm install && npm start

You should now have a working electron mini browser working. By default it loads a page from the directory itself. You can change this to any type of url, even ones from internet itself. Like below is already enough to load google.com

function createWindow () {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 800, height: 600, icon: path.join(__dirname, 'favicon.ico'), title: 'Reimburse-It' }) 


mainWindow.loadURL('https://google.com')


 If you want to customize the menu you need to do a little bit more changes. It starts by importing electron.Menu into your namespace. This holds two functions buildFromTemplate and
setApplicationMenu to create and change the menu.


const electron = require('electron')
// Module to control application life.
const app = electron.app
const Menu = electron.Menu 

Now for the actual dirt on actually creating an electron menu see below:

const template = [
  {
    label: 'File',
    submenu: [
      {role: 'minimize'},
      {role: 'close', 'label': 'Quit Application'}
    ]
  },  
  {
    label: 'Edit',
    submenu: [
      {role: 'undo'},
      {role: 'redo'},
      {type: 'separator'},
      {role: 'cut'},
      {role: 'copy'},
      {role: 'paste'},
    ]
  },
  {
    role: 'help',
    submenu: [
      {
        label: 'Learn More',
        click () { require('electron').shell.openExternal('https://google.com') }
      },
      {
        label: 'Articles & Discussion',
        click () { require('electron').shell.openExternal('http://blog.google.com') }
      }        
    ]
  }
]
  
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

Comments

Popular posts from this blog

Material & shader management

In the upcoming changes in my editor I implemented the material system inspired on  Frostbite engine of DICE, binaries are download-able on the project page. Also I've implemented an conversion tool and file-format for future mesh formats using Assimp.

A visual approach to programming

It's been a while since I had opportunity to write anything, with the added misfortune of a hardware deficit but seemingly still had some backups to recover old older entries. Over the years I've taken a interest in language theory and in particular visual programming. Inspired by Unreal Kismet, CryEngine Flow and BitSquid Flow; I too set out myself of creating a similar environment. Primarily I just wanted a visual language as I believed they hold a certain productivity value. My initial designs were of a very object-orientated nature. However this approach just never felt right to me. It means you are going to increase post-deserialization time due to v-table fix-ups but it is also takes dexterity to maintain the code hierarchy required. So what I really wanted to do was design a system a) that reduces post-deserialization times to a bare minimum b) was not inheritance heavy c) small enough to be embeddable. On of the interesting methods that I considered was generating m...

Roadtrip to Germany-Switzerland-Austria-Czech pt. 1

Last month I had the luxury to go down for a road trip through various countries in Germany. Despite it being early fall season we actually had a lot of sunshine, and it was uncanny to see the beautiful scenery we passed through. Our favorite place was on the road from Salzburg to Halstadt where we were headed for the famous sky outlook. We came across a lake surrounded by mountains (presumable alps), the nature is unfathomable.