Subscribing to Apple events in Qt - cocoa

Following the the code linked from here: Trap click event on dock icon using Qt on Mac, I tried to call the following method directly in my QApplication's constructor to receive notification of dock icon click events:
[[NSAppleEventManager sharedAppleEventManager]
setEventHandler: m_dockIconClickEventHandler
andSelector: #selector(handleDockClickEvent:withReplyEvent:)
forEventClass: kCoreEventClass
andEventID: kAEReopenApplication];
If I call it directly, I do not receive notifications of this event. However, if I call it using QTimer::singleShot with a delay of, say, 5000 ms, I receive the notifications just fine.
Also, according to the Qt documentation, "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed." So I tried 0 ms, but that didn't work. 1 or above seems to.
Why do I need to wait and what is a better way to handle this situation than delaying for n ms?

When your application exec() is called, Qt sets its own event handlers, so your handler is overriden.
You may use in your constructor
connect(this, SIGNAL(setupDockEventMonitor()), SLOT(onSetupDockEventMonitor()), Qt::QueuedConnection);
emit setupDockEventMonitor();
And in onSetupDockEventMonitor() do install this event handler.

Related

Outlook Add-In: AppointmentTimeChanged Event not getting triggered on changing the time of the event

I am trying to listen for any change in timing of the appointment through my Add-In. Here is the code where I am adding the handler.
Office.onReady(function() {
mailboxItem = Office.context.mailbox.item;
console.log("Added event handler");
mailboxItem.addHandlerAsync(Office.EventType.AppointmentTimeChanged, args =>
console.log("AppointmentTimeChanged")
),
args => {
console.log("Listening");
};
});
This however is not working for me.
AppointmentTimeChanged event listener works only till the lifecycle of the add-in. If you are using UI-less add-in functions you will not receive notifications beyond your call to event.completed().
To listen to changes beyond that you will have to listen to change using graph web hooks (https://learn.microsoft.com/en-us/graph/webhooks). This subscription from your backend service will enable you to be notified for event changes even from other clients.
But there is a catch to it, Outlook for MAC does not provide way to listen these changes till the event is sent out. To work around this problem you can use custom properties and listener to changes with these properties. Here is the doc explaining it: https://learn.microsoft.com/en-us/outlook/troubleshoot/calendars/cannot-save-meeting-as-draft-in-outlook-for-mac.

Application lifecycle test when togging system menus: screen goes black when onvisibilityChange:hidden

I am integrating youtube on cobalt 11. And now I'm testing the application lifecycle test.
I send the suspend event when I push the menu button (youtube goes to background)
I send the unpause event when I switch back to youtube. (youtube comes to foreground)
I send the deepLinke event after the unpause event
Sequence of events:
window.onfocus
window.onblur
....................?launch=remote
window.onfocus
..................:visible
onvisibilityChange:hidden
window.onblur
visible
When onvisibilityChange:hidden, youtube goes to the background; is that right?
This makes the screen turn black.
And why 1. window.onfocus and 2. window.onblur occur again after youtube has already resumed?
If you send the kSbEventTypeSuspend event, then Cobalt will assume that it is hidden and stop rendering to the display. If Cobalt is meant to remain visible, then do not send the kSbEventTypeSuspend event, instead you can send the kSbEventTypePause event. See the Cobalt lifecycle document for more information: https://cobalt.googlesource.com/cobalt/+/release_11/src/cobalt/doc/lifecycle.md .

uiless action in Outlook add-in with displayDialog()

We are seeing a change in Outlook with one of actions (“Help”) that stopped working on the web client only.
This action simply calls a js that opens a web page in a displayDialog() but it’s uiless in the sense that there’s no pane.
The other action (“Sign”) works ok but it launches a pane that does this.
Both of them work fine on the rich client (at least the version I use).
I wonder if there has been in recent changes in the requirements or the way this works?
We’re not seeing any error messages, just nothing happens after the prompt saying that the add-in is doing something.
We did some initial testing and noticed that in chrome the dialog will sometimes appear briefly. Could you confirm that you are calling event.completed() in the eventhandler of EventType.DialogEventReceived? event.completed() must be called in the DialogEventReceived handler otherwise the dialog will be closed prematurely.
Office.context.ui.displayDialogAsync(url, dialogOptions, function(result) {
// In the callback, save the dialog object
dialog = result.value;
// Add an event handler for messages sent via messageParent
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, receiveMessage);
// Add an event handler for events from the platform (like closing the dialog, etc.)
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogEventReceived, dialogClosed);
});

What can you do in CoreBluetooth background delegate calls?

I am using Core Bluetooth in my project. I have included Session Backgrounding to avail its background mode functionality. I have observed that the delegate for peripheral disconnection,
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error;
gets called in the background mode. However any code I write in this method is not executed except for NSLogs. Can somebody explain exactly what kind of code can be executed here?
My aim is to send this disconnection notification to my server.
Ok it seems it was some issue at my end. According the the documentation your app is woken (in the background) for around 10 seconds when it gets a bluetooth related delegate call.
You can use this time to perform any non view updating task and even request for additional time using beginBackgroundTaskWithExpirationHandler.
My code looks like this.
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
[self sendEmailInBackground:peripheral]; //Code to send a server request
return;
}
and its working in the background mode. This also works when the phone is in lock state.

Show a Dialog Box from non event thread

I need to show a Dialog box, from an app started via an alternate entry point, when a push message arrives.
To do this I need to create an Application instance from the alternate entry point and listen for incoming push.
The problem is when I extend my application class from UiApplication, and call enterEventDispatcher() from the alternate entry point it shows an application icon in running applications forever.
I need to listen for push messages and alert user by a dialog without having an application icon.
So is there any way I can show a dialog from an alternate entry point without a UI event thread?
You can use global dialog. Just use this code.
synchronized (Application.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "Look out!!!", Dialog.OK,
Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}

Resources