The officially official Devuan Forum!

You are not logged in.

#51 2019-02-16 00:07:44

MiyoLinux
Member
Registered: 2016-12-05
Posts: 866  

Re: Software update notifications in XFCE

MiyoLinux wrote:
franko wrote:

Are you sure? If I understand that syntax right, that means every 3:45 h since a computer is started. I believe 3 would mean at 3 am, and */3 means every 3 hours since you start a computer... Am I wrong about it? At least, that's what it seems to work like here on my machine...

I'm gonna have a brain-jerkdown thinking about this. LOL! tongue

According to my cron log, mine is working as I described. For instance, if I turn my computer on at 8:30 am (and using the 45 */3 * * * example), the cron job will do its first run at 9:45 am...despite the computer has only been on an hour and 15 minutes. However, the update-notifier.py script won't run until the computer has been on for 4 hours.

That's how mine is working...never know though...I might've jinxed it. LOLOLOL! tongue

Edited to add...

It's almost time for the cron job to run...I'll reboot and double-check. I'll report back.

Okay...it's working as I described. I'm doing the final testing of the i3 release today, so this cron log is from it.

RED = When the computer is turned on (notice I turned it on after the 6:45 am mark, but it still ran the first cron at 9:45. The second time in RED is when I rebooted to make sure that I knew what I was talking about. LOL! big_smile  Computer on at 6:20 pm, and the cron ran at 6:45 pm.

YELLOW = the cron job for the updater.

Feb 15 06:50:25 localhost cron[1386]: (CRON) INFO (pidfile fd = 3)
Feb 15 06:50:25 localhost cron[1387]: (CRON) STARTUP (fork ok)
Feb 15 06:50:25 localhost cron[1387]: (CRON) INFO (Running @reboot jobs)

Feb 15 06:55:01 localhost CRON[2835]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:05:01 localhost CRON[3939]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:15:01 localhost CRON[5020]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:17:01 localhost CRON[5231]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 07:25:01 localhost CRON[6083]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:30:01 localhost CRON[6638]: (root) CMD ([ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi)
Feb 15 07:35:01 localhost CRON[7189]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:45:01 localhost CRON[8233]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 07:55:01 localhost CRON[9322]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:05:01 localhost CRON[10344]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:15:01 localhost CRON[11372]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:17:01 localhost CRON[11583]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 08:25:01 localhost CRON[12388]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:35:01 localhost CRON[13416]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:45:01 localhost CRON[14420]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 08:55:01 localhost CRON[15417]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:05:01 localhost CRON[16414]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:15:01 localhost CRON[17415]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:17:01 localhost CRON[17610]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 09:25:01 localhost CRON[18398]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:35:01 localhost CRON[19394]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:45:01 localhost CRON[20393]: (root) CMD (/usr/bin/apt-get update)
Feb 15 09:45:01 localhost CRON[20394]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 09:45:17 localhost CRON[20390]: (CRON) info (No MTA installed, discarding output)
Feb 15 09:55:01 localhost CRON[21645]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:05:01 localhost CRON[22635]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:15:01 localhost CRON[23611]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:17:01 localhost CRON[23814]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 10:25:01 localhost CRON[24602]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:35:01 localhost CRON[25594]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:45:01 localhost CRON[26594]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 10:55:01 localhost CRON[27587]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:05:01 localhost CRON[28572]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:15:01 localhost CRON[29552]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:17:01 localhost CRON[29748]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 11:25:01 localhost CRON[30540]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:35:01 localhost CRON[31520]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:45:01 localhost CRON[32516]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 11:55:01 localhost CRON[1038]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:05:01 localhost CRON[2166]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:15:01 localhost CRON[3162]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:17:01 localhost CRON[3357]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 12:25:01 localhost CRON[4137]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:35:01 localhost CRON[5126]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:45:01 localhost CRON[6107]: (root) CMD (/usr/bin/apt-get update)
Feb 15 12:45:01 localhost CRON[6108]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 12:45:07 localhost CRON[6106]: (CRON) info (No MTA installed, discarding output)
Feb 15 12:55:01 localhost CRON[7362]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:05:01 localhost CRON[8347]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:15:01 localhost CRON[9339]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:17:01 localhost CRON[9539]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 13:25:01 localhost CRON[10412]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:35:01 localhost CRON[11401]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:45:01 localhost CRON[12389]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 13:55:01 localhost CRON[13369]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:05:01 localhost CRON[14358]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:15:01 localhost CRON[15338]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:17:01 localhost CRON[15542]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 14:25:01 localhost CRON[16330]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:35:01 localhost CRON[17314]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:45:01 localhost CRON[18298]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 14:55:01 localhost CRON[19289]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:05:01 localhost CRON[20269]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:15:01 localhost CRON[21270]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:17:01 localhost CRON[21469]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 15:25:01 localhost CRON[22250]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:35:01 localhost CRON[23242]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:45:01 localhost CRON[24233]: (root) CMD (/usr/bin/apt-get update)
Feb 15 15:45:01 localhost CRON[24234]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 15:45:06 localhost CRON[24232]: (CRON) info (No MTA installed, discarding output)
Feb 15 15:55:01 localhost CRON[25471]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:05:01 localhost CRON[26471]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:15:01 localhost CRON[27455]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:17:01 localhost CRON[27654]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 16:25:01 localhost CRON[28443]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:35:01 localhost CRON[29423]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:45:01 localhost CRON[30413]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 16:55:01 localhost CRON[31389]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:05:01 localhost CRON[32365]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:15:01 localhost CRON[888]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:17:01 localhost CRON[1091]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 17:25:01 localhost CRON[2017]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:35:01 localhost CRON[3006]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:45:01 localhost CRON[3984]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 17:55:01 localhost CRON[4974]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:05:01 localhost CRON[5958]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:15:01 localhost CRON[6946]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:17:01 localhost CRON[7146]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 15 18:20:45 localhost cron[1397]: (CRON) INFO (pidfile fd = 3)
Feb 15 18:20:45 localhost cron[1398]: (CRON) STARTUP (fork ok)
Feb 15 18:20:45 localhost cron[1398]: (CRON) INFO (Running @reboot jobs)

Feb 15 18:25:01 localhost CRON[2646]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:35:01 localhost CRON[3703]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:45:01 localhost CRON[4732]: (root) CMD (/usr/bin/apt-get update)
Feb 15 18:45:01 localhost CRON[4733]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 15 18:45:06 localhost CRON[4731]: (CRON) info (No MTA installed, discarding output)


I have been Devuanated, and my practice in the art of Devuanism shall continue until my Devuanization is complete. Until then, I will strive to continue in my understanding of Devuanchology, Devuanprocity, and Devuanivity.

Veni, vidi, vici vdevuaned. I came, I saw, I Devuaned. wink

Offline

#52 2019-02-16 02:06:14

franko
Member
Registered: 2019-02-04
Posts: 33  

Re: Software update notifications in XFCE

I've been reading this guide, that brought me to my undestanding: https://code.tutsplus.com/tutorials/sch … --net-8800

Where do you get that log? I've been just observing when do I get the aforementioned mail from the cron job...

My cron job for the update is set like this: 0 */3 * * * root /usr/bin/apt-get update

According to what you say and what seems from that log, it would mean it would be done at 3 am, 6 am etc... But I received that mail some time after midnight and before 3 am -- of that I'm sure. So I believe it counts 3 hours since the computer boot up, and than again, and again... I will give more precise attention to it tomorrow.

It IS confusing...

Last edited by franko (2019-02-16 02:09:27)

Offline

#53 2019-02-16 03:48:23

MiyoLinux
Member
Registered: 2016-12-05
Posts: 866  

Re: Software update notifications in XFCE

franko wrote:

I've been reading this guide, that brought me to my undestanding: https://code.tutsplus.com/tutorials/sch … --net-8800

Where do you get that log? I've been just observing when do I get the aforementioned mail from the cron job...

My cron job for the update is set like this: 0 */3 * * * root /usr/bin/apt-get update

According to what you say and what seems from that log, it would mean it would be done at 3 am, 6 am etc... But I received that mail some time after midnight and before 3 am -- of that I'm sure. So I believe it counts 3 hours since the computer boot up, and than again, and again... I will give more precise attention to it tomorrow.

It IS confusing...

I don't know...perhaps the mail only goes out once a day?

Regarding the location of the log...I'm on my phone, so I'm doing this from memory...

I don't remember the actual name of the cron log file...but it's located in /var/log/ and it has "cron" in the name.

EDITED: Of all things, it's called cron.log   LOLOLOL! tongue

If it's not already there, check to see if cron is commented out in the rsyslog.conf file...found in /etc/rsyslog.conf.

I think you may have to reboot after uncommenting cron in the rsyslog.conf file for it to show up in /var/log.

Last edited by MiyoLinux (2019-02-16 12:33:49)


I have been Devuanated, and my practice in the art of Devuanism shall continue until my Devuanization is complete. Until then, I will strive to continue in my understanding of Devuanchology, Devuanprocity, and Devuanivity.

Veni, vidi, vici vdevuaned. I came, I saw, I Devuaned. wink

Offline

#54 2019-02-16 12:43:34

xinomilo
Member
Registered: 2017-07-02
Posts: 59  

Re: Software update notifications in XFCE

cron.log is not always available. not by default IIRC. depends on log daemon/settings.
as root :
# grep CRON  /var/log/syslog

Feb 15 18:45:06 localhost CRON[4731]: (CRON) info (No MTA installed, discarding output)

this means there is no way to send email. you need an MTA installed. (i use ssmtp on laptop for that.)

Offline

#55 2019-02-16 17:19:36

franko
Member
Registered: 2019-02-04
Posts: 33  

Re: Software update notifications in XFCE

MiyoLinux wrote:

I don't know...perhaps the mail only goes out once a day?

Regarding the location of the log...I'm on my phone, so I'm doing this from memory...

I don't remember the actual name of the cron log file...but it's located in /var/log/ and it has "cron" in the name.

EDITED: Of all things, it's called cron.log   LOLOLOL! tongue

If it's not already there, check to see if cron is commented out in the rsyslog.conf file...found in /etc/rsyslog.conf.

I think you may have to reboot after uncommenting cron in the rsyslog.conf file for it to show up in /var/log.

No, the mail is delivered every time a root cron job is done... But you ARE right in the end. Last night I was sleepy and I deleted the mail before I checked it, and then commented basing myself on loose observation. Today I was brighter, and I checked the mail and when the various messages were sent: 15:00 and 18:00 h, for now.... and my laptop was on since about 13:00, So it's obvious I was in error. :-D Sorry for raising confusion. XD But I learned something. :-)

Offline

#56 2019-02-16 17:29:23

MiyoLinux
Member
Registered: 2016-12-05
Posts: 866  

Re: Software update notifications in XFCE

franko wrote:

No, the mail is delivered every time a root cron job is done...

Sorry for raising confusion. XD But I learned something. :-)

I also learned something. I have no mail. So, what you pointed out is good for me to know.

I didn't see it as confusion. smile


I have been Devuanated, and my practice in the art of Devuanism shall continue until my Devuanization is complete. Until then, I will strive to continue in my understanding of Devuanchology, Devuanprocity, and Devuanivity.

Veni, vidi, vici vdevuaned. I came, I saw, I Devuaned. wink

Offline

#57 2019-02-16 17:47:39

chris2be8
Member
Registered: 2018-08-11
Posts: 42  

Re: Software update notifications in XFCE

Seeing the cron log reminded me that cron tries to email output from cron jobs to the user it runs as. So if you don't want the emails just redirect the output to /dev/null (much as the output from the debian-sa1 job is). Or redirect it to a file so you can see it if you want.

Chris

Offline

#58 2019-03-23 16:23:28

vasilis74
Member
Registered: 2019-03-15
Posts: 1  

Re: Software update notifications in XFCE

Hi all! This is my first post in the forum, glad to be here!

I have followed the instructions for Update Notifier, now I am waiting for some updates to see how it works.
If I understood right, update-notifier.py starts at boot time, but does the first apt-get update after 4 hours; or I am wrong and it does the first apt-get update at boot time, and then every 4 hours? If the first is correct, could something be added, so there is an apt-get update 2-3 or 5 minutes after boot time?

I also have a problem after installing pk-update-icon and unattended-upgrades, before I found Update Notifier in this thread. Now I have uninstalled pk-update-icon and unattended-upgrades, but in Synaptic, when I click Settings>Repositories, the repositories window does not pop-up, but a "Repositories Changed" window appears. Now I can only use /etc/apt/sources.list to manage repositories.
Can someone help here, or I should better open another thread?

Offline

#59 2019-03-25 19:54:45

geki
Member
Registered: 2019-02-04
Posts: 11  

Re: Software update notifications in XFCE

Just for the curious, I ported update notifier to pygobject using glib and gio. There is no longer a status icon. Also posting my cron files for completeness to show how to delay after boot and get an update after some minutes. I have neither seen an update after boot with the pygtk2 version.

I set my update interval to one hour.

$ cat /etc/cron.d/update_notifier 
@reboot root /etc/cron.hourly/update_notifier
$ cat /etc/cron.hourly/update_notifier 
#!/bin/sh

# wait up to 180 seconds to run apt-get

MAILTO=""

test -x /usr/bin/apt-get || exit 0
/usr/bin/python3 -c 'import random; import time; time.sleep(random.random() * 180)' \
	&& /usr/bin/apt-get update
$ cat /usr/share/update-notifier/update-notifier.py
#!/usr/bin/env python3

################################################################################
# Configuration Section Begins Here                                            #
################################################################################

c = dict(
    # The title to be shown on the pop-up and the icon tooltip.
    title = "Updates Available",

    # The message to be shown in the pop-up.
    message = "There are updates available to install.",

    # Icon to use in the system tray and pop-up.
    icon = "/usr/share/update-notifier/updates.svg",

    # Frequency to check for available updates.
    #interval = 900, # 15 minutes
    #interval = 14400, # 4 hours
    interval = 3600, # 1 hour

    # Command to run to check for available updates, and the expected status
    # code that indicates updates are available.
    check = "/usr/bin/apt-get -s dist-upgrade | /bin/grep -c '^Inst '",
)

################################################################################
# Configuration Section Ends Here                                              #
################################################################################

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib

import subprocess
from time import time
from random import random

def on_activate(data):
    '''do nothing'''

def main_loop():
    global next_check
    if (int(time()) >= next_check):
        status = subprocess.getoutput(c['check'])

        # Updates?
        if (status != "0"):
            global app
            icon = Gio.Icon.new_for_string(c['icon'])
            notifier = Gio.Notification.new(c['title'])
            notifier.set_body(c['message'])
            notifier.set_icon(icon)

            app.send_notification('update.popup', notifier)

        next_check = next_check + c['interval'] + int(random() * 300)

    return GLib.SOURCE_CONTINUE;

# + 200 for cron job to run after boot
next_check = int(time()) + 200 + int(random() * 300)

# service to run only one instance and allow to functioning as-is
app = Gio.Application.new('update.notifier', Gio.ApplicationFlags.IS_SERVICE)

# either notification action or app activate signal
app.connect('activate', on_activate)

try:
    if (app.register() == True):
        source_id = GLib.timeout_add_seconds(60, main_loop)

        GLib.MainLoop().run()

        GLib.source_remove(source_id)
except GLib.Error as e:
    print('Failed to register service: {0} ({1})'.format(e.message, e.code))

# vim:expandtab

Last edited by geki (2019-04-15 14:53:58)

Offline

#60 2019-04-16 09:50:34

geki
Member
Registered: 2019-02-04
Posts: 11  

Re: Software update notifications in XFCE

I added AppIndicator3 as tray icon. UPDATE Got my problems sorted out. Reorder updating of notification and tray indicator and using Gio.SimpleAction as callback mechanism. UPDATE #2 Depend on packages ayatana-indicator-application and mate-indicator-applet or xfce-indicator-plugin.  A round of cleanup. UPDATE #3 mate-indicator-applet needs a patch to send the "secondary-activate" event. I send the patch to Debian maintainer. Hopefully we will see an update to the package with the patch applied. xfce4-indicator-plugin already generates the "secondary-activate" event.

#!/usr/bin/env python3

################################################################################
# Configuration Section Begins Here                                            #
################################################################################

config = dict(
    # The title to be shown on the pop-up and the icon tooltip.
    title = "Updates Available",

    # The message to be shown in the pop-up.
    message = "There are updates available to install.",

    # Icon to use in the system tray and pop-up.
    icon = "/usr/share/update-notifier/updates.svg",

    # Frequency to check for available updates.
    #interval = 900, # 15 minutes
    #interval = 14400, # 4 hours
    interval = 3600, # 1 hour

    # Command to run to check for available updates, and the expected status
    # code that indicates updates are available.
    check = "/usr/bin/apt-get -s dist-upgrade | /bin/grep -c '^Inst '",
)

################################################################################
# Configuration Section Ends Here                                              #
################################################################################

try:
    import gi
    gi.require_version('Gtk', '3.0')
    from gi.repository import Gio, GLib, Gtk
    gi.require_version('AyatanaAppIndicator3', '0.1')
    from gi.repository import AyatanaAppIndicator3 as appindicator

    import sys
    import subprocess
    from time import time
    from random import random
except ImportError:
    print("Failed to import Gio, GLib, Gtk or AyatanaAppIndicator3 or other helpers")
    raise NotImplementedError

# hide tray icon from application
def on_action_hide(action, parameter):
    global tray
    tray.set_status(appindicator.IndicatorStatus.PASSIVE)

# hide tray icon from app indicator
def on_menu_hide(menu_item):
    global tray
    tray.set_status(appindicator.IndicatorStatus.PASSIVE)

def on_connect_changed(indicator, connected):
    global app
    if (connected == False):
        print('packages missing: ayatana-indicator-application and mate-indicator-applet for MATE not installed (other DEs may have similar indicator-applet package for ayatana indicators)')
        app.quit()

# app indicator tray icon
def tray_icon():
    global config
    tray = appindicator.Indicator.new('update.notifier.tray', config['icon'],
        appindicator.IndicatorCategory.SYSTEM_SERVICES)
    tray.set_title(config['title'])
    tray.connect('connection-changed', on_connect_changed)

    # minimalistic menu for tray
    menu = Gtk.Menu()
    item_hide = Gtk.MenuItem.new_with_label('Hide')
    item_hide.connect('activate', on_menu_hide)
    menu.append(item_hide)
    menu.show_all()
    tray.set_menu(menu)
    tray.set_secondary_activate_target(item_hide)
    return tray

def query_update():
    global app, tray, config, next_check

    # keep application running
    app.hold()

    if (int(time()) >= next_check):
        status = subprocess.getoutput(config['check'])

        # Updates?
        if (status != "0"):
            # show tray icon
            tray.set_status(appindicator.IndicatorStatus.ACTIVE)

            # show notification popup
            icon = Gio.Icon.new_for_string(config['icon'])
            notifier = Gio.Notification.new(config['title'])
            notifier.set_body(config['message'])
            notifier.set_default_action('app.hide')
            notifier.set_icon(icon)

            app.send_notification('update-notifier-popup', notifier)

        next_check = next_check + config['interval'] + int(random() * 300)

    # keep application running
    app.release()

    return GLib.SOURCE_CONTINUE;

# + 200 for cron job to run at boot
next_check = int(time()) + 200 + int(random() * 300)

# service to run only one instance and allow to functioning as-is
app = Gio.Application.new('update.notifier.app', Gio.ApplicationFlags.IS_SERVICE)

# have a globally accessible tray instance 
tray = None

try:
    if (app.register() == True):
        # keep application running
        app.hold()

        # application hide action
        action_hide = Gio.SimpleAction.new('hide')
        action_hide.connect('activate', on_action_hide)

        app.add_action(action_hide)

        # keep application running
        app.set_inactivity_timeout(180000)

        # hidden tray icon
        tray = tray_icon()

        source_id = GLib.timeout_add_seconds(60, query_update)

        # keep application running
        app.release()
        app.run(sys.argv)

        GLib.source_remove(source_id)
except GLib.Error as e:
    print('Failed to register service: {0} ({1})'.format(e.message, e.code))

# vim:expandtab

Last edited by geki (2019-04-20 08:18:38)

Offline

#61 2019-04-16 17:11:02

geki
Member
Registered: 2019-02-04
Posts: 11  

Re: Software update notifications in XFCE

Tried to map [0][1] to python3, with Gio.Application and its dbus connection, but it seems to need a bit more knowledge. Though, an indicator should be possible without Gtk and AppIndicator3. I just need my basic variant.

If anyone is interested:

[0] https://askubuntu.com/questions/690769/ … 750#752750
[1] https://github.com/sneetsher/mysystemin … -service.c

Offline

Board footer