From 0b4566affc58fd47f8940f83fa248d7657857206 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sun, 21 Mar 2021 13:05:30 +0000 Subject: [PATCH] Work on incoming calls Unlike SXMO, I have opted to use rofi to prompt for an incoming call. This allows me to have accept and decline buttons easily rather than multiple notifications. --- bin/.bin/modem/checkCall | 58 ++++++---- rofi/.config/rofi/themes/incoming-call.rasi | 114 ++++++++++++++++++++ 2 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 rofi/.config/rofi/themes/incoming-call.rasi diff --git a/bin/.bin/modem/checkCall b/bin/.bin/modem/checkCall index e6384098..9a40ffff 100755 --- a/bin/.bin/modem/checkCall +++ b/bin/.bin/modem/checkCall @@ -30,11 +30,13 @@ lookupcontact(){ } answer-call(){ + export DISPLAY=:0.0 + echo "answer call $1" > /dev/tty mmcli -m "$modem" -o "$1" --accept } reject-call(){ - notify-send "Reject" + mmcli -m "$modem" -o "$1" --hangup } prompt-incoming(){ @@ -45,22 +47,20 @@ prompt-incoming(){ local choice='' # Used for testing - local number="${1:-01234 567890}" - - local prompt="$(echo -en "Incoming Call\n$number")" + local contact="${1:-01234 567890}" - while [ -z "$choice" ]; do + local prompt="$(echo -en "Incoming Call\n$contact")" - choice="$(echo -e "$answer\n$reject" | rofi -dmenu -i \ - -theme themes/incoming-call.rasi -a 0 -u 1 \ - -p "$prompt" \ - -me-select-entry '' -me-accept-entry MousePrimary)" + choice="$(echo -e "$answer\n$reject" | rofi -dmenu -i \ + -theme themes/incoming-call.rasi -a 0 -u 1 \ + -p "$prompt" \ + -window-title "call-from-$contact" \ + -me-select-entry '' -me-accept-entry MousePrimary)" - case "$choice" in - "$answer") echo "answer" ;; - "$reject") echo "reject" ;; - esac - done + case "$choice" in + "$answer") echo "accept" ;; + "$reject") echo "reject" ;; + esac } mkdir -p "$CALL_DIR" @@ -87,6 +87,7 @@ done checkIncoming(){ + export DISPLAY=:0.0 local id="$( mmcli -m "$modem" --voice-list-calls | grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep -Eo '[0-9]+' )" @@ -97,12 +98,15 @@ checkIncoming(){ local number="$(lookupnumberfromcallid "$id")" local contact="$(lookupcontact "$number")" - local action="$(prompt-incoming "$contact")" - - case action in - accept) answer-call "$id" ;; - reject) reject-call "$id" ;; + local action="" + while mmcli -m "$modem" --voice-list-calls | grep -Eoq "$id"' incoming \(ringing-in\)' && [ -z "$action" ]; do + action="$(prompt-incoming "$contact")" + done + case "$action" in + "accept") answer-call "$id"; break ;; + "reject") reject-call "$id"; break ;; esac + } checkFinished(){ @@ -113,14 +117,24 @@ checkFinished(){ [ "$count" -eq 0 ] && return + echo "$ids" | while read -r id; do # Delete from the modem local number="$(lookupnumberfromcallid "$id")" local contact="$(lookupcontact "$number")" - echo "Missed call from $contact" >> "$CALL_DIR/missed-calls" - mmcli -m "$modem" --voice-delete-call "$id" - + # If there is a rofi process with the title of "call-from-number", then + # it hasn't been answerd yet. + # Treat as a missed call + if ps aux | grep -E '\Wrofi' | grep -q "call-from-$number"; then + echo "Missed call from $contact" >> "$CALL_DIR/missed-calls" + mmcli -m "$modem" --voice-delete-call "$id" + ps aux | grep -E '\Wrofi' | grep "call-from-$number" | + awk '{print $2}' | xargs kill + fi + + + done } diff --git a/rofi/.config/rofi/themes/incoming-call.rasi b/rofi/.config/rofi/themes/incoming-call.rasi new file mode 100644 index 00000000..eaec1825 --- /dev/null +++ b/rofi/.config/rofi/themes/incoming-call.rasi @@ -0,0 +1,114 @@ +/* + * Adapted from code from: + * + * Author : Aditya Shakya + * Mail : adi1090x@gmail.com + * Github : @adi1090x + * Twitter : @adi1090x + * + */ + +configuration { + font: "iosevka 45"; + disable-history: false; + fullscreen: false; + hide-scrollbar: true; + sidebar-mode: false; +} + +@import "../gruvbox-dark.rasi" + +* { + background-color: @background; + text-color: @foreground; +} + +window { + transparency: "real"; + border-radius: 0px; + location: north; + width: 500px; + y-offset: 45px; +} + +prompt { + enabled: true; + padding: 1px; + background-color: @background-light; + text-color: @accent; + border: 0px; + border-radius: 0px; + border-color: @accent; + left: 2px; + text-align: center; +} + + +inputbar { + children: [ prompt ]; + spacing: 0px; + background-color: @background; + text-color: @foreground; + expand: false; + border: 0px; + border-radius: 0px; + border-color: @accent; + margin: 0px 0px 0px 0px; + padding: 0px; + position: west; +} + +listview { + columns: 6; + lines: 1; + spacing: 12px; + cycle: true; + dynamic: true; + layout: vertical; +} + +mainbox { + background-color: @background; + children: [ inputbar, listview ]; + spacing: 12px; + margin: 12px; +} + +element { + background-color: @background-light; + text-color: @foreground; + orientation: vertical; + border-radius: 0px; +} + +element-text { + font: "iosevka 45"; + expand: true; + horizontal-align: 0.5; + vertical-align: 0; + margin: 5px 10px 30px 10px; +} + +element normal.urgent, +element alternate.urgent, +element selected.urgent { + background-color: @gruvbox-dark-red; + text-color: @background; + border-radius: 0px; +} + +element normal.active, +element alternate.active, +element selected.active { + background-color: @gruvbox-dark-green; + text-color: @background; +} + +element selected { + background-color: @accent; + text-color: @background; + border: 0px; + border-radius: 0px; + border-color: @border; +} +