This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e61a60
commit 908e9ab
Showing
43 changed files
with
369 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
MANAGER_LISTEN_URL_GET_REQ: 'MANAGER_LISTEN_URL_GET_REQ', | ||
MANAGER_START_REQ: 'MANAGER_START_REQ', | ||
MANAGER_START_RES: 'MANAGER_START_RES', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { app } = require('electron'); | ||
|
||
const manager = null; | ||
const listenURL = app.commandLine.getSwitchValue('listen-url') || 'http://127.0.0.1:8080'; | ||
const window = null; | ||
|
||
module.exports = { | ||
listenURL, | ||
manager, | ||
window, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../public/assets/512x512.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,48 @@ | ||
require('./ipc'); | ||
const { | ||
app, | ||
BrowserWindow, | ||
Menu, | ||
} = require('electron'); | ||
const path = require('path'); | ||
const { spawn } = require('child_process'); | ||
const menu = require('./menu'); | ||
const { isPortFree } = require('./utils/net'); | ||
const globals = require('./globals'); | ||
|
||
Menu.setApplicationMenu(menu); | ||
app.commandLine.appendSwitch('ignore-certificate-errors', 'true'); | ||
|
||
const listenURL = app.commandLine.getSwitchValue('listen-url') || 'http://localhost:8080'; | ||
let manager = null; | ||
|
||
const createWindow = () => { | ||
const createMainWindow = () => { | ||
const window = new BrowserWindow({ | ||
show: false, | ||
height: 480, | ||
autoHideMenuBar: true, | ||
height: 720, | ||
icon: path.join(__dirname, 'icon.png'), | ||
title: 'Sentinel', | ||
width: 852, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
}, | ||
width: 1280, | ||
}); | ||
|
||
window.loadFile(path.join(__dirname, '../build/index.html')) | ||
.then(() => { | ||
window.show(); | ||
}) | ||
.catch(console.error); | ||
const indexFile = path.join(__dirname, '../build/index.html'); | ||
window.loadFile(indexFile).then().catch(console.error); | ||
|
||
globals.window = window; | ||
}; | ||
|
||
app.on('ready', () => { | ||
const url = new URL(listenURL); | ||
isPortFree(url.port, url.hostname, (error) => { | ||
if (error) { | ||
console.error(error); | ||
app.quit(); | ||
} else { | ||
manager = spawn( | ||
path.join(__dirname, '../bin/manager'), | ||
[ | ||
'server', | ||
'--listen-url', | ||
listenURL, | ||
], | ||
{ | ||
detached: false, | ||
}, | ||
); | ||
manager.stdout.on('data', (data) => { | ||
data = data.toString().trim(); | ||
console.log(data); | ||
}); | ||
manager.stderr.on('data', (data) => { | ||
data = data.toString().trim(); | ||
console.error(data); | ||
}); | ||
|
||
let created = false; | ||
manager.stdout.on('data', (data) => { | ||
if (created) { | ||
return; | ||
} | ||
|
||
data = data.toString().trim(); | ||
if (data.indexOf('Listening on URL') === -1) { | ||
app.quit(); | ||
} | ||
|
||
created = true; | ||
createWindow(); | ||
}); | ||
manager.stderr.on('data', () => { | ||
app.quit(); | ||
}); | ||
} | ||
}); | ||
createMainWindow(); | ||
}); | ||
|
||
app.on('window-all-closed', () => { | ||
app.quit(); | ||
}); | ||
|
||
app.on('will-quit', () => { | ||
manager.kill(); | ||
globals.manager.kill(); | ||
}); | ||
|
||
app.on('activate', () => { | ||
if (BrowserWindow.getAllWindows().length === 0) { | ||
createWindow(); | ||
createMainWindow(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const path = require('path'); | ||
const { spawn } = require('child_process'); | ||
const { ipcMain } = require('electron'); | ||
const { | ||
MANAGER_LISTEN_URL_GET_REQ, | ||
MANAGER_START_REQ, | ||
MANAGER_START_RES, | ||
} = require('./channels'); | ||
const globals = require('./globals'); | ||
|
||
ipcMain.on(MANAGER_LISTEN_URL_GET_REQ, (event, args) => { | ||
console.log('EVENT:', MANAGER_LISTEN_URL_GET_REQ, 'ARGS:', args); | ||
|
||
event.returnValue = globals.listenURL; | ||
}); | ||
|
||
ipcMain.on(MANAGER_START_REQ, (event, args) => { | ||
console.log('EVENT:', MANAGER_START_REQ, 'ARGS:', args); | ||
|
||
const manager = spawn( | ||
path.join(__dirname, '../bin/manager'), | ||
['server', '--listen-url', globals.listenURL], | ||
{ detached: false }, | ||
); | ||
|
||
let error = false; | ||
let success = false; | ||
|
||
manager.stderr.on('data', (data) => { | ||
data = data.toString().trim(); | ||
console.error(data); | ||
|
||
if (error) { | ||
return; | ||
} | ||
|
||
error = true; | ||
globals.window.webContents.send(MANAGER_START_RES, { | ||
success: false, | ||
data, | ||
}); | ||
}); | ||
manager.stdout.on('data', (data) => { | ||
data = data.toString().trim(); | ||
console.log(data); | ||
|
||
if (success) { | ||
return; | ||
} | ||
|
||
success = true; | ||
globals.window.webContents.send(MANAGER_START_RES, { | ||
success: true, | ||
data, | ||
}); | ||
}); | ||
|
||
globals.manager = manager; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,6 @@ const template = [ | |
{ | ||
label: 'View', | ||
submenu: [ | ||
{ | ||
role: 'reload', | ||
}, | ||
{ | ||
role: 'toggleDevTools', | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { ipcRenderer } = require('electron'); | ||
|
||
window.ipcRenderer = ipcRenderer; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,12 @@ | |
"version": "0.3.0-rc0", | ||
"main": "./electron/index.js", | ||
"homepage": "./", | ||
"description": "Sentinel desktop and web client.", | ||
"author": { | ||
"name": "Sentinel", | ||
"email": "[email protected]", | ||
"url": "https://sentinel.co" | ||
}, | ||
"private": true, | ||
"devDependencies": { | ||
"@material-ui/core": "^4.11.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.