Calling showOpenFilePicker : how avoid "must come from gesture" when calling class methods - google-chrome

Accessing the local filesystem a la: https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
If I inline all my code for the show(Open|Save)FilePicker API logic directly in my button event closure or call plain fn's then things work ok. However, if I define a class w/helper methods and call those from my event-handler, and those helpers call the file pickers, then I get this error:
Uncaught DOMException: Failed to execute 'showOpenFilePicker' on 'Window': Must be handling a user gesture to show a file picker.
I assume the the security system is looking at this to establish the gesture context - is there a way to re-establish this context with code running in my class?

Turns out the class methods were a red herring -- the issue has to do with async code and promises -- this is what looses the context and causes the error.
You need to make any calls to the FS without any promise chaining.

Related

Achieve Do after and before using ES6 Proxy

I've a View and Utility classes and wanted to hook-in the Utility method once View's job is done. So wanted to call the utility method (to add behavior to the view) once View's render call is done.
Using ES6 Proxy API, Is there a way to execute a method before / after executing the main method ? (aka method interceptions)
Similar to YUI3 Do API.
http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.

POX component listen to events

I want to discover the topology of a network emulated by mininet using POX components. I figured out that I need to write my own component, which is listening to LinkEvents. Something like:
someObject.addListenerByName("LinkEvent", someFunction)
But I don't actually know on what kind of an object i should execute this.
If I execute it as
core.openflow_discovery.addListenerByName("LinkEvent", someFunction)
as stated in the openflow.discovery module, it throws the following error:
AttributeError: 'openflow_discovery' not registered
It is easier to use pox modules named "gephi" to do this, it should be under misc directory, just add this method to the "gephi_topo.py" in "class GephiTopo":
def get_gephi_topology (self):
switchesAndLinksAndHosts=[self.switches,self.links, self.hosts]
return switchesAndLinksAndHosts
and then use it anywhere in your pox controller like:
topo=gephi_topo.GephiTopo.get_gephi_topology(core.GephiTopo)
switches= topo[0]
links=topo[1]
hosts=topo[2]
Fixed it by calling addListenerByName from within launch().

Handle specific exception that is not related to an exchange

I created a custom component for a proprietary service. If this service is down i get noticed via a call of a callback function. I am throwing a custom exception at this point.
Sending exchanges to the producer/ consumer will yield no errors or exceptions (all seems to fine).
So i need to implement an emergency stop if my custom exception is thrown. I read a bit about exception handling in camel. I think i need a context-scoped onException(MyException.class).??? but what then?
Is this working on exceptions that are called without relation to an exchange? If this is working how to handle it. I want to stop certain routes in this case.
here you can find to stop routes from a route: http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html.
If you do the call of the proprietary service in a route you do have an exchange btw.
kind regards,
soilworker
I created a little workaround: I set a boolean i the callback method is called. On each call of process i check this boolean and if true i throw an exception.
With this the exception is within normal camel exception handling and onException could be used.

System.TypeInitializationException between two program in F#

I'm working on a project and I become always an Exception "TypeInitializationException".
I tried to give a string to a global string variable but it failed.
That's the code for the viewmodel and it failed on the second line
| {State = _}, ConsumablesClicked vm ->
Testtyp <- vm.TrackPosition.ToString()
That's on the other program
let mutable Testtyp = ""
I become this InnerException "Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.".
"The type initializer for '.$BarcodeGenerieren' threw an exception.", that's the exception explication.
Has someone a Idea how solve this?
That exception indicates that some code is trying to call Console.ReadKey when the standard input for that process has been redirected (see e.g. Allowing redirection of StandardInput of a C# application when doing "Console.ReadKey"). The solution is not to call Console.ReadKey, but it's not clear from your description where this is actually happening (perhaps in the static constructor for one of your types?).
I found the solution after a lot of try and it was only, that I had a Console.Readkey in my code, that I forgot to delete.
I had before a console apllication and I transformed it to be a class.

Handling Security Errors in AS3

I am using an imported class for a vimeo player in AS3, it is the official vimeo player api (vimeo.com). I want to handle any Security Errors that an instance of the class throws (they get thrown when the obect fails to load an external URL for a video). This is what I have got:
var clipPlayer = new VimeoPlayer("5d22d3942a54d7c75b931bab4a911857", videoID[clickedClip], fullVideoWidth, fullVideoHeight, "10", 2);
clipPlayer.addEventListener(SecurityErrorEvent.SECURITY_ERROR , vimeoError);
Later in the code ofcourse, I've got the function that handles the event:
function vimeoError (e : SecurityErrorEvent) : void {
trace("vimeo player failed to load");
}
This all seems straight forward, but yet the Error Handler is not firing. I must be missing something here... Maybe you can't register this kind of event listener on a VimeoPlayer object. However, I am pretty certain it is the VimeoPlayer object throwing them. Here is an example of what I am getting:
Error opening URL
'http://api.vimeo.com/moogaloop_api.swf?oauth_key=5d22d3942a54d7c75b931bab4a911857&clip_id=21185860&width=500&height=281&fullscreen=0&fp_version=10&api=1&cache_buster=565.7249609939754'
SecurityError: Error #2000: No active security context.
Dispatched error events are separate from thrown Errors. In many cases both kinds can occur, and then you need to listen for the former and catch the latter with a try statement around the code that may throw. The error you quote seems to be of the thrown variety (as events typically stringize to something involving square brackets).