mirror of
https://github.com/markqvist/Sideband.git
synced 2025-12-13 07:38:56 -05:00
Added voice call notifications
This commit is contained in:
parent
cf0d64a746
commit
6b09c6b262
3 changed files with 75 additions and 58 deletions
|
|
@ -1274,8 +1274,11 @@ class SidebandApp(MDApp):
|
||||||
data = extras.getString("intent_action", "undefined")
|
data = extras.getString("intent_action", "undefined")
|
||||||
if data.startswith("conversation."):
|
if data.startswith("conversation."):
|
||||||
conv_hexhash = bytes.fromhex(data.replace("conversation.", ""))
|
conv_hexhash = bytes.fromhex(data.replace("conversation.", ""))
|
||||||
def cb(dt):
|
def cb(dt): self.open_conversation(conv_hexhash)
|
||||||
self.open_conversation(conv_hexhash)
|
Clock.schedule_once(cb, 0.2)
|
||||||
|
|
||||||
|
elif data.startswith("incoming_call"):
|
||||||
|
def cb(dt): self.voice_action()
|
||||||
Clock.schedule_once(cb, 0.2)
|
Clock.schedule_once(cb, 0.2)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,14 @@ class SidebandService():
|
||||||
}
|
}
|
||||||
|
|
||||||
def android_notification(self, title="", content="", ticker="", group=None, context_id=None):
|
def android_notification(self, title="", content="", ticker="", group=None, context_id=None):
|
||||||
if android_api_version < 26:
|
try:
|
||||||
return
|
if android_api_version < 26: return
|
||||||
else:
|
else:
|
||||||
package_name = "io.unsigned.sideband"
|
package_name = "io.unsigned.sideband"
|
||||||
|
silent_contexts = ["incoming_call"]
|
||||||
|
|
||||||
if not self.notification_service:
|
if not self.notification_service:
|
||||||
self.notification_service = cast(NotificationManager, self.app_context.getSystemService(
|
self.notification_service = cast(NotificationManager, self.app_context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||||
Context.NOTIFICATION_SERVICE
|
|
||||||
))
|
|
||||||
|
|
||||||
channel_id = package_name
|
channel_id = package_name
|
||||||
group_id = ""
|
group_id = ""
|
||||||
|
|
@ -84,21 +83,25 @@ class SidebandService():
|
||||||
channel_id += "."+str(context_id)
|
channel_id += "."+str(context_id)
|
||||||
group_id += "."+str(context_id)
|
group_id += "."+str(context_id)
|
||||||
|
|
||||||
if not title or title == "":
|
if not title or title == "": channel_name = "Sideband"
|
||||||
channel_name = "Sideband"
|
else: channel_name = title
|
||||||
else:
|
|
||||||
channel_name = title
|
if context_id in silent_contexts: silent = True
|
||||||
|
else: silent = False
|
||||||
|
|
||||||
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
self.notification_channel.enableVibration(True)
|
self.notification_channel.enableVibration(True)
|
||||||
self.notification_channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), None)
|
if not silent: self.notification_channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), None)
|
||||||
|
else: self.notification_channel.setSound(None, None)
|
||||||
self.notification_channel.setShowBadge(True)
|
self.notification_channel.setShowBadge(True)
|
||||||
self.notification_service.createNotificationChannel(self.notification_channel)
|
self.notification_service.createNotificationChannel(self.notification_channel)
|
||||||
|
|
||||||
notification = NotificationBuilder(self.app_context, channel_id)
|
notification = NotificationBuilder(self.app_context, channel_id)
|
||||||
notification.setContentTitle(title)
|
notification.setContentTitle(title)
|
||||||
notification.setContentText(AndroidString(content))
|
notification.setContentText(AndroidString(content))
|
||||||
notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
|
|
||||||
|
if not silent: notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
|
||||||
|
else: notification.setSound(None, None)
|
||||||
|
|
||||||
# if group != None:
|
# if group != None:
|
||||||
# notification.setGroup(group_id)
|
# notification.setGroup(group_id)
|
||||||
|
|
@ -121,8 +124,13 @@ class SidebandService():
|
||||||
notification_intent.setAction(Intent.ACTION_MAIN)
|
notification_intent.setAction(Intent.ACTION_MAIN)
|
||||||
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
if context_id != None:
|
if context_id != None:
|
||||||
|
if context_id == "incoming_call":
|
||||||
|
cstr = context_id
|
||||||
|
notification_intent.putExtra(JString("intent_action"), JString(cstr))
|
||||||
|
else:
|
||||||
cstr = f"conversation.{context_id}"
|
cstr = f"conversation.{context_id}"
|
||||||
notification_intent.putExtra(JString("intent_action"), JString(cstr))
|
notification_intent.putExtra(JString("intent_action"), JString(cstr))
|
||||||
|
|
||||||
self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)
|
self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
|
|
||||||
notification.setContentIntent(self.notification_intent)
|
notification.setContentIntent(self.notification_intent)
|
||||||
|
|
@ -131,6 +139,10 @@ class SidebandService():
|
||||||
built_notification = notification.build()
|
built_notification = notification.build()
|
||||||
self.notification_service.notify(0, built_notification)
|
self.notification_service.notify(0, built_notification)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Error while creating notification: {e}", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
|
||||||
def check_permission(self, permission):
|
def check_permission(self, permission):
|
||||||
if RNS.vendor.platformutils.is_android():
|
if RNS.vendor.platformutils.is_android():
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -5575,6 +5575,8 @@ class SidebandCore():
|
||||||
def incoming_call(self, remote_identity):
|
def incoming_call(self, remote_identity):
|
||||||
display_name = self.voice_display_name(remote_identity.hash)
|
display_name = self.voice_display_name(remote_identity.hash)
|
||||||
self.setstate("voice.incoming_call", display_name)
|
self.setstate("voice.incoming_call", display_name)
|
||||||
|
if self.gui_foreground(): RNS.log("Squelching call notification since GUI is in foreground", RNS.LOG_DEBUG)
|
||||||
|
else: self.notify(title="Incoming voice call", content=f"From {display_name}", group="LXST.Telephony", context_id="incoming_call")
|
||||||
|
|
||||||
rns_config = """# This template is used to generate a
|
rns_config = """# This template is used to generate a
|
||||||
# running configuration for Sideband's
|
# running configuration for Sideband's
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue