Browse Source

chore: tsify extensions shim (#24355)

Jeremy Rose 4 years ago
parent
commit
451086d7f2

+ 1 - 1
filenames.auto.gni

@@ -223,7 +223,7 @@ auto_filenames = {
     "lib/browser/api/views/image-view.ts",
     "lib/browser/api/web-contents-view.ts",
     "lib/browser/api/web-contents.js",
-    "lib/browser/chrome-extension-shim.js",
+    "lib/browser/chrome-extension-shim.ts",
     "lib/browser/default-menu.ts",
     "lib/browser/desktop-capturer.ts",
     "lib/browser/devtools.ts",

+ 4 - 6
lib/browser/chrome-extension-shim.js → lib/browser/chrome-extension-shim.ts

@@ -1,23 +1,21 @@
-'use strict';
-
 // This is a temporary shim to aid in transition from the old
 // BrowserWindow-based extensions stuff to the new native-backed extensions
 // API.
 
-const { app, session, BrowserWindow, deprecate } = require('electron');
+import { app, session, BrowserWindow, deprecate } from 'electron';
 
 app.whenReady().then(function () {
-  const addExtension = function (srcDirectory) {
+  const addExtension = function (srcDirectory: string) {
     return session.defaultSession.loadExtension(srcDirectory);
   };
 
-  const removeExtension = function (name) {
+  const removeExtension = function (name: string) {
     const extension = session.defaultSession.getAllExtensions().find(e => e.name === name);
     if (extension) { session.defaultSession.removeExtension(extension.id); }
   };
 
   const getExtensions = function () {
-    const extensions = {};
+    const extensions: Record<string, any> = {};
     session.defaultSession.getAllExtensions().forEach(e => {
       extensions[e.name] = e;
     });

+ 2 - 2
lib/common/api/deprecate.ts

@@ -55,12 +55,12 @@ const deprecate: ElectronInternal.DeprecationUtil = {
     };
   },
 
-  moveAPI: (fn: Function, oldUsage: string, newUsage: string) => {
+  moveAPI<T extends Function> (fn: T, oldUsage: string, newUsage: string): T {
     const warn = warnOnce(oldUsage, newUsage);
     return function (this: any) {
       warn();
       return fn.apply(this, arguments);
-    };
+    } as any;
   },
 
   // change the name of an event

+ 1 - 1
typings/internal-electron.d.ts

@@ -147,7 +147,7 @@ declare namespace ElectronInternal {
     event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
     removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K, onlyForValues?: any[]): T;
     renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
-    moveAPI(fn: Function, oldUsage: string, newUsage: string): Function;
+    moveAPI<T extends Function>(fn: T, oldUsage: string, newUsage: string): T;
   }
 
   interface DesktopCapturer {