Further developed logging for electron.
This commit is contained in:
parent
7f4b7fb1ff
commit
35773f4a18
33
dist/iwmlib.js
vendored
33
dist/iwmlib.js
vendored
@ -1545,6 +1545,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ipc = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ipc = require('electron').ipcRenderer;
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
/** Basic class for app specific logging requirements.
|
/** Basic class for app specific logging requirements.
|
||||||
* Can be used to implement persistent logging in electron apps.
|
* Can be used to implement persistent logging in electron apps.
|
||||||
*/
|
*/
|
||||||
@ -1553,10 +1559,15 @@
|
|||||||
/** Static log function.
|
/** Static log function.
|
||||||
* @param {*} message
|
* @param {*} message
|
||||||
*/
|
*/
|
||||||
log(message) {
|
static log(message) {
|
||||||
|
|
||||||
|
if (ipc) {
|
||||||
|
ipc.send('log', message);
|
||||||
|
} else {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* globals Hammer, propagating */
|
/* globals Hammer, propagating */
|
||||||
|
|
||||||
@ -2683,10 +2694,26 @@
|
|||||||
/**
|
/**
|
||||||
* Distincts if the app is running inside electron or not.
|
* 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() {
|
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.
|
/** Returns the display resolution. Necessary for retina displays.
|
||||||
|
33
dist/iwmlib.pixi.js
vendored
33
dist/iwmlib.pixi.js
vendored
@ -4709,6 +4709,12 @@
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ipc = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ipc = require('electron').ipcRenderer;
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
/** Basic class for app specific logging requirements.
|
/** Basic class for app specific logging requirements.
|
||||||
* Can be used to implement persistent logging in electron apps.
|
* Can be used to implement persistent logging in electron apps.
|
||||||
*/
|
*/
|
||||||
@ -4717,10 +4723,15 @@
|
|||||||
/** Static log function.
|
/** Static log function.
|
||||||
* @param {*} message
|
* @param {*} message
|
||||||
*/
|
*/
|
||||||
log(message) {
|
static log(message) {
|
||||||
|
|
||||||
|
if (ipc) {
|
||||||
|
ipc.send('log', message);
|
||||||
|
} else {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* globals Hammer, propagating */
|
/* globals Hammer, propagating */
|
||||||
|
|
||||||
@ -5847,10 +5858,26 @@
|
|||||||
/**
|
/**
|
||||||
* Distincts if the app is running inside electron or not.
|
* 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() {
|
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.
|
/** Returns the display resolution. Necessary for retina displays.
|
||||||
|
@ -37,10 +37,26 @@ export class Capabilities {
|
|||||||
/**
|
/**
|
||||||
* Distincts if the app is running inside electron or not.
|
* 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() {
|
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.
|
/** Returns the display resolution. Necessary for retina displays.
|
||||||
|
22
lib/logging.html
Normal file
22
lib/logging.html
Normal 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>
|
@ -1,3 +1,9 @@
|
|||||||
|
const ipc = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
ipc = require('electron').ipcRenderer
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
/** Basic class for app specific logging requirements.
|
/** Basic class for app specific logging requirements.
|
||||||
* Can be used to implement persistent logging in electron apps.
|
* Can be used to implement persistent logging in electron apps.
|
||||||
*/
|
*/
|
||||||
@ -6,7 +12,12 @@ export default class Logging {
|
|||||||
/** Static log function.
|
/** Static log function.
|
||||||
* @param {*} message
|
* @param {*} message
|
||||||
*/
|
*/
|
||||||
log(message) {
|
static log(message) {
|
||||||
|
|
||||||
|
if (ipc) {
|
||||||
|
ipc.send('log', message)
|
||||||
|
} else {
|
||||||
console.log(message)
|
console.log(message)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user