diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 6889eb6f1873..521a692f0ae4 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1596,8 +1596,11 @@ void NativeWindowMac::PreviewFile(const std::string& path, } void NativeWindowMac::CloseFilePreview() { - if ([QLPreviewPanel sharedPreviewPanelExists]) { + // Need to be careful about checking [QLPreviewPanel sharedPreviewPanel] as + // simply accessing it will cause it to reinitialize and reappear. + if ([QLPreviewPanel sharedPreviewPanelExists] && preview_item_) { [[QLPreviewPanel sharedPreviewPanel] close]; + preview_item_ = nil; } } diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 94f627ee2389..5258abd4b785 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -6256,6 +6256,7 @@ describe('BrowserWindow module', () => { w.previewFile(__filename); await setTimeout(500); expect(showCalled).to.equal(false, 'should not have called show twice'); + w.closeFilePreview(); }); });