fix: 修复桌面 DOCX 媒体捕获超时
This commit is contained in:
@@ -18,6 +18,25 @@ export interface ElectronDocxMediaEngineOptions {
|
||||
renderUrl: string;
|
||||
}
|
||||
|
||||
export async function withActiveDocxCaptureSurface<T>(
|
||||
window: Pick<
|
||||
BrowserWindow,
|
||||
"showInactive" | "hide" | "isDestroyed"
|
||||
>,
|
||||
operation: () => Promise<T>,
|
||||
settleMs = 50
|
||||
) {
|
||||
window.showInactive();
|
||||
await new Promise((resolve) => setTimeout(resolve, settleMs));
|
||||
try {
|
||||
return await operation();
|
||||
} finally {
|
||||
if (!window.isDestroyed()) {
|
||||
window.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ElectronDocxMediaEngine
|
||||
implements DocxMediaCaptureAdapter, DocxThemeStyleCaptureAdapter
|
||||
{
|
||||
@@ -98,10 +117,14 @@ export class ElectronDocxMediaEngine
|
||||
};
|
||||
signal?.addEventListener("abort", abort, { once: true });
|
||||
try {
|
||||
return await captureDocxMediaWithElectronWebContents(
|
||||
window.webContents,
|
||||
request,
|
||||
signal
|
||||
return await withActiveDocxCaptureSurface(
|
||||
window,
|
||||
() =>
|
||||
captureDocxMediaWithElectronWebContents(
|
||||
window.webContents,
|
||||
request,
|
||||
signal
|
||||
)
|
||||
);
|
||||
} finally {
|
||||
signal?.removeEventListener("abort", abort);
|
||||
|
||||
Reference in New Issue
Block a user