Further developed logging for electron.

This commit is contained in:
Sebastian Kupke 2019-05-24 10:29:10 +02:00
parent 7f4b7fb1ff
commit 35773f4a18
5 changed files with 115 additions and 12 deletions

35
dist/iwmlib.js vendored
View File

@ -1545,6 +1545,12 @@
}
const ipc = null;
try {
ipc = require('electron').ipcRenderer;
} catch (e) {}
/** Basic class for app specific logging requirements.
* Can be used to implement persistent logging in electron apps.
*/
@ -1553,8 +1559,13 @@
/** Static log function.
* @param {*} message
*/
log(message) {
console.log(message);
static log(message) {
if (ipc) {
ipc.send('log', message);
} else {
console.log(message);
}
}
}
@ -2683,10 +2694,26 @@
/**
* Distincts if the app is running inside electron or not.
*
* source: https://discuss.atom.io/t/detect-electron-or-web-page-running/33180/3
* source: https://github.com/cheton/is-electron
*/
static get isElectron() {
return typeof process != 'undefined' && process.versions && process.versions.electron !== undefined
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true
}
// Detect the user agent when the `nodeIntegration` option is set to true
if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
return true
}
return false
}
/** Returns the display resolution. Necessary for retina displays.

35
dist/iwmlib.pixi.js vendored
View File

@ -4709,6 +4709,12 @@
// }
}
const ipc = null;
try {
ipc = require('electron').ipcRenderer;
} catch (e) {}
/** Basic class for app specific logging requirements.
* Can be used to implement persistent logging in electron apps.
*/
@ -4717,8 +4723,13 @@
/** Static log function.
* @param {*} message
*/
log(message) {
console.log(message);
static log(message) {
if (ipc) {
ipc.send('log', message);
} else {
console.log(message);
}
}
}
@ -5847,10 +5858,26 @@
/**
* Distincts if the app is running inside electron or not.
*
* source: https://discuss.atom.io/t/detect-electron-or-web-page-running/33180/3
* source: https://github.com/cheton/is-electron
*/
static get isElectron() {
return typeof process != 'undefined' && process.versions && process.versions.electron !== undefined
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true
}
// Detect the user agent when the `nodeIntegration` option is set to true
if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
return true
}
return false
}
/** Returns the display resolution. Necessary for retina displays.

View File

@ -37,10 +37,26 @@ export class Capabilities {
/**
* Distincts if the app is running inside electron or not.
*
* source: https://discuss.atom.io/t/detect-electron-or-web-page-running/33180/3
* source: https://github.com/cheton/is-electron
*/
static get isElectron() {
return typeof process != 'undefined' && process.versions && process.versions.electron !== undefined
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true
}
// Detect the user agent when the `nodeIntegration` option is set to true
if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
return true
}
return false
}
/** Returns the display resolution. Necessary for retina displays.

22
lib/logging.html Normal file
View File

@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<title>Logging Doctest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="./3rdparty/highlight/styles/default.css">
<link rel="stylesheet" href="../css/doctest.css">
<script src="./3rdparty/highlight/highlight.pack.js"></script>
<script src="../dist/iwmlib.3rdparty.js"></script>
<script src="../dist/iwmlib.js"></script>
</head>
<body id="page" onload="Doctest.run()">
<h1>
Logging
</h1>
<p>Store informations of your app permanently.</p>
<script class="doctest">
Logging.log('app started')
</script>
</body>

View File

@ -1,3 +1,9 @@
const ipc = null
try {
ipc = require('electron').ipcRenderer
} catch (e) {}
/** Basic class for app specific logging requirements.
* Can be used to implement persistent logging in electron apps.
*/
@ -6,7 +12,12 @@ export default class Logging {
/** Static log function.
* @param {*} message
*/
log(message) {
console.log(message)
static log(message) {
if (ipc) {
ipc.send('log', message)
} else {
console.log(message)
}
}
}