Quantcast
Viewing latest article 6
Browse Latest Browse All 20

Titanium Desktop - Understanding Titanium.Worker

Sorry for the noob question! :)

Okay, here’s the deal: I’m writing an app that has a function that downloads a gob of files from a server using Titanium.Network.HTTPClient, and saves them to disk. And that’s working just fine.

However, when my function runs (I’m calling it from a tray menu item), the process takes over and locks up the UI until it finishes (which can take a while). I’d like it to run in the background. Therefore, Titanium.Worker must be what I’m looking for.

So, being new to Titanium (and javascript workers), here’s what I attempted:

/**
 * Instantiate a worker process to download new files
 * in the background.
 */
function downloadAllFilesWorker()
{
  // Shows a status message and spinner in my UI...
  modal(true);
 
  $worker = Titanium.Worker.createWorker(downloadAllFiles());
  $worker.start();
 
  // Removes message - need to put this somewhere :)
  // modal(false);
}
When I call this function from my menu item (rather than calling downloadAllFiles() directly), two things happen:

1) The UI locks up anyway (I get to watch the beach ball for a while).

2) My app craps out with this message:

[17:34:43:854] [Titanium.Worker] [Debug] worker file path =
'/Volumes/Development/Projects/Download App/dist/osx/
Download App.app/Contents/Resources/undefined' 'undefined'
 
[17:34:43:855] [Titanium.KEventObject] [Error] Exception caught
during event callback (target=[(UI.MenuItem) { ALL : "all",
APP_EXIT : "app.exit", CLOSE : "close", CLOSED : "closed",
  <<snip snip snip>>
isSeparator : , removeEventListener : , setIcon : , setLabel : ,
setSubmenu : }]): "File not found"
So, I’m stumped. It looks like, perhaps, Titanium.Worker.createWorker() is wanting me to reference a separate .js file, rather than calling a function within my current script, but that doesn’t make sense in terms of the API docs anyway...

Any ideas? Once I get this one issue resolved, my app is ready for RELEASE!!! :)

BTW, Titanium Desktop is awesome.


Viewing latest article 6
Browse Latest Browse All 20

Trending Articles