Browse Source

chore: tsify net-log (#25670)

* chore: tsify net-log

* comment

* gn

Co-authored-by: Jeremy Rose <[email protected]>
trop[bot] 4 years ago
parent
commit
de0ddd5b56
3 changed files with 23 additions and 33 deletions
  1. 1 1
      filenames.auto.gni
  2. 0 32
      lib/browser/api/net-log.js
  3. 22 0
      lib/browser/api/net-log.ts

+ 1 - 1
filenames.auto.gni

@@ -204,7 +204,7 @@ auto_filenames = {
     "lib/browser/api/module-list.ts",
     "lib/browser/api/native-image.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.js",
     "lib/browser/api/power-monitor.ts",

+ 0 - 32
lib/browser/api/net-log.js

@@ -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 };
-  }
-}));

+ 22 - 0
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;
+  }
+};