PDA

View Full Version : OnlineManager for Sencha Touch



kostysh
12 Aug 2012, 9:27 PM
Useful utility for detection of the online status, and something else
Initial release on GitHub: https://github.com/kostysh/Online-Manager-for-Sencha-Touch

Features:

Detection of the online status (real, not only connection)
Events: exception, beforeonline, beforeoffline, onlinechange, online, offline


OnlineManager.on({
'onlinechange': function(mode) {
if (mode) {
console.log('We are online');
} else {
console.log('We are offline');
}
}
});

OnlineManager.start();

scottmartin
13 Aug 2012, 11:41 AM
Thank you for the contribution.

Scott.

jerome76
14 Aug 2012, 5:19 AM
Thanks kostysh! :) I will try it out

Note: this requires the apps to be native to have access to device.Connection

kostysh
15 Aug 2012, 7:46 AM
Note: this requires the apps to be native to have access to device.Connection

it is not necessary. In web-app Ext.device.Connection works in Simulator mode - it is all what is need for our task

jerome76
15 Aug 2012, 1:43 PM
If it isn't a native web-app, it wont have access to the libraries in Ext.device. I tried adding it to one of my web-apps and ran it in Chrome and it did not work.

kostysh
15 Aug 2012, 2:51 PM
but it works fine in my non-native app :)
look into official docs: http://docs.sencha.com/touch/2-0/#!/api/Ext.device.Connection

Both the Sencha Packager and PhoneGap implementations will use the native functionality to determine if the current device is online. The Simulator version will simply use navigator.onLine.
confirm that in Chrome (desktop) isOnline method works and uses navigator...

jerome76
16 Aug 2012, 7:49 AM
You gave a local link :)) but I checked the docs. I am not using PhoneGap or Sencha Packager.

When I request navigator.onLine in the console, that works.

kostysh
16 Aug 2012, 8:18 AM
Ups. fixed.
I am not using PhoneGap at this time too. But some guys use.
The main thing that Ext.device.Connection will works without native (with less features) and without any errors. If you have problems with 'production' build of your app - this is completely different question.

jerome76
16 Aug 2012, 9:08 AM
I told ya I am not using an app. I was trying this with a web app (not native, no phonegap, no sencha command). Just a dynamic web project.

kostysh
16 Aug 2012, 9:09 AM
this is what I meant

kostysh
16 Aug 2012, 9:20 AM
once again confirm:
The main thing that Ext.device.Connection will works without native (with less features) and without any errors.

And it does not matter - web app or native packaged app.

jerome76
16 Aug 2012, 9:25 AM
If Ext.device wasn't undefined when I ran my web-app I wouldn't be commenting about this. Do you include the device library any other ways?

kostysh
16 Aug 2012, 10:17 AM
If Ext.device wasn't undefined when I ran my web-app I wouldn't be commenting about this. Do you include the device library any other ways?

Yes of course. All libs should be required.
I just created simple demo for my OnlimeManager http://mindsaur.com/demo/online/
This is not native app - just web app and all works fine :)

Upd: code of the demo app already on GitHub

jerome76
16 Aug 2012, 10:20 AM
Yes, but how did you create that demo? Did you use Sencha Command? How did you include Ext.device?...

kostysh
16 Aug 2012, 10:24 AM
Yes, demo app created with sencha command. You can see on GitHub repository now

How did you include Ext.device?...
Look inside OnlineManager.js
requires: [ 'Ext.device.Connection',
...
],

jerome76
16 Aug 2012, 10:30 AM
When I try including that code in my web app, it doesn't work.


Uncaught Error: [Ext.Loader] Failed loading './device/Connection.js', please verify that the file exists sencha-touch-all-debug.js:7889
Ext.apply.onFileLoadError sencha-touch-all-debug.js:7889
(anonymous function) sencha-touch-all-debug.js:3167
Ext.apply.loadScriptFile.onScriptError sencha-touch-all-debug.js:7613
Ext.apply.injectScriptElement.onErrorFn sencha-touch-all-debug.js:7543

This is what I've been trying to get at. Sorry.

I don't use Sencha Command to create my web-apps.

kostysh
16 Aug 2012, 10:45 AM
I don't use Sencha Command to create my web-apps.
This is the reason. Sencha command uses microloader (not sdk builds).
I suggest you to use the sencha command for application structure creating.

jerome76
16 Aug 2012, 10:57 AM
No thanks.. :)) I really have no use for Ext.device. If I did, I would use Sencha commands. I don't like how the commands create the app structure and everything and my company follows a certain structure that would be hard to rearrange. I figured it was the reason once you told me you did use commands to create your app.

Anyway, it is a great plugin :)

kostysh
16 Aug 2012, 11:04 AM
Of course you can create app structure (etc) without sencha command. But, if you uses - your apps will be more lighter. Microloader - is a super feature of Sencha Touch SDK

jerome76
16 Aug 2012, 11:08 AM
I use custom bootstraps instead of the microloader. I understand what it all does. It doesn't really make a difference when you have a web-app that is 40,000 lines of code with tons of enhancements. I would definitely use sencha command if I was working on my own app and it wasn't such a big one.