Questions about jquery and release dates of some features in AppJS

85 views
Skip to first unread message

Андрей Чернявский

unread,
Oct 20, 2012, 7:02:19 AM10/20/12
to appj...@googlegroups.com
Hi to all from Kazakhstan! :)

First of all, i want to say, that i am noob. Second - please answer on a list of my questions:
  • How to connect jquery with app.js? if you can, please write example of connecting...
  • What about date of release of tray in Windows XP/Vista/Seven/Eight?
  • What about feature of hiding application window in tray?
  • Is there already exist some loop in app.js? For example i need to process some code each hour or minute...
  • Is it hard to realize: run javascript in another thread (process). For example running javascript file, where gonna be while(1){ /*some processing*/ }.
  • Is there any options to control maximum of (process loading). For example set up app.js process loading maximum to 20%...
Sorry if you do not understand some of my questions... and thank you for AppJS ^__^

sihorton

unread,
Oct 20, 2012, 7:29:09 AM10/20/12
to appj...@googlegroups.com
Welcome to all from Kazakhstan!

To use jquery in appjs you can add a script tag in index.html in the normal way:-

<html>
<head>
<script src="js/jquery.js"/>
..
In app.js file you can then use the loaded jquery library in the ready event:

window.on('ready', function() {
    var $ = window.$;
  //now you can use jquery as you would normally..
  //click a button with an id of test
  $('#test').click();
});

Of course you can also write jquery code in index.html exactly as you would in a normal web page application.

We don't have a firm date on the desktop integration features. If you have particular windows features you want to access then there is a node module called node-ffi (https://github.com/rbranson/node-ffi) this allows you to call windows api functions from nodejs (i.e. from the app.js file). As a temporary solution you could bundle a windows executable along with appjs, communicate with it via the command line or similar mechanism and get it to add tray icons and menus etc.

You can use the javascript function setTimeout to schedule events:
setTimeout(function() {
   //this function is called every 5000 milliseconds
},5000);
The function reference is given here: http://nodejs.org/api/timers.html

Nodejs which is run in the app.js file has been designed to be event driven, none blocking in nature. This means it is optimised for responding to events with callback functions. The entire stack in nodejs is implemented in this way. This means that support for multiple threads is more limited than something like java or c. Ideally if possible you might be able to re-design as an event oriented rather than thread based program. There is a node module: https://github.com/xk/node-threads-a-gogo which goes give you a nice interface to run threads. I do not know if this works on windows, it does work on linux. It is also possible to setup a cluster http://nodejs.org/api/cluster.html this works cross platform although it might not be exactly what you are looking for.

There is no option to limit CPU activity so you would have to implement that yourself within the application you write.

/Simon


Андрей Чернявский

unread,
Oct 20, 2012, 9:10:10 AM10/20/12
to appj...@googlegroups.com
Oh, didn't expect such a quick response! )
Thank you Simon! )

One last question:
What i must do, if i want to connect jquery right in app.js?

You see, AppJS has one wonderfull feature: if i redirect user from index.html to google.com for example, functions, that stored in AppJS is still works! Due this feature, i can minimize app and do my other work, while app sending ajax request to server-side.

i'm feel like i am idiot...
I think appjs is already has some functions that realising ajax methods... can you tell me where i can read documentation about it? Or it available after i connect jquery? O_o

sihorton

unread,
Oct 20, 2012, 9:24:09 AM10/20/12
to appj...@googlegroups.com
yes ok I understand. It is possible to have your functions in app.js and then you can "inject" them into the browser page:

window.on('ready', function(){
  var document = window.document;
  var script = document.createElement('script');
  script.onload = function(){
    var $ = window.$;
    /**
      Every page the user visits will have jQuery injected into it via a script tag. Once this is loaded then you can write code here to script the page, call ajax functions etc.
    **/
  }
});

You can write code that you could write in the browser and it will work. so to access ajax functions in jquery you could just write:

$.get("test.php", { name:"Donald", town:"Ducktown" },function(response) {
   ..cool code here..
});


/Simon

Joe Hillman

unread,
Oct 25, 2012, 11:00:44 AM10/25/12
to appj...@googlegroups.com
Either I'm missing something or jQuery is not available based on the code posted above.

Example:

index.html:
<p id="mytag">test test test test test test test test test test test test test test </p>

app.js file
$('#mytag').css('opacity', 0.25);

In a typical browser the opacity is changed as expected.  But it does not work once the ready event is fired.

Also, another interesting tidbit in the console (Command/Option J), $('#mytag') displays null, but $('mytag') displays the entire contents of the dom element.

Simon Horton

unread,
Oct 25, 2012, 11:15:00 AM10/25/12
to appj...@googlegroups.com
Hi Joe,

You are right, a line from the example code had disappeared in the post I made:

document.body.appendChild(script);

that line should be added after the lines:
  **/
  }
});

This is the line that adds the script tag to the document that then loads jquery. Add that line and see if it works for you now.

/Simon
Reply all
Reply to author
Forward
0 new messages