rootkiwi / an2linuxserver

Sync Android notifications encrypted to a Linux desktop
Other
402 stars 43 forks source link

Icon size #26

Open jonathashenriques opened 7 years ago

jonathashenriques commented 7 years ago

Is there a way to change the default icon size of the notifications ?

rootkiwi commented 7 years ago

Great idea, just added a setting in the app so user can choose between 20-100 px.

Most notification daemons seem to scale the icon to a specific size anyway. I'm using dunst and it does not scale the icon so for me this setting is nice.

jonathashenriques commented 7 years ago

Thank you so much ! I'm using dunst too. Sorry for bothering but, its possible that i add an script before the software send the notification ? Here's the example:

#!/usr/bin/env bash

# TAKE A SCREENSHOT AND DISPLAY A NOTIFICATION
# DEPENDS ON: DATE, IMAGEMAGICK AND LIBNOTIFY-ID

# COMPOSED SCREENSHOT ICON TEMPORARY PATH
COMPOSED_SCREENSHOT_ICON="/tmp/COMPOSED_SCREENSHOT_ICON.png"

# NON-COMPOSED SCREENSHOT ICON TEMPORARY PATH
NON_COMPOSED_SCREENSHOT_ICON="/tmp/NON_COMPOSED_SCREENSHOT_ICON.png"

# RESIZE SCREENSHOT
SCREENSHOT_ICON_DIMENSIONS="40x40"

# SCREENSHOT ICON BACKGROUND FOR COMPOSITION
SCREENSHOT_ICON_BACKGROUND="/usr/share/icons/Notifications/Notifications_Model.png"

# SCRIPT BEGINS HERE

# SCREENSHOT DIRECTORY
SCREENSHOT_FOLDER="$HOME/Pictures/Screenshots"
mkdir -p "$SCREENSHOT_FOLDER" || { printf "%s\n" "Error: Couldn't create screenshot directory"; exit; }

# PUT SCREENSHOT IN CURRENT DATE FOLDER
DATE="$(date +%F)"
mkdir -p "${SCREENSHOT_FOLDER}/${DATE}"

# NAME THE SCREENSHOT
SCREENSHOT="${SCREENSHOT_FOLDER}/${DATE}/$(date +%F-%I-%M-%S).png"

# TAKE THE SCREENSHOT
import -window root "$SCREENSHOT"

# COMPOSITE SCREENSHOT ICON FOR NOTIFICATION
convert "$SCREENSHOT" -quality 100 -resize "$SCREENSHOT_ICON_DIMENSIONS" "$NON_COMPOSED_SCREENSHOT_ICON"
composite -gravity west "$NON_COMPOSED_SCREENSHOT_ICON" "$SCREENSHOT_ICON_BACKGROUND" "$COMPOSED_SCREENSHOT_ICON"
SCREENSHOT_ICON="$COMPOSED_SCREENSHOT_ICON"

# SEND THE NOTIFICATION
notify-send -a ImageMagick -i "$SCREENSHOT_ICON" -r 101 "A screenshot was taken !" "Saved as: ${SCREENSHOT/*\/}"

And that's how it looks like at the end: PS.: Yeah, its just that icon and that line, haha.

2017-02-04-06-17-12

2017-02-04-06-17-25

Again, sorry about the long post ! But i really will apreciate if you know how to help.

rootkiwi commented 7 years ago

Im not exactly sure what you mean. With current code it can not run a script before but changing a few lines of code should be enough.

If you explain what it is you want I can help you with that.

jonathashenriques commented 7 years ago

All i want is add this little line at the side of the icon, is just a separator. On my setup i use imagemagick to do it, using the composite function with the icon.png and a background.png:

composite -gravity west "$NON_COMPOSED_ICON" "$_ICON_BACKGROUND" "$COMPOSED_ICON"

Then i send the composed image with notify-send:

notify-send -i "$COMPOSED_ICON"

But to do it with an2linux i need to be able to make that composition before sending the notification. Hope i made myself clear now.

rootkiwi commented 7 years ago

Yes now I understand. You could try something like this:

Replace what is on line 73 self.icon_path = icon_tmp_file.name with:

index d7b8851..31443fb 100755
--- a/an2linuxserver.py
+++ b/an2linuxserver.py
@@ -70,7 +70,12 @@ class Notification:
         self.icon_tmp_file = icon_tmp_file
         self.icon_path = ''
         if self.icon_tmp_file is not None:
-            self.icon_path = icon_tmp_file.name
+            non_comp = '/tmp/NON_COMPOSED_ICON.png'
+            comp = '/tmp/COMPOSED_ICON.png'
+            line = '/usr/share/icons/Notifications/Notifications_Model.png'
+            shutil.copy(icon_tmp_file.name, non_comp)
+            subprocess.Popen(['composite', '-gravity', 'west', non_comp, line, comp]).wait()
+            self.icon_path = comp