chore: remove deprecated webContents.getPrinters()
(#39663)
This commit is contained in:
parent
d76a35afe4
commit
c96bb9958f
7 changed files with 19 additions and 51 deletions
|
@ -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
|
Returns `boolean` - Whether this page is being captured. It returns true when the capturer count
|
||||||
is large then 0.
|
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()`
|
#### `contents.getPrintersAsync()`
|
||||||
|
|
||||||
Get the system printer list.
|
Get the system printer list.
|
||||||
|
|
|
@ -91,6 +91,22 @@ systemPreferences.on('high-contrast-color-scheme-changed', () => { /* ... */ })
|
||||||
nativeTheme.on('updated', () => { /* ... */ })
|
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)
|
## Planned Breaking API Changes (26.0)
|
||||||
|
|
||||||
### Deprecated: `webContents.getPrinters`
|
### Deprecated: `webContents.getPrinters`
|
||||||
|
|
|
@ -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 () {
|
WebContents.prototype.getPrintersAsync = async function () {
|
||||||
// TODO(nornagon): this API has nothing to do with WebContents and should be
|
// TODO(nornagon): this API has nothing to do with WebContents and should be
|
||||||
// moved.
|
// moved.
|
||||||
|
|
|
@ -41,25 +41,6 @@ struct Converter<printing::PrinterBasicInfo> {
|
||||||
namespace electron::api {
|
namespace electron::api {
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
#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) {
|
v8::Local<v8::Promise> GetPrinterListAsync(v8::Isolate* isolate) {
|
||||||
gin_helper::Promise<printing::PrinterList> promise(isolate);
|
gin_helper::Promise<printing::PrinterList> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
@ -92,7 +73,6 @@ v8::Local<v8::Promise> GetPrinterListAsync(v8::Isolate* isolate) {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
using electron::api::GetPrinterList;
|
|
||||||
using electron::api::GetPrinterListAsync;
|
using electron::api::GetPrinterListAsync;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -103,7 +83,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
gin_helper::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
#if BUILDFLAG(ENABLE_PRINTING)
|
#if BUILDFLAG(ENABLE_PRINTING)
|
||||||
dict.SetMethod("getPrinterList", base::BindRepeating(&GetPrinterList));
|
|
||||||
dict.SetMethod("getPrinterListAsync",
|
dict.SetMethod("getPrinterListAsync",
|
||||||
base::BindRepeating(&GetPrinterListAsync));
|
base::BindRepeating(&GetPrinterListAsync));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1954,16 +1954,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()', () => {
|
ifdescribe(features.isPrintingEnabled())('getPrintersAsync()', () => {
|
||||||
afterEach(closeAllWindows);
|
afterEach(closeAllWindows);
|
||||||
it('can get printer list', async () => {
|
it('can get printer list', async () => {
|
||||||
|
|
|
@ -1275,6 +1275,9 @@ win4.webContents.on('devtools-open-url', (event, url) => {
|
||||||
|
|
||||||
win4.loadURL('http://github.com');
|
win4.loadURL('http://github.com');
|
||||||
|
|
||||||
|
// @ts-expect-error Removed API
|
||||||
|
win4.webContents.getPrinters();
|
||||||
|
|
||||||
// TouchBar
|
// TouchBar
|
||||||
// https://github.com/electron/electron/blob/main/docs/api/touch-bar.md
|
// https://github.com/electron/electron/blob/main/docs/api/touch-bar.md
|
||||||
|
|
||||||
|
|
1
typings/internal-electron.d.ts
vendored
1
typings/internal-electron.d.ts
vendored
|
@ -72,7 +72,6 @@ declare namespace Electron {
|
||||||
_sendInternal(channel: string, ...args: any[]): void;
|
_sendInternal(channel: string, ...args: any[]): void;
|
||||||
_printToPDF(options: any): Promise<Buffer>;
|
_printToPDF(options: any): Promise<Buffer>;
|
||||||
_print(options: any, callback?: (success: boolean, failureReason: string) => void): void;
|
_print(options: any, callback?: (success: boolean, failureReason: string) => void): void;
|
||||||
_getPrinters(): Electron.PrinterInfo[];
|
|
||||||
_getPrintersAsync(): Promise<Electron.PrinterInfo[]>;
|
_getPrintersAsync(): Promise<Electron.PrinterInfo[]>;
|
||||||
_init(): void;
|
_init(): void;
|
||||||
canGoToIndex(index: number): boolean;
|
canGoToIndex(index: number): boolean;
|
||||||
|
|
Loading…
Reference in a new issue