Browse Source

chore: remove deprecated `webContents.getPrinters()` (#39735)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <[email protected]>
trop[bot] 1 year ago
parent
commit
0fe0a90341

+ 0 - 8
docs/api/web-contents.md

@@ -1536,14 +1536,6 @@ If you would like the page to stay hidden, you should ensure that `stayHidden` i
 Returns `boolean` - Whether this page is being captured. It returns true when the capturer count
 is large then 0.
 
-#### `contents.getPrinters()` _Deprecated_
-
-Get the system printer list.
-
-Returns [`PrinterInfo[]`](structures/printer-info.md)
-
-**Deprecated:** Should use the new [`contents.getPrintersAsync`](web-contents.md#contentsgetprintersasync) API.
-
 #### `contents.getPrintersAsync()`
 
 Get the system printer list.

+ 16 - 0
docs/breaking-changes.md

@@ -45,6 +45,22 @@ systemPreferences.on('high-contrast-color-scheme-changed', () => { /* ... */ })
 nativeTheme.on('updated', () => { /* ... */ })
 ```
 
+### Removed: `webContents.getPrinters`
+
+The `webContents.getPrinters` method has been removed. Use
+`webContents.getPrintersAsync` instead.
+
+```js
+const w = new BrowserWindow({ show: false })
+
+// Removed
+console.log(w.webContents.getPrinters())
+// Replace with
+w.webContents.getPrintersAsync().then((printers) => {
+  console.log(printers)
+})
+```
+
 ## Planned Breaking API Changes (26.0)
 
 ### Deprecated: `webContents.getPrinters`

+ 0 - 11
lib/browser/api/web-contents.ts

@@ -386,17 +386,6 @@ WebContents.prototype.print = function (options: ElectronInternal.WebContentsPri
   }
 };
 
-WebContents.prototype.getPrinters = function () {
-  // TODO(nornagon): this API has nothing to do with WebContents and should be
-  // moved.
-  if (printing.getPrinterList) {
-    return printing.getPrinterList();
-  } else {
-    console.error('Error: Printing feature is disabled.');
-    return [];
-  }
-};
-
 WebContents.prototype.getPrintersAsync = async function () {
   // TODO(nornagon): this API has nothing to do with WebContents and should be
   // moved.

+ 0 - 21
shell/browser/api/electron_api_printing.cc

@@ -41,25 +41,6 @@ struct Converter<printing::PrinterBasicInfo> {
 namespace electron::api {
 
 #if BUILDFLAG(ENABLE_PRINTING)
-printing::PrinterList GetPrinterList(v8::Isolate* isolate) {
-  EmitWarning(node::Environment::GetCurrent(isolate),
-              "Deprecation Warning: getPrinters() is deprecated. "
-              "Use the asynchronous and non-blocking version, "
-              "getPrintersAsync(), instead.",
-              "electron");
-  printing::PrinterList printers;
-  auto print_backend = printing::PrintBackend::CreateInstance(
-      g_browser_process->GetApplicationLocale());
-  {
-    ScopedAllowBlockingForElectron allow_blocking;
-    printing::mojom::ResultCode code =
-        print_backend->EnumeratePrinters(printers);
-    if (code != printing::mojom::ResultCode::kSuccess)
-      LOG(INFO) << "Failed to enumerate printers";
-  }
-  return printers;
-}
-
 v8::Local<v8::Promise> GetPrinterListAsync(v8::Isolate* isolate) {
   gin_helper::Promise<printing::PrinterList> promise(isolate);
   v8::Local<v8::Promise> handle = promise.GetHandle();
@@ -92,7 +73,6 @@ v8::Local<v8::Promise> GetPrinterListAsync(v8::Isolate* isolate) {
 namespace {
 
 #if BUILDFLAG(ENABLE_PRINTING)
-using electron::api::GetPrinterList;
 using electron::api::GetPrinterListAsync;
 #endif
 
@@ -103,7 +83,6 @@ void Initialize(v8::Local<v8::Object> exports,
   v8::Isolate* isolate = context->GetIsolate();
   gin_helper::Dictionary dict(isolate, exports);
 #if BUILDFLAG(ENABLE_PRINTING)
-  dict.SetMethod("getPrinterList", base::BindRepeating(&GetPrinterList));
   dict.SetMethod("getPrinterListAsync",
                  base::BindRepeating(&GetPrinterListAsync));
 #endif

+ 0 - 10
spec/api-web-contents-spec.ts

@@ -1915,16 +1915,6 @@ describe('webContents module', () => {
     });
   });
 
-  ifdescribe(features.isPrintingEnabled())('getPrinters()', () => {
-    afterEach(closeAllWindows);
-    it('can get printer list', async () => {
-      const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
-      await w.loadURL('about:blank');
-      const printers = w.webContents.getPrinters();
-      expect(printers).to.be.an('array');
-    });
-  });
-
   ifdescribe(features.isPrintingEnabled())('getPrintersAsync()', () => {
     afterEach(closeAllWindows);
     it('can get printer list', async () => {

+ 3 - 0
spec/ts-smoke/electron/main.ts

@@ -1275,6 +1275,9 @@ win4.webContents.on('devtools-open-url', (event, url) => {
 
 win4.loadURL('http://github.com');
 
+// @ts-expect-error Removed API
+win4.webContents.getPrinters();
+
 // TouchBar
 // https://github.com/electron/electron/blob/main/docs/api/touch-bar.md
 

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

@@ -70,7 +70,6 @@ declare namespace Electron {
     _sendInternal(channel: string, ...args: any[]): void;
     _printToPDF(options: any): Promise<Buffer>;
     _print(options: any, callback?: (success: boolean, failureReason: string) => void): void;
-    _getPrinters(): Electron.PrinterInfo[];
     _getPrintersAsync(): Promise<Electron.PrinterInfo[]>;
     _init(): void;
     canGoToIndex(index: number): boolean;