From d9d07c65b2440f61e0b979fde90ac896334b1c3f Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 29 Jun 2020 09:21:32 -0700 Subject: [PATCH] chore: tsify net-log (#24322) * chore: tsify net-log * comment * gn --- filenames.auto.gni | 2 +- lib/browser/api/net-log.js | 32 -------------------------------- lib/browser/api/net-log.ts | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 lib/browser/api/net-log.js create mode 100644 lib/browser/api/net-log.ts diff --git a/filenames.auto.gni b/filenames.auto.gni index 3bbcec5e8bbc..1469d666c06f 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -208,7 +208,7 @@ auto_filenames = { "lib/browser/api/message-channel.ts", "lib/browser/api/module-list.ts", "lib/browser/api/native-theme.ts", - "lib/browser/api/net-log.js", + "lib/browser/api/net-log.ts", "lib/browser/api/net.ts", "lib/browser/api/notification.ts", "lib/browser/api/power-monitor.ts", diff --git a/lib/browser/api/net-log.js b/lib/browser/api/net-log.js deleted file mode 100644 index 11b8071880ab..000000000000 --- a/lib/browser/api/net-log.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -// TODO(deepak1556): Deprecate and remove standalone netLog module, -// it is now a property of session module. -const { app, session } = require('electron'); - -// Fallback to default session. -Object.setPrototypeOf(module.exports, new Proxy({}, { - get (target, property) { - if (!app.isReady()) return; - - const netLog = session.defaultSession.netLog; - - if (!Object.prototype.hasOwnProperty.call(Object.getPrototypeOf(netLog), property)) return; - - // check for properties on the prototype chain that aren't functions - if (typeof netLog[property] !== 'function') return netLog[property]; - - // Returning a native function directly would throw error. - return (...args) => netLog[property](...args); - }, - - ownKeys () { - if (!app.isReady()) return []; - - return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession.netLog)); - }, - - getOwnPropertyDescriptor (target) { - return { configurable: true, enumerable: true }; - } -})); diff --git a/lib/browser/api/net-log.ts b/lib/browser/api/net-log.ts new file mode 100644 index 000000000000..81a9e5152435 --- /dev/null +++ b/lib/browser/api/net-log.ts @@ -0,0 +1,22 @@ +// TODO(deepak1556): Deprecate and remove standalone netLog module, +// it is now a property of session module. +import { app, session } from 'electron'; + +const startLogging: typeof session.defaultSession.netLog.startLogging = async (path, options) => { + if (!app.isReady()) return; + return session.defaultSession.netLog.startLogging(path, options); +}; + +const stopLogging: typeof session.defaultSession.netLog.stopLogging = async () => { + if (!app.isReady()) return; + return session.defaultSession.netLog.stopLogging(); +}; + +export default { + startLogging, + stopLogging, + get currentlyLogging (): boolean { + if (!app.isReady()) return false; + return session.defaultSession.netLog.currentlyLogging; + } +};