WIP support for custom shutdown hooks with possible shutdown prevention
#31
(2014-09-11, 10:35)wsnipex Wrote: nice, feel free to share the scripts Wink
I'm no expert in this but it worked for me.

Code:
#!/bin/bash

## XBMC: Simple script to activate login window

## Configure your XBMC details here
XBMC_HOST=127.0.0.1
XBMC_PORT=8080
XBMC_USER=xbmc
XBMC_PASS=xbmc

## No configuration changes needed below
json () {
  curl -s -i -X POST --header "Content-Type: application/json" -d "$1" http://$XBMC_USER:$XBMC_PASS@$XBMC_HOST:$XBMC_PORT/jsonrpc >/dev/null
}

echo -n "Activating loginscreen on $XBMC_HOST ..."
json '{"jsonrpc": "2.0", "method": "GUI.ActivateWindow", "params": {"window":"loginscreen"}, "id": 1}';
echo " done."
exit 0
Reply
#32
a non 0 exit code indicates failure, so your "exit 1" would stop shutdown and further processing if I read sven88's code right.
Reply
#33
(2014-09-13, 09:45)wsnipex Wrote: a non 0 exit code indicates failure, so your "exit 1" would stop shutdown and further processing if I read sven88's code right.

Your correct about the exit code fixed it but for some reason it doesn't seem to work as a hook yet. I'll do some more testing.

/edit:
Found it. Seems function json { isn't recognized correctly in OpenELEC, change it to json () { worked.
Reply
#34
Seems that my previous code doesn't work also. It locks up xbmc.

/edit:
Looks like it locks out xbmc/kodi when triggerd.
Script works perfect when xbmc/kodi is still active.
Reply
#35
(2014-09-08, 21:22)sven88 Wrote: next thing i wanna do is a simple enable/disable button at the gui settings.

i added now an gui option to enable/disable the shutdownHookCheck, which is disabled per default (f0e5f80):

Image

i did the part of the code, where i'm looking for the value of the setting, by parsing the xml on my own.
i'm sure there already has to be an internal xbmc function with something like getValueOfSetting()
and if someone could give me hint, what xbmc function you guys are using for that, i would be very grateful and of course modifying my code to use it.

i already had a look for a function like getValueOfSetting() at the sourcecode, but didn't found what i was looking for yet and playing a little bit around with xml,
was a good exercise for me anyway (also if i will replace it with an internal xbmc function later).

patches are added to the first post.
Reply
#36
(2014-09-14, 12:19)sven88 Wrote:
(2014-09-08, 21:22)sven88 Wrote: next thing i wanna do is a simple enable/disable button at the gui settings.

i added now an gui option to enable/disable the shutdownHookCheck, which is disabled per default (f0e5f80):

Image

i did the part of the code, where i'm looking for the value of the setting, by parsing the xml on my own.
i'm sure there already has to be an internal xbmc function with something like getValueOfSetting()
and if someone could give me hint, what xbmc function you guys are using for that, i would be very grateful and of course modifying my code to use it.

i already had a look for a function like getValueOfSetting() at the sourcecode, but didn't found what i was looking for yet and playing a little bit around with xml,
was a good exercise for me anyway (also if i will replace it with an internal xbmc function later).

patches are added to the first post.
Nice +1

For other OE users that want to try this out, these are the modified patches to make it compile successfully for OE
Note: based against commit 72b3a4ba
https://www.dropbox.com/s/gt0v95p1arcqya...s.zip?dl=0

Still have some issues with my previous script, added a sleep command in it now and removed echo messages and going to test it later today if it works now.
Reply
#37
@sven88: CSettings::Get().XX
e.g. CSettings::Get().GetBool()
Reply
#38
(2014-09-14, 16:22)schumi2004 Wrote:
(2014-09-14, 12:19)sven88 Wrote:
(2014-09-08, 21:22)sven88 Wrote: next thing i wanna do is a simple enable/disable button at the gui settings.

i added now an gui option to enable/disable the shutdownHookCheck, which is disabled per default (f0e5f80):

Image

i did the part of the code, where i'm looking for the value of the setting, by parsing the xml on my own.
i'm sure there already has to be an internal xbmc function with something like getValueOfSetting()
and if someone could give me hint, what xbmc function you guys are using for that, i would be very grateful and of course modifying my code to use it.

i already had a look for a function like getValueOfSetting() at the sourcecode, but didn't found what i was looking for yet and playing a little bit around with xml,
was a good exercise for me anyway (also if i will replace it with an internal xbmc function later).

patches are added to the first post.
Nice +1

For other OE users that want to try this out, these are the modified patches to make it compile successfully for OE
Note: based against commit 72b3a4ba
https://www.dropbox.com/s/gt0v95p1arcqya...s.zip?dl=0

Still have some issues with my previous script, added a sleep command in it now and removed echo messages and going to test it later today if it works now.

ok, i tested your script now and i can confirm, that it's working, while xbmc is active.
but when executed as a hook, xbmc hangs. music is still playing, but no interaction is possible.

then i edited your script a little bit to get more debug and saw, that your curl cmd hangs.
there is no answer coming from xbmc and the curl is still waiting for the response.
after killing just the curl process, the rest of the script continued and the expected actions happened.
i don't know, why there is no json answer coming, which would close the connection....so i just made a dirty workaround and added a connection timeout of 1 sec.

you could have a look for the curl debug ('additional stuff not fine transfer'), what this error is about.
maybe someone else has an idea, why this is happening, because the workaround isn't the way, how it should be done.

but i still don't get the use-case for that, why do you want do that at every shutdown?

curl debug info:
Code:
* About to connect() to 127.0.0.1 port 8080 (#0)
*   Trying 127.0.0.1...
* connected
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'xbmc'
> POST /jsonrpc HTTP/1.1
> Authorization: Basic eGJtYzp4Ym1j
> User-Agent: curl/7.26.0
> Host: 127.0.0.1:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 95
>
} [data not shown]
* upload completely sent off: 95 out of 95 bytes
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0

script:
Code:
#!/bin/bash

## XBMC: Simple script to activate login window

## Configure your XBMC details here
XBMC_HOST=127.0.0.1
XBMC_PORT=8080
XBMC_USER=xbmc
XBMC_PASS=xbmc

LOG='/tmp/blub.log'

## No configuration changes needed below
function json () {
  curl -vvvvv --max-time 1 -s -i -X POST --header "Content-Type: application/json" -d "$1" http://$XBMC_USER:$XBMC_PASS@$XBMC_HOST:$XBMC_PORT/jsonrpc >>$LOG 2>&1
}


echo "Activating loginscreen on $XBMC_HOST ..." > $LOG

json '{"jsonrpc": "2.0", "method": "GUI.ActivateWindow", "params": {"window":"loginscreen"}, "id": 1}'

echo -e "\ndone." >> $LOG


exit 0

(2014-09-14, 17:05)wsnipex Wrote: @sven88: CSettings::Get().XX
e.g. CSettings::Get().GetBool()

thanks, i will have a look for it.
Reply
#39
(2014-09-14, 18:04)sven88 Wrote: ok, i tested your script now and i can confirm, that it's working, while xbmc is active.
but when executed as a hook, xbmc hangs. music is still playing, but no interaction is possible.

then i edited your script a little bit to get more debug and saw, that your curl cmd hangs.
there is no answer coming from xbmc and the curl is still waiting for the response.
after killing just the curl process, the rest of the script continued and the expected actions happened.
i don't know, why there is no json answer coming, which would close the connection....so i just made a dirty workaround and added a connection timeout of 1 sec.

you could have a look for the curl debug ('additional stuff not fine transfer'), what this error is about.
maybe someone else has an idea, why this is happening, because the workaround isn't the way, how it should be done.

but i still don't get the use-case for that, why do you want do that at every shutdown?
I have a multi user household here and every morning someone else as previous user can launch system.
Since they all have there own Trakt.tv settings and own (modded) database (watched status etc) it would be nice to have it launch with login window every time system recovers from hibernate.
Then the user selects his profile and all is settled.
I know I can accomplish this in other ways (already do) but for me this would be the ultimate solution. (less management/configurations)

Anyway, fact is that when a shutdown/exit/hibernate is triggered, your solution doesn't allow any XBMC/Kodi handling being triggered.
Proven with your curl debug and previous tests. When a shutdown/exit/hibernate is triggered XBMC/Kodi seems to be locked and no actions can be done at that point.
Doesn't mean your mod isn't useful but not for XBMC/Kodi actions (yet)
Reply
#40
(2014-09-14, 18:14)schumi2004 Wrote:
(2014-09-14, 18:04)sven88 Wrote: ok, i tested your script now and i can confirm, that it's working, while xbmc is active.
but when executed as a hook, xbmc hangs. music is still playing, but no interaction is possible.

then i edited your script a little bit to get more debug and saw, that your curl cmd hangs.
there is no answer coming from xbmc and the curl is still waiting for the response.
after killing just the curl process, the rest of the script continued and the expected actions happened.
i don't know, why there is no json answer coming, which would close the connection....so i just made a dirty workaround and added a connection timeout of 1 sec.

you could have a look for the curl debug ('additional stuff not fine transfer'), what this error is about.
maybe someone else has an idea, why this is happening, because the workaround isn't the way, how it should be done.

but i still don't get the use-case for that, why do you want do that at every shutdown?
I have a multi user household here and every morning someone else as previous user can launch system.
Since they all have there own Trakt.tv settings and own (modded) database (watched status etc) it would be nice to have it launch with login window every time system recovers from hibernate.
Then the user selects his profile and all is settled.
I know I can accomplish this in other ways (already do) but for me this would be the ultimate solution. (less management/configurations)

aah ok i understand, thanks.

(2014-09-14, 18:14)schumi2004 Wrote: Anyway, fact is that when a shutdown/exit/hibernate is triggered, your solution doesn't allow any XBMC/Kodi handling being triggered.
Proven with your curl debug and previous tests. When a shutdown/exit/hibernate is triggered XBMC/Kodi seems to be locked and no actions can be done at that point.

yes, but that's not exactly how it looks like to me, because at the method 'GUI.ActivateWindow' from your example, it's not the action itself which is blocking, it's the response
and because of the missing response, the action will not be done, before the connection is closed.
i don't know if my previous post was clear enough, the curl debug was from the script without a connection timeout limit.
if the timeout limit is added (like at the modified code above) the connection will be closed and the loginscreen window shows up.
so the question is, why is the response blocked (by myself?)? :-)

and i'm also using json in my hook scripts to send xbmc-notifications (GUI.ShowNotification) without connection timeout hacks.
but that method is on this list JSON-RPC_API/v6 instead of List_of_built-in_functions.
so, it's not a general problem with json, it must be something more specific.

EDIT:
'GUI.ActivateWindow' method is also from the same list and not from the built-in list

(2014-09-14, 18:14)schumi2004 Wrote: Doesn't mean your mod isn't useful but not for XBMC/Kodi actions (yet)
Reply
#41
I think, this could be the solution for my problem. I would like to suspend my Windows based media center with one single button on my remote. The problem is that it doesn’t go to sleep while something is playing i.e. live tv. So I have to push the stop button first. With this add-on I could have a hook that stops everything before suspending. Is there any help how I could do this? I’m not a programmer so I‘m not able to write a needed script by myself.
Reply

Logout Mark Read Team Forum Stats Members Help
support for custom shutdown hooks with possible shutdown prevention0