WIP support for custom shutdown hooks with possible shutdown prevention - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93) +--- Thread: WIP support for custom shutdown hooks with possible shutdown prevention (/showthread.php?tid=201665) |
support for custom shutdown hooks with possible shutdown prevention - sven88 - 2014-08-08 hi, i was wondering, that there isn't any shutdown-hook-possibility integrated already. or did i missed something? i thought i can not be the only one with this kind of usual use cases, that's why i wanna share the code, maybe someone else has also usage for it. so far i patched and tested it with the current gotham branch from git with linux. if someone has any criticism/suggestions about the code, ideas or whatever, i would be happy to hear about! what?:
why? - some of my use cases
any future plans? - stuff i was thinking about:
what's about the os independence exatly? i have to say that i'm a linux-only guy and i don't have any other os to test this. that's also a reason, why i wanna make this feature optional via advancedsettings, to make sure this will not gonna make problems on some other os, if you did'nt activated it. at least i would say that i would have to add some os-switches for the path of the shutdown-hooks, but i don't know if that would be enough. maybe there are also different exit codes for scripting or some c/c++ functions missing. best regards, sven my xbmc branch and patches are rebased against xbmc-gotham.git-867305b. xbmc branch on github...............................................: https://github.com/svenburkard/xbmc/commits/fb_shutdownHookCheck some example shutdown-hook-scripts on github: https://github.com/svenburkard/xbmcShutdownHooks #-----------------------------------------------------------------------------------------------------------------------# latest patches: 0001-custom-shutdown-hook-support-added-with-a-possible-e.patch 0002-shutdown-hook-folder-is-now-changed-to-an-available-.patch 0003-send-a-xbmc-notification-if-a-shutdown-hook-script-i.patch 0004-.deb-build-related-stuff-added-to-.gitignore-file.patch 0005-trailing-whitespaces-removed.patch 0006-improved-the-way-of-getting-the-home-directory-to-be.patch 0007-replaced-the-sendMSGtoXBMC-curl-hack-with-a-native-x.patch 0008-replaced-cout-with-a-native-xbmc-logging-function.patch 0009-improved-the-way-of-getting-the-home-directory-now-u.patch 0010-separated-the-functions-and-class-stuff-into-.h-.cpp.patch 0011-gui-option-added-for-enabling-disabling-of-shutdownH.patch latest AllInOne Patch: fb_shutdownHookCheck-AllInOnePatch-2014.09.13-f0e5f80.patch #-----------------------------------------------------------------------------------------------------------------------# EDIT: latest patches added; future plans modified; RE: support for custom shutdown hooks with possible shutdown prevention~github link added - schumi2004 - 2014-09-04 Just what i was looking for. Can you tell me which commits i need to integrate this in my custom OpenELEC build (Gotham), is initial commit sufficient? /edit: Maybe provide some example script? For example logoff user before going in hibernate/shutdown? RE: support for custom shutdown hooks with possible shutdown prevention - sven88 - 2014-09-04 (2014-09-04, 14:56)schumi2004 Wrote: Just what i was looking for. here (link removed: see first post for patches) is a patch with all commits of this branch until now, to make implementing and testing easier. to apply the patch: Code: git am fb_shutdownHookCheck-2014.09.04-66eb2cc.patch i only tested it with xbmc gotham, generally i think this changes should also work on openelec. but it could be, that i first have to replace my notification function. because the code is looking for '/usr/bin/curl', which is maybe not available at your openelec. shouldn't be a big deal, i will replace this curl hack at the weekend. the code in xbmc is looking for a directory called 'xbmcShutdownHooks/hooks-enabled/' in the home directory of the xbmc user. my scripts are in '~/xbmcShutdownHooks/hooks-available/' and i just make softlinks to activate them. (like apache modules/sites style) you can have a look at my hook repository on github, which i'm using in my xbmc users home directory on a debian system. https://github.com/svenburkard/xbmcShutdownHooks at the moment there are hook-scripts for:
in the hook-scripts i already wrote some c++ code to send xbmc-notifications, which i also wanna use in xbmc to replace my curl binary hacks. so far i didn't wrote any documentation, so here in short to build it: Code: cd ~/xbmcShutdownHooks/ && g++ src/sendMSGtoXBMC.cpp -o bin/sendMSGtoXBMC -lcurl EDIT: link removed: see first post for patches RE: support for custom shutdown hooks with possible shutdown prevention - wsnipex - 2014-09-04 I like the idea, could really be useful. If you want to get this in mainline, it needs at least using native methods to pop notifications and moving the logic from the header to a cpp. RE: support for custom shutdown hooks with possible shutdown prevention - schumi2004 - 2014-09-05 (2014-09-04, 21:22)sven88 Wrote: i only tested it with xbmc gotham, generally i think this changes should also work on openelec. Thanks for explaining. Openelec does have curl so that shouldn't be a problem: openelec:~ # which curl /usr/bin/curl Going to compile and test it. /edit: Okay, compiling went fine after i changed the patch a bit for part @@ -259,36 +276,51 @@ void CApplicationMessenger:rocessMessage(ThreadMessage *pMsg) Probably because OE hasn't updated XBMC code to latest Gotham yet. Going to test later today. RE: support for custom shutdown hooks with possible shutdown prevention - MrMC - 2014-09-05 For OpenElec, xbmc-send -a "Notification(Hey,Hey this is a message)" RE: support for custom shutdown hooks with possible shutdown prevention - Martijn - 2014-09-05 OE always has latest code. RE: support for custom shutdown hooks with possible shutdown prevention - schumi2004 - 2014-09-05 (2014-09-05, 20:30)Martijn Wrote: OE always has latest code. Your right at some point, it doesn't do daily updates to XBMC code. (Can't expect them to do so and don't want them to) Anyway, or sven88 based his patch on older/newer XBMC code then OE was using or vice versa. In my case I needed to change that part mentioned to match XBMC version used in latest OE 4.1.5, not such a big deal. RE: support for custom shutdown hooks with possible shutdown prevention - sven88 - 2014-09-05 (2014-09-04, 21:56)wsnipex Wrote: I like the idea, could really be useful. ok, i will look into this. are there any lists/documentations available for common xbmc functions to get started? i already had a look at the wiki, but just found built-in functions to use inside of addons. so far i just did a short grep for 'notification' through the sourcecode, but there are so much matches, that i have to take a deeper look. (2014-09-05, 09:47)schumi2004 Wrote:(2014-09-04, 21:22)sven88 Wrote: i only tested it with xbmc gotham, generally i think this changes should also work on openelec. ok, good news that curl is available on openelec, but i wanted to change this curl hack anyway. but today i remembered something else, which could be a problem. the way how i got the home directory path. because in my code i thought to straight about the common linux paths (/home/..) and i think openelec has /storage. now i'm looking for the xbmc users home env variable, to be more flexible for openelec. so i think you will have more luck, if you also apply the latest patch: 0006-improved-the-way-of-getting-the-home-directory-to-be.patch RE: support for custom shutdown hooks with possible shutdown prevention - wsnipex - 2014-09-05 (2014-09-05, 20:39)sven88 Wrote:(2014-09-04, 21:56)wsnipex Wrote: I like the idea, could really be useful. check xbmc/dialogs/GUIDialogKaiToast.h RE: support for custom shutdown hooks with possible shutdown prevention - sven88 - 2014-09-05 (2014-09-05, 20:34)schumi2004 Wrote:(2014-09-05, 20:30)Martijn Wrote: OE always has latest code. to make some things clear, my patches are based on b79e5f1 at the moment. so, it's a 4 weeks old version of xbmc gotham right now. (2014-09-05, 20:47)wsnipex Wrote:(2014-09-05, 20:39)sven88 Wrote:(2014-09-04, 21:56)wsnipex Wrote: I like the idea, could really be useful. thanks RE: support for custom shutdown hooks with possible shutdown prevention - schumi2004 - 2014-09-05 (2014-09-05, 21:00)sven88 Wrote:That figures, OE is @0f3db05(2014-09-05, 20:34)schumi2004 Wrote:(2014-09-05, 20:30)Martijn Wrote: OE always has latest code. Compiling with your newest patch now and testing afterwards. RE: support for custom shutdown hooks with possible shutdown prevention - schumi2004 - 2014-09-05 I was thinking that wouldn't this be more user friendly if you could select a script from GUI instead of making folders and place scripts in it? /EDIT: Ideal would be to have a extra option in power saving settings to or shutdown/hibernate as normal or only run a script and let user decide (in script) to shutdown/hibernate or not. Or better, have the Shutdown Function list have a extra option "Run script" and an extra selection afterwards to do a shutdown/hibernate as user is used to or not? And what about multiple users (profiles) with separate scripts? /EDIT2: I probably did something wrong but it didn't worked as expected with a simple user logoff python script Code: #!/usr/bin/python I created the needed dirs in storage folder (openelec:~/xbmcShutdownHooks/hooks-enabled #) and placed script logoff.py in it and shutdown xbmc When it came back i didn't see the expected user login window. I did see a notification window "xbmcShutdownHooks stopped by sleep.py" RE: support for custom shutdown hooks with possible shutdown prevention - Martijn - 2014-09-05 tbh honest i don't think how you implemented this is in any way user friendly. you would have to be some "serious" tech savy guy to use this. I would try to aim a little for the lesser tech people as well. RE: support for custom shutdown hooks with possible shutdown prevention - sven88 - 2014-09-06 (2014-09-05, 21:24)schumi2004 Wrote: I was thinking that wouldn't this be more user friendly if you could select a script from GUI instead of making folders and place scripts in it? (2014-09-05, 21:37)Martijn Wrote: tbh honest i don't think how you implemented this is in any way user friendly. yes i agree with you guys schumi and martijn, that this solution isn't easy to use for a default user, without technical background. but i did not thought this could be an interesting feature for non-tech users, because they couldn't write their own scripts anyway. so, if there would be a good idea to make this easier, i would like to improve this of course. (2014-09-05, 21:24)schumi2004 Wrote: /EDIT: the 'extra-option' suggestion of schumi, could be a good way, right? maybe this extra option in the gui settings should show a dynamic list of all available hook scripts from the predefined directory, and make it possible to enable/disable them each per click. but you still would need to write/clone/cp/... your custom hook scripts at the commandline anyway, if you wanna use real custom hook scripts, for your own use cases. so, the full possibilitys could only be used by advanced users anyway, because the non-tech users could only activate from some predefined common scripts and not write their own scripts. i also like the idea of a user interaction for some use cases, to show a window with a question if you really wanna abort the shutdown, if a scripts has not an exit code of 0. but i wouldn't make this default, this should be configurable in the gui for each of the scripts. for example i don't want to get asked everytime at a script, which checks for active vdr recordings, because i never would shutdown xbmc while recording, this would just get anoying. (2014-09-05, 21:24)schumi2004 Wrote: Or better, have the Shutdown Function list have a extra option "Run script" and an extra selection afterwards to do a shutdown/hibernate as user is used to or not? i don't see the point in doing that for just a manual single script execute, this behavior could already be added with a custom remote key or custom button in a skin. but i wanted to be able to catch every attempt for shutdown/reboot/..., doesn't matter how you try to do this and automatic execute multiple and expandable scripts before and to be able to abort the shutdown. (2014-09-05, 21:24)schumi2004 Wrote: And what about multiple users (profiles) with separate scripts? that is something i didn't thought about yet, i do not have this use case. but if the hook settings would be done through the gui, i could imagine that there is somehow a 'xbmc-profile-name-env' variable available in xbmc, which could be used to get this personalized. (2014-09-05, 21:24)schumi2004 Wrote: /EDIT2: i have no experience with python, but if you get the message 'shutdown stopped by sleep.py', it looks like sleep.py didn't closed with an exit code of 0. did you mean sleep.py instead of logoff.py with your example code, or what is inside sleep.py? i tried to execute your example code and at my system it fails because of the import. maybe 'import xbmc' works only inside of xbmc itself. but when executing outside of xbmc, it maybe doesn't finds the libs, at least in my case it looks like that. did you also executed your file manual for testing? i would check the exit code of the script and test something without lib dependencies first (like just a script, which exits with an exit code of 0 and another script with an exit code 1) this is what i tested: sleep.py: Code: #!/usr/bin/python test.pl: Code: #!/usr/bin/perl Code: xbmc@xbmcUS:~/xbmcShutdownHooks/hooks-available$ [master] # ./test.pl at my system it isn't able to load the lib, so it's crashing, not doing my second test print and fails with an exit code of 256 and that is why the shutdown is stopped at my system. |