Close Extension window automatically after sending transaction - elrond

When you use the Maiar Exchange with the Chrome Extension and send a transaction, you can see that the extension window automatically closes after sending the transaction.
When I implement the same behavior, the Extension window stays open and the sendTransaction() Promise only resolves after the call is done. If I close the window by myself by clicking somewhere else on the website, I get the following error in the console:
Uncaught (in promise) Extension window was closed without response.
With that error, my promise success resolving code is not executed anymore which basically forces the user to wait about 30 seconds until the transaction is done.
This happens when using the sendTransaction() method of the ExtensionProvider from erdjs.
Does anyone have an explanation how e.g. the Maiar Exchange solves this?

The way the Maiar Exchange handles this is slightly different from your approach.
Sending the transaction directly with the ExtensionProvider requires that the extension window stays open until it is finished to return you the result.
However if you only use the ExtensionProvider to sign the transaction using the signTransaction method and send it yourself via the ProxyProvider you won't run into this limitation. The signing is basically instant and quickly closes the extension window. It also allows you to retry sending, without user interaction, if you run into any timeouts or similar.

Related

in tnis auth sample of google-oauth, how can I get callback of closing browser?

Using this sample api named 'Auth.java',
https://github.com/youtube/api-samples/tree/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline
last of those line :
'return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");'
when that .authorize("user") start to work, it opens google account select page on default brower .
if I choose my google account and following flows, it works very well.
but problem occured after opening browser. if I don't choose google account or just close this page, code stopped and stay that line. so close browser and if I take course of Oauth again, error
occurs : binding port already used(8080).
what I want is how can I take callback from server or anywhere like browser has closed so rollback this process or if authorizing process doesn't work for miinute, process roll back.

Determine the origin of a WM_CLOSE message

I have an app that prompts the user for confirmation on exit, which is (indirectly) done by opening a confirmation dialog when the WM_CLOSE message is received. However the message is also sent by the task manager when the user uses end task on the process.
Because I prevent the window from closing with the confirmation dialog, task manager sees it as the process hanging and forcefully terminates it preventing the app from doing a graceful exit when it's possible.
Is there any way to determine if it's the user closing the window from the message (e.g. clicking the close button, or Alt+F4), and not the task manager? As the message's parameters are unused the only way I could think of is checking for mouse events or WM_SYSCOMMAND that were received some time before the WM_CLOSE is received, but I'm unsure if this would handle all cases.
I assume the task manager calls EndTask. Perhaps in the old days it only sent WM_CLOSE but it seems to send WM_SYSCOMMAND when I tested now so there are no clues in the messages you can use, it just looks like a normal Alt+F4.
If your app is asking about unsaved changes in a document, I would say, put up the dialog regardless and just accept the hard termination if that is what the user wants.
If you are just trying to prevent an accidental close, call GetForegroundWindow in WM_CLOSE. If you are not foreground, it was not an accidental close.

WM_COPYDATA, PostThreadMessage, and Error 1159

I am trying to send data from one app to another using WM_COPYDATA. Both apps are console and have no window. I can send user messages just fine. When I try to send WM_COPYDATA, and setup the data structure or not, I get error 1159, which basically says I have to send using a synchronous message call... yet there is no SendThreadMessage.
It seems this is a oversight in the api or docs? There seems to be no way to use WM_COPYDATA using only threads without windows?
WM_COPYDATA can only be sent and cannot be posted. Because the payload is marshaled between processes, temporary data structures are created to support that marshaling. They need to be destroyed when the message processing is complete. That implies that the message must be delivered synchronously.
All of this means that you cannot use PostThreadMessage. Instead you will need to create a window to act as the recipient of such messages. Note that this window can be a message-only window and does not need to be visible.

Chromecast sender that knows when session started from Cast Extension

The SDK docs for building a Chromecast Sender on Chrome mention this:
There is also a third way of getting a Cast session. A user with the
Cast extension installed in their Chrome browser can mirror any Chrome
tab to a Cast device. If the user lands on your site, for which you
have implemented a Cast app, tab mirroring will automatically trigger
a new Cast session instead of putting the browser in mirroring mode.
And this works just fine; however, I'd like to better understand how my sender code can know when a session has been started this way. Normally, when we set up our own trigger to start a session (i.e. the cast icon), we pass as an argument the callback that will execute when the session connection is ready, If someone visits my app and launches the Cast session directly from the extension, then, how can my app be notified? Is there an event that's raised? Does it execute its own callback (and if so, how can we hook into that callback)?
A similar question was asked here at SO a while ago, and Leon Nicholls answered indicating that it was possible, but not how to do it. Any insights woyld be very useful.

Force Close forge.request.ajax

I am writing an app that allows file upload to our server. I would like to give users the option to stop the file upload once it has started.
Since the file is being sent via forge.request.ajax, the process runs in the background even if the user leaves the upload screen.
Is there a native way of closing an active forge.request.ajax connection??
My Application allows users to send a file to our server via forge.request - I need to be able to cancel the request - do you have any suggestions as to how to go about this??
Currently, no: although "cancel" messages could be passed through the JS / Native communication bridge, we haven't got logic in the native code to abort partially-sent requests.
I don't think there's anything in java.net.* that would support that sort of interaction either...

Resources