mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
Fix crash on trying to print multiple times
This commit is contained in:
@ -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:));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user