[Distribution]
Run with UI in background Console logs
This commit is contained in:
1 parent
d76ee9274f
commit
fe1b93391d
2 files changed
+124
-113
No files matched your search
+9
-62
@@ -10,7 +10,7 @@
|
|||||||
.log-warn { color: orange }
|
.log-warn { color: orange }
|
||||||
.log-error { color: red }
|
.log-error { color: red }
|
||||||
.log-info { color: skyblue }
|
.log-info { color: skyblue }
|
||||||
.log-log { color: silver }
|
.log-log { color: silver}
|
||||||
|
|
||||||
.log-warn, .log-error { font-weight: bold; }
|
.log-warn, .log-error { font-weight: bold; }
|
||||||
</style>
|
</style>
|
||||||
@@ -24,75 +24,22 @@
|
|||||||
<script>
|
<script>
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
window.api.receive('fromMain', (data) => {
|
window.api.receive('fromMain', (data) => {
|
||||||
//const consoleLine = document.createElement('span')
|
|
||||||
//const consoleLineText = document.createTextNode(data)
|
|
||||||
//consoleLine.appendChild(consoleLineText)
|
|
||||||
if(data.includes('[ERROR]')) {
|
if(data.includes('[ERROR]')) {
|
||||||
//const consoleLine = document.createElement('span')
|
|
||||||
document.getElementById('log').insertAdjacentHTML('beforeend', "<span class=\"log-error\">" + data + "</span><br>");
|
document.getElementById('log').insertAdjacentHTML('beforeend', "<span class=\"log-error\">" + data + "</span><br>");
|
||||||
}
|
}
|
||||||
if(data.includes('[WARN]')) {
|
else if(data.includes('[WARN]')) {
|
||||||
//consoleLineText.style.cssText = "color: orange; font-weight: bold;"
|
|
||||||
document.getElementById('log').insertAdjacentHTML('beforeend',"<span class=\"log-warn\">" + data + "</span><br>");
|
document.getElementById('log').insertAdjacentHTML('beforeend',"<span class=\"log-warn\">" + data + "</span><br>");
|
||||||
}
|
}
|
||||||
document.getElementById('log').insertAdjacentHTML('beforeend',"<span class=\"log-info\">" + data + "</span><br>");
|
else if(data.includes('[INFO]')) {
|
||||||
//document.getElementById('log').insertAdjacentHTML('beforeend', consoleLineText);
|
document.getElementById('log').insertAdjacentHTML('beforeend',"<span class=\"log-info\">" + data + "</span><br>");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('log').insertAdjacentHTML('beforeend',"<span class=\"log-log\">" + data + "</span><br>");
|
||||||
|
}
|
||||||
|
window.scrollTo(0, document.querySelector("#log-container").scrollHeight)
|
||||||
})
|
})
|
||||||
window.api.send("toMain", "ImAlive!")
|
window.api.send("toMain", "ImAlive!")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- <script>
|
|
||||||
rewireLoggingToElement(
|
|
||||||
() => document.getElementById("log"),
|
|
||||||
() => document.getElementById("log-container"), true);
|
|
||||||
|
|
||||||
function rewireLoggingToElement(eleLocator, eleOverflowLocator, autoScroll) {
|
|
||||||
fixLoggingFunc('log');
|
|
||||||
fixLoggingFunc('debug');
|
|
||||||
fixLoggingFunc('warn');
|
|
||||||
fixLoggingFunc('error');
|
|
||||||
fixLoggingFunc('info');
|
|
||||||
|
|
||||||
function fixLoggingFunc(name) {
|
|
||||||
console['old' + name] = console[name];
|
|
||||||
console[name] = function(...arguments) {
|
|
||||||
//const output = produceOutput(name, arguments);
|
|
||||||
output = window.api.receive('fromMain', (message, arguments) => {
|
|
||||||
produceOutput(message, arguments)
|
|
||||||
})
|
|
||||||
const eleLog = eleLocator();
|
|
||||||
|
|
||||||
if (autoScroll) {
|
|
||||||
const eleContainerLog = eleOverflowLocator();
|
|
||||||
const isScrolledToBottom = eleContainerLog.scrollHeight - eleContainerLog.clientHeight <= eleContainerLog.scrollTop + 1;
|
|
||||||
eleLog.innerHTML += output + "<br>";
|
|
||||||
if (isScrolledToBottom) {
|
|
||||||
eleContainerLog.scrollTop = eleContainerLog.scrollHeight - eleContainerLog.clientHeight;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eleLog.innerHTML += output + "<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
console['old' + name].apply(undefined, arguments);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function produceOutput(name, args) {
|
|
||||||
return args.reduce((output, arg) => {
|
|
||||||
return output +
|
|
||||||
"<span class=\"log-" + (typeof arg) + " log-" + name + "\">" +
|
|
||||||
(typeof arg === "object" && (JSON || {}).stringify ? JSON.stringify(arg) : arg) +
|
|
||||||
"</span> ";
|
|
||||||
}, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* setInterval(() => {
|
|
||||||
const method = (['log', 'debug', 'warn', 'error', 'info'][Math.floor(Math.random() * 5)]);
|
|
||||||
console[method](method, 'logging something...');
|
|
||||||
}, 200); */
|
|
||||||
</script> -->
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+115
-51
@@ -1,55 +1,50 @@
|
|||||||
const {app, Menu, BrowserWindow, ipcMain} = require('electron')
|
const {app, Menu, BrowserWindow, ipcMain, dialog } = require('electron')
|
||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
// To check for update on Github repo
|
// To check for update on Github repo
|
||||||
const {autoUpdater} = require("electron-updater")
|
const {autoUpdater} = require("electron-updater")
|
||||||
const { windowsStore } = require('process')
|
|
||||||
|
|
||||||
// Enable non contribution mode (test)
|
// Enable non contribution mode (test)
|
||||||
process.env.SA_MODE = 'gitDisable'
|
process.env.SA_MODE = 'gitDisable'
|
||||||
process.env.PACKAGED_PATH = app.getAppPath()
|
process.env.PACKAGED_PATH = app.getAppPath()
|
||||||
process.env.DATA_PATH = app.getPath('documents')
|
process.env.DATA_PATH = app.getPath('documents')
|
||||||
|
|
||||||
const WINDOW_WIDTH = null
|
const WINDOW_WIDTH = 1280
|
||||||
const WINDOW_HEIGHT = null
|
const WINDOW_HEIGHT = 768
|
||||||
|
|
||||||
let mainWindow, consoleWindow, platform
|
let mainWindow, consoleWindow, platform
|
||||||
|
|
||||||
var app_ready = false
|
|
||||||
var server_ready = false
|
|
||||||
|
|
||||||
const port = 34248 // Default HTTP port
|
const port = 34248 // Default HTTP port
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
||||||
//var platform = null
|
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
const { fork } = require('child_process')
|
const { fork } = require('child_process')
|
||||||
platform = fork(path.join(__dirname, '/PlatformRoot.js'), ["noBrowser"], {stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: process.env})
|
platform = fork(path.join(__dirname, '/PlatformRoot.js'), ["noBrowser"], {stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: process.env})
|
||||||
|
|
||||||
//var consoleOutput = ""
|
|
||||||
|
|
||||||
platform.on('message', _ => {
|
platform.on('message', _ => {
|
||||||
open()
|
openMain()
|
||||||
|
openConsoleWindow()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on("toMain", (event, args) => {
|
ipcMain.on("toMain", (event, args) => {
|
||||||
platform.stdout.setEncoding('utf8')
|
if (args === "ImAlive!" && consoleWindow) {
|
||||||
platform.stdout.on('data', (data) => {
|
platform.stdout.setEncoding('utf8')
|
||||||
//data = data.toString()
|
platform.stdout.on('data', (data) => {
|
||||||
//consoleOutput += data
|
if(consoleWindow != null) {
|
||||||
consoleWindow.webContents.send("fromMain", data);
|
consoleWindow.webContents.send("fromMain", data);
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function open () {
|
function openMain () {
|
||||||
let bw_options = {
|
let bw_options = {
|
||||||
width: WINDOW_WIDTH ? WINDOW_WIDTH : 1280,
|
width: WINDOW_WIDTH,
|
||||||
height: WINDOW_HEIGHT ? WINDOW_HEIGHT : 768,
|
height: WINDOW_HEIGHT,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: false, // is default value after Electron v5
|
nodeIntegration: false, // is default value after Electron v5
|
||||||
@@ -62,33 +57,55 @@ function open () {
|
|||||||
bw_options
|
bw_options
|
||||||
)
|
)
|
||||||
|
|
||||||
//mainWindow.setResizable(true)
|
createMainMenus()
|
||||||
|
|
||||||
mainWindow.loadURL("http://localhost:" + port)
|
mainWindow.loadURL("http://localhost:" + port)
|
||||||
|
|
||||||
// w.webContents.openDevTools()
|
mainWindow.on('close', function (e) {
|
||||||
|
if (consoleWindow.isVisible()) {
|
||||||
|
e.preventDefault()
|
||||||
|
mainWindow.hide()
|
||||||
|
} else {
|
||||||
|
let choice = dialog.showMessageBoxSync(
|
||||||
|
mainWindow,
|
||||||
|
{
|
||||||
|
type: 'question',
|
||||||
|
buttons: ['Yes', 'No'],
|
||||||
|
title: 'Confirm',
|
||||||
|
message: 'Do you really want to close Superalgos?'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// 0 for Yes
|
||||||
|
if (choice === 0) {
|
||||||
|
mainWindow = null
|
||||||
|
app.exit()
|
||||||
|
}
|
||||||
|
// 1 for No
|
||||||
|
if (choice === 1) {
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow.on('closed', function () {
|
mainWindow.on('activate', function () {
|
||||||
mainWindow = null
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function openConsoleWindow() {
|
function openConsoleWindow() {
|
||||||
createConsoleMenus()
|
|
||||||
if(consoleWindow) {
|
if(consoleWindow) {
|
||||||
consoleWindow.focus()
|
consoleWindow.focus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newWindow =
|
|
||||||
consoleWindow = new BrowserWindow({
|
consoleWindow = new BrowserWindow({
|
||||||
resizable: true,
|
resizable: true,
|
||||||
title: 'Platform Logs',
|
title: 'Platform Logs',
|
||||||
minimizable: false,
|
minimizable: false,
|
||||||
fullscreenable: false,
|
fullscreenable: true,
|
||||||
width: 1024,
|
show: false,
|
||||||
|
width: WINDOW_WIDTH,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
devTools: true,
|
|
||||||
nodeIntegration: false, // is default value after Electron v5
|
nodeIntegration: false, // is default value after Electron v5
|
||||||
contextIsolation: true, // protect against prototype pollution
|
contextIsolation: true, // protect against prototype pollution
|
||||||
enableRemoteModule: false, // turn off remote
|
enableRemoteModule: false, // turn off remote
|
||||||
@@ -99,25 +116,42 @@ function openConsoleWindow() {
|
|||||||
consoleWindow.setBackgroundColor('#000000')
|
consoleWindow.setBackgroundColor('#000000')
|
||||||
consoleWindow.loadFile('./console.html')
|
consoleWindow.loadFile('./console.html')
|
||||||
|
|
||||||
/* consoleWindow.on('ready'), _ => {
|
|
||||||
platform.stdout.setEncoding('utf8')
|
|
||||||
platform.stdout.on('data', (data) => {
|
|
||||||
//data = data.toString()
|
|
||||||
//consoleOutput += data
|
|
||||||
consoleWindow.webContents.send("fromMain", data);
|
|
||||||
})
|
|
||||||
} */
|
|
||||||
|
|
||||||
consoleWindow.on('closed', function() {
|
consoleWindow.on('close', function (e) {
|
||||||
consoleWindow = null
|
if (mainWindow.isVisible()) {
|
||||||
|
e.preventDefault()
|
||||||
|
createMainMenus()
|
||||||
|
consoleWindow.hide()
|
||||||
|
} else {
|
||||||
|
let choice = dialog.showMessageBoxSync(
|
||||||
|
mainWindow,
|
||||||
|
{
|
||||||
|
type: 'question',
|
||||||
|
buttons: ['Yes', 'No'],
|
||||||
|
title: 'Confirm',
|
||||||
|
message: 'Do you really want to close Superalgos?'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// 0 for Yes
|
||||||
|
if (choice === 0) {
|
||||||
|
consoleWindow = null
|
||||||
|
app.exit()
|
||||||
|
}
|
||||||
|
// 1 for No
|
||||||
|
if (choice === 1) {
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
consoleWindow.on('show', function () {
|
||||||
|
createConsoleMenus()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
app_ready = true
|
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
createMainMenus()
|
createMainMenus()
|
||||||
if (server_ready) open()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
@@ -128,8 +162,16 @@ app.on('activate', function () {
|
|||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||||
})
|
})
|
||||||
|
|
||||||
function createMainMenus () {
|
function createMainMenus() {
|
||||||
const template = [
|
function logsActive() {
|
||||||
|
if(consoleWindow) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainTemplate = [
|
||||||
{
|
{
|
||||||
label: 'File',
|
label: 'File',
|
||||||
submenu: [
|
submenu: [
|
||||||
@@ -176,18 +218,32 @@ function createMainMenus () {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Logs',
|
label: 'Logs',
|
||||||
|
enabled: logsActive(),
|
||||||
click () {
|
click () {
|
||||||
openConsoleWindow()
|
if(consoleWindow) {
|
||||||
|
consoleWindow.show()
|
||||||
|
} else {
|
||||||
|
openConsoleWindow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const menu = Menu.buildFromTemplate(template)
|
const mainMenu = Menu.buildFromTemplate(mainTemplate)
|
||||||
Menu.setApplicationMenu(menu)
|
Menu.setApplicationMenu(mainMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createConsoleMenus () {
|
function createConsoleMenus () {
|
||||||
const template = [
|
|
||||||
|
function uiActive() {
|
||||||
|
if(mainWindow.isVisible()) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const consoleTemplate = [
|
||||||
{
|
{
|
||||||
label: 'File',
|
label: 'File',
|
||||||
submenu: [
|
submenu: [
|
||||||
@@ -222,9 +278,17 @@ function createConsoleMenus () {
|
|||||||
{type: 'separator'},
|
{type: 'separator'},
|
||||||
{role: 'togglefullscreen'}
|
{role: 'togglefullscreen'}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Show UI',
|
||||||
|
id: 'ui',
|
||||||
|
enabled: uiActive(),
|
||||||
|
click () {
|
||||||
|
mainWindow.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const menu = Menu.buildFromTemplate(template)
|
const consoleMenu = Menu.buildFromTemplate(consoleTemplate)
|
||||||
Menu.setApplicationMenu(menu)
|
Menu.setApplicationMenu(consoleMenu)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user