annotate sat/plugins/plugin_misc_android.py @ 2853:6901a425d882

quick frontend (widgets): improved deletion of widget: QuickWidget deletion has been improved a bit. A new "all_instances" kwarg can be used to completely delete all instances of a widget.
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:03:41 +0100
parents 90115cf4e731
children 26d6ac4e4a66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for file tansfer
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2756
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
20 import sys
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 import os
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
22 import os.path
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _, D_
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.constants import Const as C
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.log import getLogger
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
26 from sat.core import exceptions
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
27 from twisted.internet import reactor
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
28 from twisted.internet import protocol
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
29 from twisted.internet import error as int_error
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 log = getLogger(__name__)
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
34 C.PI_NAME: "Android ",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
35 C.PI_IMPORT_NAME: "android",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
36 C.PI_TYPE: C.PLUG_TYPE_MISC,
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
37 C.PI_MAIN: "AndroidPlugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
38 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 C.PI_DESCRIPTION: D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 """Manage Android platform specificities, like pause or notifications"""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 ),
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 }
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 if sys.platform != "android":
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 raise exceptions.CancelError(u"this module is not needed on this platform")
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 from plyer import notification, vibrator
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 PARAM_VIBRATE_CATEGORY = "Notifications"
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 PARAM_VIBRATE_NAME = "vibrate"
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 PARAM_VIBRATE_LABEL = D_(u"Vibrate on notifications")
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
52 SOCKET_DIR = "/data/data/org.salutatoi.cagou/"
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
53 SOCKET_FILE = ".socket"
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 STATE_RUNNING = "running"
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
55 STATE_PAUSED = "paused"
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
56 STATE_STOPPED = "stopped"
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
57 STATES = (STATE_RUNNING, STATE_PAUSED, STATE_STOPPED)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
58
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
59
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
60 class FrontendStateProtocol(protocol.Protocol):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
61
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
62 def __init__(self, android_plugin):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
63 self.android_plugin = android_plugin
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
64
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
65 def dataReceived(self, data):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
66 if data in STATES:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
67 self.android_plugin.state = data
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
68 else:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
69 log.warning(u"Unexpected data: {data}".format(data=data))
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
70
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
71
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
72 class FrontendStateFactory(protocol.Factory):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
73
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
74 def __init__(self, android_plugin):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
75 self.android_plugin = android_plugin
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
76
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
77 def buildProtocol(self, addr):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
78 return FrontendStateProtocol(self.android_plugin)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
79
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 class AndroidPlugin(object):
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 params = """
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 <params>
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 <individual>
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 <category name="{category_name}" label="{category_label}">
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 <param name="{param_name}" label="{param_label}" value="true" type="bool" security="0" />
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 </category>
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 </individual>
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 </params>
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 """.format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 category_name=PARAM_VIBRATE_CATEGORY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 category_label=D_(PARAM_VIBRATE_CATEGORY),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 param_name=PARAM_VIBRATE_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 param_label=PARAM_VIBRATE_LABEL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 )
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def __init__(self, host):
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
100 log.info(_(u"plugin Android initialization"))
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.host = host
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 host.memory.updateParams(self.params)
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
103 try:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
104 os.mkdir(SOCKET_DIR, 0700)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
105 except OSError as e:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
106 if e.errno == 17:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
107 # dir already exists
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
108 pass
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
109 else:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
110 raise e
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
111 self._state = None
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
112 factory = FrontendStateFactory(self)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
113 socket_path = os.path.join(SOCKET_DIR, SOCKET_FILE)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
114 try:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
115 reactor.listenUNIX(socket_path, factory)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
116 except int_error.CannotListenError as e:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
117 if e.socketError.errno == 98:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
118 # the address is already in use, we need to remove it
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
119 os.unlink(socket_path)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
120 reactor.listenUNIX(socket_path, factory)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
121 else:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
122 raise e
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 # we set a low priority because we want the notification to be sent after all
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
124 # plugins have done their job
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=-1000)
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 @property
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
128 def state(self):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
129 return self._state
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
130
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
131 @state.setter
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
132 def state(self, new_state):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
133 log.debug(u"frontend state has changed: {state}".format(state=new_state))
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
134 previous_state = self._state
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 self._state = new_state
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
136 if new_state == STATE_RUNNING:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
137 self._onRunning(previous_state)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
138 elif new_state == STATE_PAUSED:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
139 self._onPaused(previous_state)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
140 elif new_state == STATE_STOPPED:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
141 self._onStopped(previous_state)
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
142
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
143 @property
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def cagou_active(self):
2841
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
145 return self._state == STATE_RUNNING
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
146
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
147 def _onRunning(self, previous_state):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
148 if previous_state is not None:
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
149 self.host.bridge.bridgeReactivateSignals()
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
150
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
151 def _onPaused(self, previous_state):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
152 self.host.bridge.bridgeDeactivateSignals()
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
153
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 def _onStopped(self, previous_state):
90115cf4e731 plugin android: improved state handling:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
155 pass
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def _notifyMessage(self, mess_data, client):
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 # send notification if there is a message and it is not a groupchat
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 if mess_data["message"] and mess_data["type"] != C.MESS_TYPE_GROUPCHAT:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 message = mess_data["message"].itervalues().next()
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 subject = mess_data["subject"].itervalues().next()
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 subject = u"Cagou new message"
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 notification.notify(title=subject, message=message)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 if self.host.memory.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 PARAM_VIBRATE_NAME, PARAM_VIBRATE_CATEGORY, profile_key=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 ):
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 vibrator.vibrate()
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 return mess_data
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 def messageReceivedTrigger(self, client, message_elt, post_treat):
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 if not self.cagou_active:
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 # we only send notification is the frontend is not displayed
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 post_treat.addCallback(self._notifyMessage, client)
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 return True