maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   [WIP] Custom Ambience System (https://talk.maemo.org/showthread.php?t=92910)

gehowa 2014-03-20 20:56

[WIP] Custom Ambience System
 
I tried to create a more elaborated Ambience system -- just changing the background and ringtones gets rather dull after a while. My first small steps are documented on TJC. I also got a lot of inspiration from the "Tinkering with DBUS" thread here on TMO.

Now I that I got the whole thing to work, I thought I'd share it with you. Please note that this still involves rather a lot of console work.

At the heart of this custom ambience system is the following python script, let's call it custom_ambiences.py. This script first executes boot.sh (so that you can run something when your Jolla starts up), and then listens to the DBIS and executes $TOHID.sh when a TOH is attached. Besides that, it executes [I]$AMBIENCE_NAME[I].sh when a new ambience is selected. It looks for those scripts in /home/nemo/scripts.

The content of /home/nemo/scripts/custom_ambiences.py:

PHP Code:

#!/usr/bin/python

def start_script(cmd):
    try:
        
subprocess.Popen([cmd])
    
except OSError:
            
with open(cmd"w") as text_file:
                    
text_file.write("#!/bin/sh")

def start_toh_script(senderdict, array):
        if 
'TOHID' in dict:
                print 
dict['TOHID']
                
cmd "/home/nemo/scripts/"+dict['TOHID']+".sh"

def start_ambience_script(var1,var2,var3,var4):
        
pathos.popen("gconftool-2 -g /desktop/meego/background/portrait/picture_filename").read()
        
path=path.split("/")
        
ambience=path[len(path)-1].split(".ambience")[0]
        
cmd="/home/nemo/scripts/"+ambience+".sh"
    
start_script(cmd)


import dbusgobjectsubprocessos
from dbus
.mainloop.glib import DBusGMainLoop
dbus
.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus dbus.SystemBus()
session dbus.SessionBus()
object session.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications')
interface = 
dbus.Interface(object,'org.freedesktop.Notifications')

cmd "/home/nemo/scripts/boot.sh"
subprocess.Popen([cmd])

bus.add_signal_receiver(start_toh_script,dbus_interface='org.freedesktop.DBus.Properties',path='/com/jolla/tohd')
session.add_signal_receiver(start_ambience_script,dbus_interface='com.nokia.profiled'path='/com/nokia/profiled')

loop gobject.MainLoop()
loop.run() 

Then we have to turn this script into a service, so that it starts during booting the device and runs in the background the whole time. In order to achieve this, first create /home/nemo/.config/systemd/user/autostart-apps.service:

PHP Code:

[Unit]
Description=Run applications at startup
Requires
=lipstick.service
After
=lipstick.service

[Service]
Type=oneshot
ExecStart
=/home/nemo/.config/systemd/scripts/autostart-apps

[Install]
WantedBy=post-user-session.target 

Then create /home/nemo/.config/systemd/scripts/autostart-apps:

PHP Code:

#!/bin/sh -

invoker ---type=generic /home/nemo/scripts/custom_ambiences.py 

Then enable the service: systemctl --user enable /home/nemo/.config/systemd/user/autostart-apps.service

(I took this also from TJC)

And then you're good to go!

Some cool things you can do with this:
  • Overrule the ambience which is associated with a specific TOH: Just use dbus-send --session --print-reply --dest=com.jolla.ambienced /com/jolla/ambienced com.jolla.ambienced.setAmbience string:"file://path/to/ambience" in the $TOHID.sh script
  • Start a VPN connection
  • Hide some apps (e.g. no games when you should work ;) ) by means of adding "NoDisplay=true" to the appropriate .desktop files
  • Enable/disable email: e.g. ag-tool enable-service 4 email

If you have any other ideas, I'd be glad to hear them.

Penguin 2014-03-21 01:39

Re: [WIP] Custom Ambience System
 
Jolla is working with some extensions to ambiance framework with Rovio and their Angry Birds TOH. I do not know when those will be available in OS or if those already are.

I like this custom Ambience system idea. However in my opinion it should be installed properly under /usr and so that it would be possible to still create ambience rpms fully compatible with native ambiance support but with extensions this custom system would provide.

I do not support such short cutting solutions which alter system files or other applications files as those are like asking for troubles and average joe will only break his OS with those sooner or later.

Would be nice target to have a framework with custom-ambience-server and custom-ambience-gui to manage them, guidelines howto to create custom features into ambience packages, how those shall be installed into system so that custom framework will recognize those, common configuration guidelines for those (gconf?) etc...

I might be interested to contribute to such activity too. Currently I am too busy with custom keyboard framework and one commercial project but after those may be.

taixzo 2014-03-21 02:29

Re: [WIP] Custom Ambience System
 
Would it be possible to set a custom ambiance from an app (or terminal command) for those of us with an N9 or other device that doesn't support Other Halfs?

Penguin 2014-03-21 03:24

Re: [WIP] Custom Ambience System
 
Can't you just set any ambiance from UI as in Jolla if you are running Sailfish OS in your device?

taixzo 2014-03-21 03:42

Re: [WIP] Custom Ambience System
 
Quote:

Originally Posted by Penguin (Post 1417914)
Can't you just set any ambiance from UI as in Jolla if you are running Sailfish OS in your device?

Sure, but not these extended ones, as the scripts are triggered by the OH if I understand correctly.

Penguin 2014-03-21 03:45

Re: [WIP] Custom Ambience System
 
With that script may be, but it could be changed so that any ambience change triggers extensions too. Good start in that script but as I wrote IMO should be extended to more robust custom ambience framework.

Schturman 2014-03-21 09:37

Re: [WIP] Custom Ambience System
 
gehowa, thank for this command:
Code:

dbus-send --session --print-reply --dest=com.jolla.ambienced /com/jolla/ambienced com.jolla.ambienced.setAmbience string:"file://path/to/ambience"
Going to use it :)

Schturman 2014-03-26 08:12

Re: [WIP] Custom Ambience System
 
Can someone tell me how to check with dbus command which ambience active now ?
I found only this way to see the name of active ambience... :o:
Code:

grep 'ambience' /home/nemo/.gconf/desktop/meego/background/portrait/%gconf.xml|cut -d '/' -f6|cut -d '<' -f1

Penguin 2014-03-26 09:32

Re: [WIP] Custom Ambience System
 
Not dbus but...

Execute as nemo user:
Code:

gconftool-2 --get /desktop/meego/background/portrait/picture_filename
or as root

Code:

su - nemo -c "gconftool-2 --get /desktop/meego/background/portrait/picture_filename"

Schturman 2014-03-26 10:08

Re: [WIP] Custom Ambience System
 
Thanks, it shorter than my :D


All times are GMT. The time now is 07:58.

vBulletin® Version 3.8.8