-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (62 loc) · 1.91 KB
/
main.js
File metadata and controls
77 lines (62 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const electron = require('electron');
var path = require('path');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var authWindow = require('./authWindow');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
function createWindow (railsApp) {
const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize;
mainWindow = new BrowserWindow({
width: width,
height: height,
icon: path.join(__dirname, 'app/assets/images/pinte_squared.png'),
show: false,
});
mainWindow.once('ready-to-show', function() {
mainWindow.show();
});
mainWindow.setMenu(null);
mainWindow.loadURL('http://localhost:2626');
mainWindow.on('closed', function() {
if (railsApp) {
railsApp.kill('SIGINT');
}
mainWindow = null;
});
}
app.on('ready', function() {
var env = Object.create(process.env);
env.LOG_LEVEL = 'INFO';
var railsApp;
var rp = require('request-promise');
rp('http://localhost:2626').catch(function () {
railsApp = require('child_process').spawn('bundle', ['exec', 'rails', 's'], { stdio: 'inherit', env: env });
});
function start() {
rp('http://localhost:2626').then(function () {
console.log('Rails server started!'); // eslint-disable-line no-console
createWindow(railsApp);
}).catch(function () {
console.log('Waiting on server to start...'); // eslint-disable-line no-console
setTimeout(start, 1000);
});
}
start();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
app.on('login', (event, webContents, request, authInfo, callback) => {
event.preventDefault();
authWindow.createAuthWindow(mainWindow, callback);
});