Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 04-08-2013, 06:06 PM   #1
PaulFreund
*
PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.
 
PaulFreund's Avatar
 
Posts: 35
Karma: 145852
Join Date: Apr 2013
Device: Kindle Touch
pillowHelper - access to nativeBridge from mesquite

The file is also located here: https://github.com/PaulFreund/WebLau...illowHelper.js

It is used in WebLaunch and I hope it can help somebody

PHP Code:
/*##############################################################################
//
// pillowHelper.js - Library for mesquite apps requiring more capabilities
//                    - Version 1.1
//
//##############################################################################

//==============================================================================
// Exposed API 
//==============================================================================

pillowHelper.Run                                // Run function as Pillow
pillowHelper.RegisterStatusBarEventCallback        // Register for system events
pillowHelper.UnRegisterStatusBarEventCallback    // Unregister from system events
pillowHelper.RequestStatusBarEvent                // Request specific system event

//==============================================================================
// pillowHelper.Run - Run functions in the scope of a a pillow application 
//==============================================================================

//------------------------------------------------------------------------------
// Arguments 
//------------------------------------------------------------------------------

* appID has to be the id of the mesquite app currently running 
* fkt can be a string with javascript expressions or a real javascript function
* callback has one argument which is the return value of the supplied function

//------------------------------------------------------------------------------
// Information
//------------------------------------------------------------------------------

* Return values will be automatically converted to strings
* You can not access external variables inside the function supplied to fkt

//------------------------------------------------------------------------------
// Example
//------------------------------------------------------------------------------

pillowHelper.Run(
    'default_status_bar',
    'com.PaulFreund.WebLaunch',
    function() 
    {
        // Get the Screen saver prevention status
        return nativeBridge.getIntLipcProperty(
            'com.lab126.powerd', 
            'preventScreenSaver'
        );
    }, 
    function(retVal) {
        document.write('preventScreenSaver is set to '+retVal+'<br>');
    }
);

//==============================================================================
// pillowHelper.RegisterStatusBarEventCallback 
// pillowHelper.UnRegisterStatusBarEventCallback 
//==============================================================================

//------------------------------------------------------------------------------
// Arguments 
//------------------------------------------------------------------------------

* appID has to be the id of the mesquite app currently running 
* callback has one argument which is the return value of the supplied function.
  Only RegisterStatusBarEventCallback has this argument

//------------------------------------------------------------------------------
// Information
//------------------------------------------------------------------------------

* IMPORTANT!, call pillowHelper.UnRegisterStatusBarEventCallback(appID)
  before exiting the app, or else dbus will complain. This is really IMPORTANT!
* Call this function once, it will call the supplied callback for ALL events
* Events most likely have to be defined in DBUS

//------------------------------------------------------------------------------
// Example
//------------------------------------------------------------------------------

pillowHelper.RegisterStatusBarEventCallback(
    'com.PaulFreund.WebLaunch', 
    function(value) 
    {
        document.write(JSON.stringify(value));
    }
);

// Later when you close the app, this is very IMPORTANT
pillowHelper.UnRegisterStatusBarEventCallback('com.PaulFreund.WebLaunch');

//==============================================================================
// pillowHelper.RequestStatusBarEvent 
//==============================================================================

//------------------------------------------------------------------------------
// Arguments 
//------------------------------------------------------------------------------

* appID has to be the id of the mesquite app currently running 
* eventAppID has to be the name of an app you want to catch events from
* eventID has to be the message name you want to catch

//------------------------------------------------------------------------------
// Information
//------------------------------------------------------------------------------

* This works only with a registered callback (RegisterStatusBarEventCallback)
* Events most likely have to be defined in DBUS

//------------------------------------------------------------------------------
// Example
//------------------------------------------------------------------------------

pillowHelper.RequestStatusBarEvent(
    'com.PaulFreund.WebLaunch', 
    'org.freedesktop.DBus', 
    'NameOwnerChanged'
);

//==============================================================================
// Additional information
//==============================================================================

//------------------------------------------------------------------------------
// Available nativeBridge methods ( from /usr/lib/libpillow.so )
//------------------------------------------------------------------------------

devcapInitialize, raiseChrome, dismissChrome, devcapGetInt, devcapIsAvailable,
accessHasharrayProperty, getIntLipcProperty, showDialog, setLipcProperty, 
logString, setIntLipcProperty, getOrientationValue, getDynamicConfigValue,
devcapGetString, getAppId, getStringLipcProperty, messagePillowCase, 
setWindowTitle, setWindowPosition, getWindowPosition, hideKb, showKb, 
setAcceptFocus, hideMe, showMe, setWindowSize, registerEventsWatchCallback,
subscribeToEvent, cancelPendingDismiss, registerClientParamsCallback, dismissMe,
clearFlashTrigger, createFlashTrigger, flash, redraw, logTime, logDbgNum, 
logDbg, dbgCmd

//------------------------------------------------------------------------------
// Tested methods with parameters
//------------------------------------------------------------------------------

* showMe() - Set the supplied pillow visible (useful for default_status_bar)
* hideMe() - Set the supplied pillow invisible (useful for default_status_bar)
* showKb() - Show the keyboard
* hideKb() - Hide the keyboard

* getIntLipcProperty(appID, propertyName)           - Returns a integer property
* getStringLipcProperty(appID, propertyName)        - Returns a string property
* setLipcProperty(appID, propertyName, valueString) - Set property with string
* setIntLipcProperty(appID, propertyName, valueInt) - Set proprety with int


* registerEventsWatchCallback(cb)   - Set a function that will be called 
                                      when a registered event fires, 
                                      first argument of callback gets value
* subscribeToEvent(appID, eventID)  - Add a event that triggers the function
                                      supplied to registerEventsWatchCallback

* dbgCmd(command) -    Execute command, mainly from 
                    /usr/share/webkit-1.0/pillow/debug_cmds.json

//------------------------------------------------------------------------------
// Notes
//------------------------------------------------------------------------------

Special thanks go to mobileread.com, especially silver18 and eureka for 
discovering a lot of the functionality I'm using

##############################################################################*/

var pillowHelper = {};

//==============================================================================
pillowHelper.Run = function(pillowIDappIDfktcallback)
{
    
//--------------------------------------------------------------------------
    // Get function string to use (supplied function object or string )
    
var fktString '';
    if( 
fkt && {}.toString.call(fkt) === '[object Function]' )
        
fktString fkt.toString();
    else
        
fktString "function(){" fkt "}";
        
    
//--------------------------------------------------------------------------
    // Empty function, exit
    
if( fktString === undefined || fktString.length <= ) return;
    
    
//--------------------------------------------------------------------------
    // Get a (at least a little bit) unique key
    
var cmdKey Math.floor((Math.random()*10000000000)).toString();

    
//--------------------------------------------------------------------------
    // Build the command we send to pillow
    
var cmdVal=    "nativeBridge.setLipcProperty('"+appID+"','"+cmdKey+"'," +
                    
"function(){" +
                        
"try{" +
                            
"return " fktString "().toString();" 
                        
"}" +
                        
"catch(err){" 
                            
"return err;" 
                        
"}" +
                    
"}()" +
                
");";
    
    
//--------------------------------------------------------------------------
    // Strip all non-wanted whitespace characters from command
    //cmdVal = cmdVal.replace(/[\t\r\n]+/g, "");

    //--------------------------------------------------------------------------
    // Register event handler for the callback if callback is defined
    
if( callback && {}.toString.call(callback) === '[object Function]' )
    {
        
kindle.messaging.receiveMessage(cmdKey, function(messagevalue
        { 
            
callback(value); 
        });                    
    }
    
    
//--------------------------------------------------------------------------
    // Send pillow the message to execute supplied code
    
kindle.messaging.sendMessage(
        
'com.lab126.pillow'
        
'interrogatePillow'
        {
            
"pillowId"pillowID
            
"function"cmdVal
        
}
    );
}

//==============================================================================
pillowHelper.RegisterStatusBarEventCallback = function(appIDcallback)
{
    
kindle.messaging.receiveMessage(
        
'persistantCallback'
        function(
messagevalue
        {
            
callback(JSON.parse(value));
        }
    );
    
    
pillowHelper.Run(
        
'default_status_bar',
        
appID,
        
"\
            if( document.body.persistantCallback !== undefined ) \n\
                return; \n\
            \n\
            document.body.persistantCallback = function(a)\n\
            {\n\
                StatusBar.eventsCallback(a);\n\
                nativeBridge.setLipcProperty(\n\
                    '" 
appID "',\n\
                    'persistantCallback',\n\
                    JSON.stringify(a)\n\
                );\n\
            };\n\
            nativeBridge.registerEventsWatchCallback(\n\
                document.body.persistantCallback\n\
            );\n\
        "
    
);    
}

//==============================================================================
pillowHelper.UnRegisterStatusBarEventCallback = function(appID)
{
    
pillowHelper.Run(
        
'default_status_bar',
        
appID,
        function()
        {
            
// Set back to default handler 
            
nativeBridge.registerEventsWatchCallback(StatusBar.eventsCallback);     
            
            
// Undefine our persistantCallback
            
document.body.persistantCallback undefined;
        }
    );    
}

//==============================================================================
pillowHelper.RequestStatusBarEvent = function(appIDeventAppIDeventID)
{
    
pillowHelper.Run(
        
'default_status_bar',
        
appID,
        
"nativeBridge.subscribeToEvent('" eventAppID "', '" eventID "');"
    
);


Last edited by PaulFreund; 04-09-2013 at 03:39 PM. Reason: Removed unnecessary function
PaulFreund is offline   Reply With Quote
Old 04-09-2013, 07:27 AM   #2
silver18
THE NOOB
silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.silver18 ought to be getting tired of karma fortunes by now.
 
silver18's Avatar
 
Posts: 701
Karma: 1545649
Join Date: Jan 2012
Location: Italy
Device: Kindle Touch 5.3.2
Good work!!!
I don't have much time right now (I'm going to graduate in 2 weeks) but I plan to use this in Komic!
Thanks a lot!!!!
silver18 is offline   Reply With Quote
Old 04-09-2013, 03:20 PM   #3
PaulFreund
*
PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.PaulFreund understands the importance of being earnest.
 
PaulFreund's Avatar
 
Posts: 35
Karma: 145852
Join Date: Apr 2013
Device: Kindle Touch
Just wanted to say this is a new version (1.1) including event registering features as described here
PaulFreund is offline   Reply With Quote
Old 04-09-2013, 03:53 PM   #4
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
Shiny colors!! Hot content!

What more could we ask from a poster. NICE
twobob is offline   Reply With Quote
Old 11-03-2013, 12:09 PM   #5
Aeris
Developer's Corner Mascot
Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.
 
Aeris's Avatar
 
Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
Does anybody know how to use nativeBridge.setWindowPosition command?
Aeris is offline   Reply With Quote
Old 11-03-2013, 01:56 PM   #6
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
setWindowPosition(x, y)
setWindowSize(width, height)
eureka is offline   Reply With Quote
Old 11-03-2013, 02:25 PM   #7
Aeris
Developer's Corner Mascot
Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.
 
Aeris's Avatar
 
Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
mmh I've tried the first...but seems to not work for custom dialogs
Aeris is offline   Reply With Quote
Old 11-03-2013, 02:35 PM   #8
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
They are managed by the logic in the LUA layer I believe. I.E. centered.
twobob is offline   Reply With Quote
Old 11-03-2013, 02:42 PM   #9
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Maybe it's just doing not what you're expecting it to do basing on name (but I don't know what it's doing either).

Don't forget also about possible role of window manager (awesome). It... uhm... manages windows (position etc.) and can ignore any requests.
eureka is offline   Reply With Quote
Old 11-03-2013, 03:01 PM   #10
brianinmaine
Evangelist
brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.brianinmaine ought to be getting tired of karma fortunes by now.
 
brianinmaine's Avatar
 
Posts: 456
Karma: 1287375
Join Date: Jan 2013
Location: West Gardiner, Maine
Device: Touch (5.3.7)
i use that xwininfo trick: "xwininfo -tree -root | more" to see what windows are loaded by name
brianinmaine is offline   Reply With Quote
Old 11-03-2013, 03:29 PM   #11
Aeris
Developer's Corner Mascot
Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.Aeris ought to be getting tired of karma fortunes by now.
 
Aeris's Avatar
 
Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
Quote:
Originally Posted by twobob View Post
They are managed by the logic in the LUA layer I believe. I.E. centered.
Seems so...
Aeris is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding USBNetworking Icon to StatusBar (catch lipc-set-prop event with nativeBridge) MaPePeR Kindle Developer's Corner 0 07-05-2012 02:10 PM
nativeBridge.dbgCmd silver18 Kindle Developer's Corner 26 05-19-2012 09:25 AM
How do I access footnotes? Busirane Kindle Fire 6 03-04-2012 12:09 AM
Wi-Fi access lostaquarium Amazon Kindle 9 01-09-2011 04:44 PM
Kobo Firmware Access and Early Access Program PeterT Kobo Reader 115 08-09-2010 08:06 PM


All times are GMT -4. The time now is 09:12 AM.


MobileRead.com is a privately owned, operated and funded community.