diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm index fdbc3b9f1..0dcea47c2 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm @@ -1047,12 +1047,16 @@ NSLog(@"options: %@", nameLocales); CAscApplicationManager * appManager = [NSAscApplicationWorker getAppManager]; - - if (appManager) { - m_pContext = new ASCPrinterContext(appManager); -// m_pContext->BeginPaint([viewId intValue], [pagesCount intValue], self, @selector(printOperationDidRun:success:contextInfo:)); - m_pContext->BeginPaint(notification.userInfo, self, @selector(printOperationDidRun:success:contextInfo:)); - } + + // using synchronization to be sure that flag `ASCPrinterContext::isCurrentlyPrinting` is correctly handled + static dispatch_queue_t printQueue = dispatch_queue_create(NULL, NULL); + dispatch_sync(printQueue, ^{ + if (appManager && !ASCPrinterContext::isCurrentlyPrinting) { + m_pContext = new ASCPrinterContext(appManager); + // m_pContext->BeginPaint([viewId intValue], [pagesCount intValue], self, @selector(printOperationDidRun:success:contextInfo:)); + m_pContext->BeginPaint(notification.userInfo, self, @selector(printOperationDidRun:success:contextInfo:)); + } + }); } } diff --git a/macos/ONLYOFFICE/Code/Utils/ascprinter.h b/macos/ONLYOFFICE/Code/Utils/ascprinter.h index 6f53f0d90..8f37a37ca 100644 --- a/macos/ONLYOFFICE/Code/Utils/ascprinter.h +++ b/macos/ONLYOFFICE/Code/Utils/ascprinter.h @@ -279,6 +279,9 @@ class ASCPrinterContext : public NSEditorApi::CAscPrinterContextBase NSView* m_pView; CCefView* m_pParent; +public: + static bool isCurrentlyPrinting; + public: ASCPrinterContext(CAscApplicationManager* pManager) : NSEditorApi::CAscPrinterContextBase() { @@ -289,6 +292,8 @@ public: void BeginPaint(NSDictionary * info, id sender, SEL didRunSelector) { + isCurrentlyPrinting = true; + int viewId = [info[@"viewId"] intValue]; int pageCurrent = [info[@"currentPage"] intValue]; @@ -389,6 +394,7 @@ public: m_pParent->Apply(pEventEnd); m_pView = nil; + isCurrentlyPrinting = false; this->Release(); } @@ -459,4 +465,7 @@ public: } }; +// TODO: move outside of the header file +bool ASCPrinterContext::isCurrentlyPrinting = false; + #endif // NSASCPRINTER_H