Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deprecated webContents.getPrinters() #39663

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions docs/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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`
Expand Down
11 changes: 0 additions & 11 deletions lib/browser/api/web-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,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.
Expand Down
21 changes: 0 additions & 21 deletions shell/browser/api/electron_api_printing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions spec/api-web-contents-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1946,16 +1946,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 () => {
Expand Down
3 changes: 3 additions & 0 deletions spec/ts-smoke/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion typings/internal-electron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down