import {app, screen, BrowserWindow, ipcMain} from 'electron';
import path from 'path';

import {mkdirp, ipcDecorator} from './main/helpers';
import {APP_DATA_PATH} from './main/constants';
import {sequelize} from './main/models';

import * as folder from './main/controllers/folder';

const ipc = ipcDecorator.decorate(ipcMain);

sequelize.sync()
  .then(init);

function init() {

  let mainWindow = null;

  app.on('window-all-closed', () => {
    app.quit();
  });

  app.on('ready', () => {

    const {width, height} = screen.getPrimaryDisplay().workAreaSize;
    mainWindow = new BrowserWindow({width, height});

    mainWindow.loadURL('file://' + __dirname + '/index.html');

    mainWindow.on('close', (event) => {
    });

    mainWindow.on('closed', () => {
      mainWindow = null;
    });
  });

  ipc.on('GET /folders', folder.listFolders);
}

@@ -282,107 +282,8 @@
 ';%0A%0A
-const ipc = ipcDecorator.decorate(ipcMain);%0A%0Asequelize.sync()%0A  .then(init);%0A%0Afunction init() %7B%0A%0A  
 let 
@@ -302,18 +302,16 @@
  null;%0A%0A
-  
 app.on('
@@ -338,18 +338,16 @@
 () =%3E %7B%0A
-  
   app.qu
@@ -352,25 +352,21 @@
 quit();%0A
-  
 %7D);%0A%0A
-  
 app.on('
@@ -377,19 +377,55 @@
 y', 
-() =%3E
+handleAppReady);%0A%0Afunction handleAppReady()
  %7B%0A%0A
-  
   co
@@ -487,18 +487,16 @@
 eaSize;%0A
-  
   mainWi
@@ -535,26 +535,24 @@
  height%7D);%0A%0A
-  
   mainWindow
@@ -556,59 +556,40 @@
 dow.
-loadURL('file://' + __dirname + '/index.html');%0A%0A  
+on('close', (event) =%3E %7B%0A  %7D);%0A%0A
   ma
@@ -602,33 +602,29 @@
 ow.on('close
+d
 ', (
-event
 ) =%3E %7B%0A    %7D
@@ -626,72 +626,193 @@
     
-%7D);%0A%0A    mainWindow.on('closed', () =%3E %7B%0A      mainWindow = null
+mainWindow = null;%0A  %7D);%0A%0A  sequelize.sync()%0A    .then(() =%3E %7B%0A      mainWindow.loadURL('file://' + __dirname + '/index.html');%0A    %7D)%0A    .catch((err) =%3E %7B%0A      log.error('err:', err)
 ;%0A  
@@ -817,19 +817,60 @@
     %7D);%0A
+%0A
   
-%7D
+const ipc = ipcDecorator.decorate(ipcMain
 );%0A%0A  ip

refactor main.js