Completed
Push — master ( d88391...473b86 )
by Dimas
221:13 queued 206:00
created

libs/src/electron/main.js   A

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 136
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 68
dl 0
loc 136
rs 10
c 0
b 0
f 0
wmc 9
mnd 3
bc 3
fnc 6
bpm 0.5
cpm 1.5
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A main.js ➔ createWindow 0 32 5
1
const electron = require('electron')
2
// Module to control application life.
3
const app = electron.app
4
// Module for mennu
5
const Menu = electron.Menu
6
// Module to create native browser window.
7
const BrowserWindow = electron.BrowserWindow
8
9
const path = require('path')
0 ignored issues
show
Unused Code introduced by
The constant path seems to be never used. Consider removing it.
Loading history...
10
const url = require('url')
0 ignored issues
show
Unused Code introduced by
The constant url seems to be never used. Consider removing it.
Loading history...
11
12
/////////////////////////////
13
14
///////////////////////////////
15
// Copy paste fixed by this 
16
17
app.on('ready', () => {
18
//  createWindow() // commented for avoiding double window issue
19
  if (process.platform === 'darwin') {
20
    var template = [{
21
      label: 'FromScratch',
22
      submenu: [{
23
        label: 'Quit',
24
        accelerator: 'CmdOrCtrl+Q',
25
        click: function() { app.quit(); }
26
      }]
27
    }, {
28
      label: 'Edit',
29
      submenu: [{
30
        label: 'Undo',
31
        accelerator: 'CmdOrCtrl+Z',
32
        selector: 'undo:'
33
      }, {
34
        label: 'Redo',
35
        accelerator: 'Shift+CmdOrCtrl+Z',
36
        selector: 'redo:'
37
      }, {
38
        type: 'separator'
39
      }, {
40
        label: 'Cut',
41
        accelerator: 'CmdOrCtrl+X',
42
        selector: 'cut:'
43
      }, {
44
        label: 'Copy',
45
        accelerator: 'CmdOrCtrl+C',
46
        selector: 'copy:'
47
      }, {
48
        label: 'Paste',
49
        accelerator: 'CmdOrCtrl+V',
50
        selector: 'paste:'
51
      }, {
52
        label: 'Select All',
53
        accelerator: 'CmdOrCtrl+A',
54
        selector: 'selectAll:'
55
      }]
56
    }];
57
    var osxMenu = Menu.buildFromTemplate(template);
58
    Menu.setApplicationMenu(osxMenu);
59
  }
60
})
61
62
// PHP SERVER CREATION /////
63
const PHPServer = require('php-server-manager');
64
65
const server = new PHPServer({
66
  
67
    port: 5555,
68
    directory: __dirname,
69
    directives: {
70
        display_errors: 1,
71
        expose_php: 1
72
    }
73
});
74
75
//////////////////////////
76
77
// Keep a global reference of the window object, if you don't, the window will
78
// be closed automatically when the JavaScript object is garbage collected.
79
let mainWindow
80
81
function createWindow () {
82
83
  server.run();
84
  // Create the browser window.
85
  mainWindow = new BrowserWindow({width: 800, height: 600})
86
87
  // and load the index.html of the app.
88
  mainWindow.loadURL('http://'+server.host+':'+server.port+'/')
89
90
/*
91
mainWindow.loadURL(url.format({
92
  pathname: path.join(__dirname, 'index.php'),
93
  protocol: 'file:',
94
  slashes: true
95
}))
96
*/
97
 const {shell} = require('electron')
98
 shell.showItemInFolder('fullPath')
99
100
  // Open the DevTools.
101
  // mainWindow.webContents.openDevTools()
102
103
  // Emitted when the window is closed.
104
  mainWindow.on('closed', function () {
105
    // Dereference the window object, usually you would store windows
106
    // in an array if your app supports multi windows, this is the time
107
    // when you should delete the corresponding element.
108
    // PHP SERVER QUIT
109
    server.close();
110
    mainWindow = null;
111
  })
112
}
113
114
// This method will be called when Electron has finished
115
// initialization and is ready to create browser windows.
116
// Some APIs can only be used after this event occurs.
117
//app.on('ready', createWindow) // <== this is extra so commented, enabling this can show 2 windows..
118
119
// Quit when all windows are closed.
120
app.on('window-all-closed', function () {
121
  // On OS X it is common for applications and their menu bar
122
  // to stay active until the user quits explicitly with Cmd + Q
123
  if (process.platform !== 'darwin') {
124
    // PHP SERVER QUIT
125
    server.close();
126
    app.quit();
127
  }
128
})
129
130
app.on('activate', function () {
131
  // On OS X it's common to re-create a window in the app when the
132
  // dock icon is clicked and there are no other windows open.
133
  if (mainWindow === null) {
134
    createWindow()
135
  }
136
})
137
138
139
140
// In this file you can include the rest of your app's specific main process
141
// code. You can also put them in separate files and require them here.
142