Seems like you only need to trigger user input if the "Digital Editions" directory is where the book is being opened from. So how about something like:
Code:
#!/bin/sh
appDir=/ebrmain/cramfs/bin
bookDir=$(dirname "$1")
function checkDir {
if [ "$bookDir" == "/mnt/ext1/Digital Editions" ]; then digEdit=1
else digEdit=0; fi
}
function default {
exec /mnt/ext1/applications/koreader.app "$1"
exit
}
function setKorRead {
echo "$1":koreader.app >> /mnt/ext1/system/config/handlers.cfg
exec /mnt/ext1/applications/koreader.app "$1"
}
function setPbRead {
echo "$1":eink-reader.app >> /mnt/ext1/system/config/handlers.cfg
exec $appDir/eink-reader.app "$1"
}
function askUser {
$appDir/dialog 2 "" "Open $1 with:" "KOReader" "eink-reader" "Not now"; ans=$?
if [ $ans == "1" ]; then setKorRead
elif [ $ans == "2" ]; then setPbRead
elif [ $ans == "3" ]; then default
else askUser; fi
}
checkDir
if [ $digEdit == 1 ]; then askUser
else default; fi
exit
I've found you need to specify the path for the eink-reader.app file specifically within
/ebrmain/cramfs/bin otherwise the Darkmode state is not respected. Same for dialog.
You could also use this script as a replacement for
/mnt/ext1/system/bin/koreader.app as I previously suggested. This .app file is not overwritten by Koreader updates. It would mean the changes to
extensions.cfg are not necessary.
Is user input even required if you can test for the "Digital Editions" directory? If not my initial
much simpler script (now updated) would be sufficient.