Firefox addon. Communicating using child_process with native app - firefox-addon

Following this Link, I created an add-on that launches a native child process. The child process can send data to the extension using StdOut of the process, no issues there. However when I try to send data from Extension (add-on script ) to the native app using the emit(target,'data', 'the data') ; emit(target,'end'); as mentioned in the MDN documentation, it seems like the app recieves the message only once. If I try to again do emit(target,'data',..) ; emit(target,'end') , again .. it is not sent to the native app. I debugged it and looks like after we emit('end') , it removes some listeners and next time when emit() is called there is no registered listeners and it does not actually dispatch the event. Would really appreciate if some one could point me to what I am missing.

Emitting end likely closes the output stream or something to that effect, so simply don't emit end until you're actually done sending data for good.

Related

Outlook REST API Flagging Message losing start date

I'm building an Outlook Add-In and using the Outlook REST API 2.0. When updating a mail message to flag the message for follow-up, the update is accepted and in the Outlook Web client it briefly shows the start and due dates, but within a few seconds the start date goes away. When looking at the message through the API, the start date is completely removed, even though it was successfully added.
The API is PATCH Office.context.mailbox.restUrl + '/v2.0/me/messages/' + messageId ...
EDIT: I confirmed that this same behavior is exhibited in the Graph API as well.
As soon as the API is called, the UI on the message is updated:
Shortly after that (sometimes within a second, sometimes a little longer), the UI changes to:
And once the UI updates, if you query the API for the message and look at the Flag property, the StartDateTime object is completely gone.
Has anyone seen this or know why it might be happening?
Checked it on Graph with the following payload for PATCH-Message call and it seems to be working fine.
{"flag":{"dueDateTime":{"dateTime":"2020-08-20T00:00:00.0000000","timeZone":"Asia/Kolkata"},"flagStatus":"flagged","startDateTime":{"dateTime":"2020-08-14T00:00:00.0000000","timeZone":"Asia/Kolkata"}}}
I suspect that there is another application/outlook add-in that's removing this flag. Can you check once?

Is the ononline event supported in a service worker?

document.ononline is an event available in the browser. Is there an equivalent event supported by service worker code, which does not have DOM access?
All the sample code I have seen checks network status in the course of handling a request. It would be desirable to respond to network availability immediately for the purposes of committing local updates to the server or cloud.
The best I could find in terms of documentation was https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope and it lists only these events:
onactivate
onfetch
oninstall
onmessage
onnotificationclick
onnotificationclose
onpush
onpushsubscriptionchange
onsync
Of these, sync seems most like what I seek, but it depends on use of a SyncManager, and the documentation for that is fraught with warnings against use in production code.
I'm not sure whether there's an event available in the SW for that. Someone should confirm this.
You could work around this problem by having the ononline event handler logic in your page's JS which could inform the SW of the connectivity changes. This would also be an appropriate place to handle any notifications in the UI for the user.
Spesifically:
SW registers an onmessage handler
Client/page JS registers a handler for the ononline event
When connection changes, the handler notifies the SW via postMessage API
SW receives the connection change msg from the client and acts accordingly
The postMessage API is very useful and can be used to pass basically any data between the page and the SW. Note that there isn't any spesific message for my proposal, just pass something like { "new_status": "online" } etc.
This is an old question but one I'm currently interested in. What I've found is that while MDN currently says it's supported in the (shared) WorkerGlobalScope, I'm sitting on a breakpoint right now in my service worker using Chrome DevTools and the ServiceWorkerGlobalScope does not have an "ononline" property. The "navigator.onLine" indicator appears to work however. You can at least check that and return cached responses immediately.
I added event listeners for online and offline events and neither triggered, so it appears to be unsupported. I can think of plausible reasons for not supporting it, but it would be interesting to hear the real ones.

Is it possible to update only part of an app in the App Store?

My app relies on an external service that might change its output any time without warning, so I would need a completly new function to parse it. Is there anyway to update my service parser without having to re-submit the whole app for review? Otherwise part of my app would be broken during the time to develop and review the new parser. I was told I cannot use bundles for this, so I really am clueless how to solve this problem.
You can't solve that problem completely on the client side.
Depending on the output format of the external service, and the methods you use to parse its output, you might have the option to store a file in a server that contains information about the current output format of the external service. Then your app can use the meta-data in that file to determine how to do the parsing.
You can also develop a simple web service that wraps the external service. Then your app can use the web service instead of the original service, and whenever the output of the original service is changed, you can quickly update your web service to make your app continue functioning properly.

Is it required that I use forge.request.ajax in stead of $.post?

First , I am not trying to do a cross site request.
I have created a small JS app and I can test in in a browser and it works fine i.
I see that my request from the app makes it to my server and I can confirm that my server responds with the data I expect. The problem is that the compiled app triggers the .fail in my javascript.
Is is REQUIRED that I use forge.request.ajax. instead of $.post? I see many posts saying I should but no one says I cannot use $.post .It makes debugging and development much easier being able to test all my JS in a browser before making the package.
Unfortunately I haven't found a way around it. You can use a promise, create a wrapper function/service, detect the platform that you are running on and call the corresponding function.

Pusher in background job is outpacing my app - missing JS notifications

I'm moving imports of excel files (often large, often small) into the background using Sidekiq, and alerting the user when the importing is complete using Pusher.
At first, in the 'synchronous' flow (Rails app here), it will kick off the excel import, and then it will redirect to a dashboard page which will receive notifications from Pusher when the importing is done.
The problem is the Sidekiq-Pusher flow sometimes goes faster than the redirect to the dashboard page. My JavaScript subscriber won't be initialized in time to receive the message that is being published from within the background process. So the client gets nothing.
Does Pusher offer a way to delay publishing a message until there is a subscriber? Or does Pusher offer a way to 'stockpile' messages until the subscriber springs to life to consume them? Or maybe there is a simpler solution here I have not thought of?
Fyi, I don't want the background job to sleep for a few seconds to make sure the client is ready, and I don't want to use Pusher to trigger a refresh (i.e. save something in a DB, then refresh to display it).
I am happy to provide code samples if desired.
EDIT:
I'm certainly open to using something else besides Pusher if something else can solve my problem.
Invoke the worker after 1 or 2 seconds from the current time so that it gets invoked and show the message after being redirected to the landing page.
TestProcess.perform_at(2.seconds.from_now,parameters)
It will work as expected. Hope it helps :)

Resources