From aff4f239c303852e210ee56543cab03e8836247b Mon Sep 17 00:00:00 2001 From: B Stack Date: Fri, 25 Sep 2020 21:09:00 -0400 Subject: add xdg autostart, and hide_when_no_media config opt --- src/etc/xdg/autostart/myautomount-trayicon.desktop | 10 +++++++++ src/etc/xdg/autostart/myautomountd.desktop | 10 +++++++++ src/usr/bin/myautomountd | 9 ++++---- .../libexec/myautomount/myautomount-trayicon.py | 25 +++++++++++++--------- 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 src/etc/xdg/autostart/myautomount-trayicon.desktop create mode 100644 src/etc/xdg/autostart/myautomountd.desktop (limited to 'src') diff --git a/src/etc/xdg/autostart/myautomount-trayicon.desktop b/src/etc/xdg/autostart/myautomount-trayicon.desktop new file mode 100644 index 0000000..061454d --- /dev/null +++ b/src/etc/xdg/autostart/myautomount-trayicon.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Comment=Tray icon for managing removable media +Exec=/usr/bin/myautomount-trayicon +GenericName=Automount helper tray icon +Icon=media-removable +Keywords=automount; +Name=MyAutoMount tray icon +NoDisplay=true +Terminal=false +Type=Application diff --git a/src/etc/xdg/autostart/myautomountd.desktop b/src/etc/xdg/autostart/myautomountd.desktop new file mode 100644 index 0000000..57a147a --- /dev/null +++ b/src/etc/xdg/autostart/myautomountd.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Comment=Monitor udevadm for removable media +Exec=/usr/bin/myautomountd +GenericName=Automount helper daemon +Icon=media-removable +Keywords=automount; +Name=MyAutoMount daemon +NoDisplay=true +Terminal=false +Type=Application diff --git a/src/usr/bin/myautomountd b/src/usr/bin/myautomountd index d23940a..3501b97 100755 --- a/src/usr/bin/myautomountd +++ b/src/usr/bin/myautomountd @@ -4,11 +4,10 @@ # Authors: beanpole135, bgstack15 # Startdate: 2020-09-23 # Title: Automount in Shell -# Purpose: almost one-for-one translation of Go version +# Purpose: # History: -# 2020-09-23 translated by bgstack15 to shell from Go version (reference 1) -# Several translation notes: configuration split out into separate file -# and given a Fedora flavor. +# 2020-09-23 originally translated by bgstack15 to shell from Go version (reference 1) +# 2020-09-25 diverged from original architecture # Usage: # Invoke this at X startup. This can be from the xdg autostart mechanism, or "exec myautomountd &" in ~/fluxbox.startup # This is the backend to myautomount-trayicon @@ -124,7 +123,7 @@ mkdir -p "${AUTOMOUNT_BASEDIR}" udevadm monitor -u -s block 1> "${AUTOMOUNT_TMPFILE}" & export AUTOMOUNT_PID="${!}" test -n "${DEBUG}" && env | grep -E '^AUTOMOUNT_' 1>&2 -while ! test -e /tmp/kill-automount ; +while ! test -e /tmp/kill-myautomount ; do tail -F "${AUTOMOUNT_TMPFILE}" 2>/dev/null | while read line ; do diff --git a/src/usr/libexec/myautomount/myautomount-trayicon.py b/src/usr/libexec/myautomount/myautomount-trayicon.py index 257c54f..e326314 100755 --- a/src/usr/libexec/myautomount/myautomount-trayicon.py +++ b/src/usr/libexec/myautomount/myautomount-trayicon.py @@ -4,7 +4,7 @@ # Author: bgstack15 # Startdate: 2020-09-24 13:17 # Title: Tray icon for automount daemon -# Purpose: Easy access to autofs-mounted removable media +# Purpose: Easy access to autofs-mounted removable media, without dbus # History: # Usage: # to be called from /usr/bin/myautomount-trayicon only, because it loads the environment variables @@ -32,9 +32,10 @@ from gi.repository import Gtk, Gdk, GLib import xdg.DesktopEntry as dentry import xdg.Exceptions as exc -showmount = 1 # show the "MOUNTED" value for each drive -skip_sd_without_partitions = 1 # skip sdb sdc, etc. # NOT IMPLEMENTED YET. -only_update_on_menuitem = 0 # if 1, then disables the mouseover poll. Prevents showmount=1 from working. +showmount = 1 # Default: 1, show the "MOUNTED" value for each drive +skip_sd_without_partitions = 1 # Default: 1, skip sdb sdc, etc. # NOT IMPLEMENTED YET. +only_update_on_menuitem = 0 # Default: 0, disable the mouseover poll. Prevents showmount=1 from working. +hide_when_no_media = 1 # Default: 1, stay hidden until some removable media is discovered # load environment variables AUTOMOUNT_BASEDIR = os.getenv("AUTOMOUNT_BASEDIR") # probably /run/user/${UID}/automedia @@ -188,7 +189,6 @@ class MainIcon(Gtk.StatusIcon): self.traymenu = Gtk.Menu() self.connect("button-press-event", self.on_button_press_event) self.connect("popup-menu", self.context_menu) - self.reestablish_menu() if not only_update_on_menuitem: self.connect("query-tooltip", self.mouseover) # need these anyway, for when the icon is hidden. @@ -199,6 +199,7 @@ class MainIcon(Gtk.StatusIcon): self.notifier1 = pyinotify.ThreadedNotifier(self.wm1, default_proc_fun=self.identity) self.notifier1.start() self.wm1.add_watch(AUTOMOUNT_BASEDIR, pyinotify.IN_CREATE | pyinotify.IN_DELETE, rec=True, auto_add=True) + self.reestablish_menu() def mouseover(self, second_self, x, y, some_bool, tooltip): #print("Mouseover happened at",str(x)+",",y,tooltip, some_bool) @@ -231,11 +232,13 @@ class MainIcon(Gtk.StatusIcon): self.add_menuitem(str(entry.app.name.decode("utf-8")),entry.app.path,entry.app.icon,self.execute,entry.app.command) self.add_separator_to_menu() if only_update_on_menuitem: - self.add_menuitem("Update menu","",None,self.reestablish_menu,"re establish") # If you want a menu option for this - self.add_menuitem("Hide until next disk change","","",self.hide,"hide") - self.add_menuitem("Exit automount-trayicon","","system-logout",self.exit,"exit") - self.menuitem_count = len(self.menuitems) - 2 + self.add_menuitem("Update menu","",None,self.reestablish_menu,"FALSE") + self.add_menuitem("Hide until next disk change","","",self.hide,"FALSE") + self.add_menuitem("Exit automount-trayicon","","system-logout",self.exit,"FALSE") + self.menuitem_count = len(self.menuitems) self.set_tooltip_text(str(self.menuitem_count)+" mount point"+("s" if self.menuitem_count > 1 else "")) + if hide_when_no_media and self.menuitem_count == 0: + self.hide() def execute(self, widget): x=0 ; y=-1 @@ -259,7 +262,9 @@ class MainIcon(Gtk.StatusIcon): self.traymenu.append(i) def add_menuitem(self,label_str,label_paren_str,icon_str,function_func,action_str): - self.menuitems.append(action_str) + # only count the real items + if action_str != "FALSE": + self.menuitems.append(action_str) full_label_str=label_str mounted_str="" # collection = [line.split()[1] for line in open("/etc/mtab") if line.split()[1].startswith('/browse') and line.split()[2] != "autofs"] -- cgit