nate-parrott / Flashlight

The missing Spotlight plugin system
http://flashlight.nateparrott.com
Other
5.39k stars 411 forks source link

Run results method in background #59

Closed allenhsu closed 9 years ago

allenhsu commented 9 years ago

Currently, if there's any slow network requests in results method, it will block the spotlight's main thread, which cause it not responding.

Is it possible to run results method in background thread, and before it returns the result, show some placeholder from a placeholder method maybe.

nate-parrott commented 9 years ago

Hmm... I think the preferred way of dealing with this is to return HTML and then do your network requests in javascript. This has the added benefit of automatically cleaning up the previous query's requests when the query changes. See the weather plugin for an example of this.

allenhsu commented 9 years ago

@nate-parrott Yea, that's a good way, but during development, I found many of the APIs disallow cross domain xhr, which returns No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. while trying to fetch in JS. Any solution to this problem except setting up a proxy server?

nate-parrott commented 9 years ago

Hmm... looks like there's an undocumented switch you can flip on the Webview. We're already using loads of undocumented APIs at it is, so this might be doable — although it might introduce security issues.

nate-parrott commented 9 years ago

Running a local proxy server is another alternative, but that'd be a bit of work...

nate-parrott commented 9 years ago

Actually, I might be mistaken here. Do cross-origin restrictions apply to content loaded by the local app into a webview, or is this just a problem for you during development? (in the browser)

allenhsu commented 9 years ago

Thanks @nate-parrott , I succeeded running network requests in JS. As you said, there's no cross domain problem in Flashlight, it just failed when I debug in browser. You can close this issue.

BTW, I created a repo listing Chinese plugins for Flashlight (https://github.com/allenhsu/FlashlightPlugins). Do you have any plan to implement kinda subscription channel so that Chinese users can subscribe to a Chinese plugin list.

nate-parrott commented 9 years ago

I'm sure there's some setting in some browser that'll let you turn off cross-domain protection during debugging.

Re: Chinese plugins: That's awesome. At the very least, we could add some way to subscribe to third-party repositories, but there's gotta be a better way. Maybe I'll add some sort of channel system and then automatically enable the Chinese channel for users w/ Chinese as their system language. (Isn't github blocked in mainland China? Would it make sense to host this stuff on gitcafe or something?) On Mon, Nov 17, 2014 at 1:13 AM Allen Hsu notifications@github.com wrote:

Thanks @nate-parrott https://github.com/nate-parrott , I succeeded running network requests in JS. As you said, there's no cross domain problem in Flashlight, it just failed when I debug in browser. You can close this issue.

BTW, I created a repo listing Chinese plugins for Flashlight ( https://github.com/allenhsu/FlashlightPlugins). Do you have any plan to implement kinda subscription channel so that Chinese users can subscribe to a Chinese plugin list.

— Reply to this email directly or view it on GitHub https://github.com/nate-parrott/Flashlight/issues/59#issuecomment-63263915 .

allenhsu commented 9 years ago

@nate-parrott aha, github was blocked only for a few days long time ago. It works fine now.