This requires a little bit of help from outside and I figured udev would be a good way to catch the event in the first place.
The following shell code from the WebLaunch start.sh script creates a udev rule that listens to 'yoshibutton' and executes a shell script.
The executed script will send an event through lipc with the command "lipc-send-event com.lab126.system.event yoshibutton"(thanks eureka) which can later be catched in a mesquite app (I use pillowHelper.js for this).
So when the app gets started ( 'go' event in a Kindle template ):
And when the app gets closed to clean up ('unload' or 'pause' in a Kindle template):
Now when the power button is pressed, the function closeApplication() is called in this example and that regardless of whether preventScreenSaver is set or not.
This method is implemented in WebLaunch and works for me on the K5. As I developed this for the PaperWhite where there is no home button it would be nice if somebody with a PW could test it ( for example by testing the implementation in the WebLaunch application ).
EDIT: It is now tested and works on the K5 and the KPW :) Thanks for testing twobob!
The following shell code from the WebLaunch start.sh script creates a udev rule that listens to 'yoshibutton' and executes a shell script.
Code:
###############################################################################
## Register powerbutton handler
FILE_RULES="/etc/udev/rules.d/98-yoshibutton.rules"
FILE_NOTIFY="/lib/udev/bin/notifyyoshibutton"
#------------------------------------------------------------------------------
# Rules
if [ ! -f $FILE_RULES ]
then
mntroot rw
echo "KERNEL==\"yoshibutton\", RUN+=\"$FILE_NOTIFY\"" > $FILE_RULES
udevadm control --reload-rules
mntroot ro
fi
#------------------------------------------------------------------------------
# Notifier
if [ ! -f $FILE_NOTIFY ]
then
mntroot rw
echo '#!/bin/sh' > $FILE_NOTIFY
echo '/usr/bin/lipc-send-event com.lab126.system.event yoshibutton' >> $FILE_NOTIFY
chmod +x $FILE_NOTIFY
mntroot ro
fi
So when the app gets started ( 'go' event in a Kindle template ):
PHP Code:
//-------------------------------------------------------------
// Register power button callback
function registerPowerButtonCallback()
{
// Register Callback and watch for power button
pillowHelper.RegisterStatusBarEventCallback(appName,
function(value)
{
if( value.eventName && value.eventName === 'yoshibutton')
closeApplication();
}
);
// Request powerbutton event
pillowHelper.RequestStatusBarEvent(
appName,
'com.lab126.system.event',
'yoshibutton'
);
}
PHP Code:
pillowHelper.UnRegisterStatusBarEventCallback(appName);
This method is implemented in WebLaunch and works for me on the K5. As I developed this for the PaperWhite where there is no home button it would be nice if somebody with a PW could test it ( for example by testing the implementation in the WebLaunch application ).
EDIT: It is now tested and works on the K5 and the KPW :) Thanks for testing twobob!