How to use the electron-util.is.renderer function in electron-util

To help you get started, we’ve selected a few electron-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / electron-timber / index.js View on Github external
electron.ipcMain.on(errorChannel, (event, data) => {
			rendererLogger.error(...data);
		});
	}

	// Register a preload script so we know whenever a new renderer is created.
	(async () => {
		await app.whenReady();

		const session = electron.session.defaultSession;
		const currentPreloads = session.getPreloads();
		if (!currentPreloads.includes(preloadScript)) {
			session.setPreloads(currentPreloads.concat([preloadScript]));
		}
	})();
} else if (is.renderer) {
	if (electron.ipcRenderer.listenerCount(updateChannel) === 0) {
		electron.ipcRenderer.on(updateChannel, (event, flag) => {
			if (flag) {
				logger.hookConsole();
			} else {
				isConsoleHooked = false;
				for (const key of hookableMethods) {
					console[key] = _console[key];
					_console[key] = null;
				}
			}
		});
	}
}

module.exports = logger;
github sindresorhus / electron-timber / index.js View on Github external
warn(...args) {
		if (!this.isEnabled || this._options.logLevel > logLevels.warn) {
			return;
		}

		if (is.renderer) {
			electron.ipcRenderer.send(warnChannel, args);
		} else if (this.name) {
			args.unshift(this._getPrefix() + ' ' + chalk.yellow('›'));
		}

		if (this._options.ignore && this._options.ignore.test(args.join(' '))) {
			return;
		}

		this._console.warn(...args);
	}
github sindresorhus / electron-timber / index.js View on Github external
logger.hookConsole = ({main, renderer} = {main: is.main, renderer: is.renderer}) => {
	if (main && is.renderer) {
		throw new Error('You cannot hook the console in the main process from a renderer process.');
	}

	const hookThisConsole = (is.main && main) || (is.renderer && renderer);
	const shouldHookRenderers = is.main && renderer;

	if (hookThisConsole) {
		if (isConsoleHooked) {
			return unhookConsoleFn(hookThisConsole, shouldHookRenderers);
		}

		isConsoleHooked = true;

		for (const key of hookableMethods) {
			_console[key] = console[key];
github sindresorhus / electron-timber / index.js View on Github external
logger.hookConsole = ({main, renderer} = {main: is.main, renderer: is.renderer}) => {
	if (main && is.renderer) {
		throw new Error('You cannot hook the console in the main process from a renderer process.');
	}

	const hookThisConsole = (is.main && main) || (is.renderer && renderer);
	const shouldHookRenderers = is.main && renderer;

	if (hookThisConsole) {
		if (isConsoleHooked) {
			return unhookConsoleFn(hookThisConsole, shouldHookRenderers);
		}

		isConsoleHooked = true;

		for (const key of hookableMethods) {
			_console[key] = console[key];
			console[key] = logger[key];
		}
	}

	if (shouldHookRenderers) {