Add gap to ringing and dialing sounds

This commit is contained in:
emil 2022-05-19 05:53:57 +02:00 committed by Maxim Logaev
parent 39d1a29ced
commit 78d8dabf39

View file

@ -5,31 +5,34 @@ namespace Dino.Plugins.PhoneRinger {
public class Plugin : RootInterface, NotificationProvider, Object { public class Plugin : RootInterface, NotificationProvider, Object {
private const int GAP = 1;
private const int RINGER_ID = 0;
private const int DIALER_ID = 1;
private Canberra.Context sound_context; private Canberra.Context sound_context;
private const int ringer_id = 0;
private const int dialer_id = 1;
private Canberra.Proplist ringer_props; private Canberra.Proplist ringer_props;
private Canberra.Proplist dialer_props; private Canberra.Proplist dialer_props;
private bool ringing = false;
private bool dialing = false;
private void loop_ringer() { private void loop_ringer() {
sound_context.play_full(ringer_id, ringer_props, (c, id, code) => { sound_context.play_full(RINGER_ID, ringer_props, (c, id, code) => {
if (code != Canberra.Error.CANCELED) { if (code == Canberra.Error.CANCELED) return;
Idle.add(() => { Timeout.add_seconds(GAP, () => {
loop_ringer(); if (!ringing) return Source.REMOVE;
return Source.REMOVE; loop_ringer();
}); return Source.REMOVE;
} });
}); });
} }
private void loop_dialer() { private void loop_dialer() {
sound_context.play_full(dialer_id, dialer_props, (c, id, code) => { sound_context.play_full(DIALER_ID, dialer_props, (c, id, code) => {
if (code != Canberra.Error.CANCELED) { if (code == Canberra.Error.CANCELED) return;
Idle.add(() => { Timeout.add_seconds(GAP, () => {
loop_dialer(); if (!dialing) return Source.REMOVE;
return Source.REMOVE; loop_dialer();
}); return Source.REMOVE;
} });
}); });
} }
@ -50,19 +53,23 @@ public class Plugin : RootInterface, NotificationProvider, Object {
public void shutdown() { } public void shutdown() { }
public async void notify_call(Call call, Conversation conversation, bool video, bool multiparty, string conversation_display_name){ public async void notify_call(Call call, Conversation conversation, bool video, bool multiparty, string conversation_display_name){
ringing = true;
loop_ringer(); loop_ringer();
} }
public async void retract_call_notification(Call call, Conversation conversation){ public async void retract_call_notification(Call call, Conversation conversation){
sound_context.cancel(ringer_id); ringing = false;
sound_context.cancel(RINGER_ID);
} }
public async void notify_dialing(){ public async void notify_dialing(){
dialing = true;
loop_dialer(); loop_dialer();
} }
public async void retract_dialing(){ public async void retract_dialing(){
sound_context.cancel(dialer_id); dialing = false;
sound_context.cancel(DIALER_ID);
} }
public double get_priority(){ public double get_priority(){