Skip to content

apt-updates@zamszowy: initial release #6935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions apt-updates@zamszowy/LICENSE

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions apt-updates@zamszowy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# APT updates notifier

This applet monitors if updates are available for systems using APT tool (like
Debian). It also allows viewing available updates and installing them through
the popup menu.

In order to have updates count refreshed, some external way to do this is
needed (e.g. enabled automatic updates checking in `gnome-software`, or some
other way to periodically run `apt update`).

## Settings

You can:

- change refresh timeout
- change default (`apt update/upgrade`) commands to your own.
- enable showing three (configurable) levels of icon to show how many packages
are waiting for the upgrades.
- hide applet if there are not updates available

## Dependencies

- `gnome-terminal`

## Icons

Icons are based on [Papirus icon theme](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme).
151 changes: 151 additions & 0 deletions apt-updates@zamszowy/files/apt-updates@zamszowy/applet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const Applet = imports.ui.applet;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const Settings = imports.ui.settings;
const Util = imports.misc.util;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;


function AptUpdates(metadata, orientation, panel_height, instance_id) {
this._init(metadata, orientation, panel_height, instance_id);
}

AptUpdates.prototype = {
__proto__: Applet.TextIconApplet.prototype,

_init: function(metadata, orientation, panel_height, instance_id) {
this.applet_path = metadata.path;

Applet.TextIconApplet.prototype._init.call(this, orientation, panel_height, instance_id);

this.set_applet_icon_name("update-none");
this.hide_applet_label(true);

this.menuManager = new PopupMenu.PopupMenuManager(this);
this.menu = new Applet.AppletPopupMenu(this, orientation);
this.menuManager.addMenu(this.menu);

if (!GLib.find_program_in_path("gnome-terminal")) {
this.hide_applet_icon(true);
this.hide_applet_label(false);
this.set_applet_label("missing dependencies");
return;
}

this.uuid = metadata.uuid;
this.settings = new Settings.AppletSettings(this, metadata.uuid, instance_id);

this.settings.bind("update-refresh", "refreshTimeout", null, null);
this.settings.bind("hide-applet", "hideApplet", this._update, null);

this.settings.bind("different-levels", "differentLevels", this._update, null);
this.settings.bind("level-1", "level1", this._update, null);
this.settings.bind("level-2", "level2", this._update, null);

this.settings.bind("commandUpdate", "commandUpdate", null, null);
this.settings.bind("commandUpgrade", "commandUpgrade", null, null);

this.packages_count = 0;

this.enabled = true;
this.run();
},

_update: function() {
const count = this.packages_count;

this.set_applet_enabled(!this.hideApplet || count != 0);

if (this.differentLevels) {
if (count <= 0) {
this.set_applet_tooltip("No updates available");
this.set_applet_icon_name("update-none");
} else if (count < this.level1) {
this.set_applet_tooltip(count.toString() + " updates available");
this.set_applet_icon_name("update-low");
} else if (count < this.level2) {
this.set_applet_tooltip(count.toString() + " updates available");
this.set_applet_icon_name("update-medium");
} else {
this.set_applet_tooltip(count.toString() + " updates available");
this.set_applet_icon_name("update-high");
}
} else {
if (count <= 0) {
this.set_applet_tooltip("No updates available");
this.set_applet_icon_name("update-none");
} else {
this.set_applet_tooltip(count.toString() + " updates available");
this.set_applet_icon_name("update-low");
}
}

this.menu.removeAll();
this._contentSection = new PopupMenu.PopupMenuSection();
this.menu.addMenuItem(this._contentSection);

const iViewStr = count > 0 ? "View " + count.toString() + " updates" : "No updates to view";
let iView = new PopupMenu.PopupIconMenuItem(iViewStr, "view-list-bullet-symbolic", St.IconType.SYMBOLIC, {reactive: count > 0});
iView.connect('activate', Lang.bind(this, function () {
Util.spawn_async(['/bin/bash', this.applet_path + '/updates.sh', "view"]);
}));

let iCheck = new PopupMenu.PopupIconMenuItem("Check for new updates", "view-refresh-symbolic", St.IconType.SYMBOLIC);
iCheck.connect('activate', Lang.bind(this, function () {
const args = ['/bin/bash', this.applet_path + '/updates.sh', "command", this.commandUpdate];
Util.spawn_async(args, Lang.bind(this, function() {
this._refreshUpdatesInfo();
}));
}));

const iUpgradeStr = count > 0 ? "Upgrade " + count.toString() + " packages" : "No packages to upgrade";
let iUpgrade = new PopupMenu.PopupIconMenuItem(iUpgradeStr, "system-run-symbolic", St.IconType.SYMBOLIC, {reactive: count > 0});
iUpgrade.connect('activate', Lang.bind(this, function () {
const args = ['/bin/bash', this.applet_path + '/updates.sh', "command", this.commandUpgrade];
Util.spawn_async(args, Lang.bind(this, function() {
this._refreshUpdatesInfo();
}));
}));

this.menu.addMenuItem(iCheck);
this.menu.addMenuItem(iView);
this.menu.addMenuItem(iUpgrade);
},

on_applet_clicked: function() {
this.menu.toggle();
},

on_applet_removed: function() {
this.enabled = false;
},

_refreshUpdatesInfo: function() {
Util.spawn_async(['/bin/bash', this.applet_path + '/updates.sh', "check"], Lang.bind(this, function(stdout){
this.packages_count = parseInt(stdout.trim());
this._update();
}));
},

run: function() {
if (!this.enabled) {
return;
}

Util.spawn_async(['/bin/bash', this.applet_path + '/updates.sh', "check"], Lang.bind(this, function(stdout){
this.packages_count = parseInt(stdout.trim());
this._update();

Util.spawn_async(['/usr/bin/sleep', (parseInt(this.refreshTimeout) * 60).toString()], Lang.bind(this, function(_) {
this.run();
}));
}));
},
};

function main(metadata, orientation, panel_height, instance_id) {
return new AptUpdates(metadata, orientation, panel_height, instance_id);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions apt-updates@zamszowy/files/apt-updates@zamszowy/info-window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/gjs

imports.gi.versions.Gtk = "3.0";
const Gtk = imports.gi.Gtk;
const GLib = imports.gi.GLib;

function onKeyPress(actor, event) {
const [, key] = event.get_keyval();
const [, modifier] = event.get_state();

if ((key === 65307 /* ESC */) || (key === 119 /* w */ && modifier == 20 /* ctrl */)) {
actor.close();
Gtk.main_quit();
}
}

Gtk.init(null);

let win = new Gtk.Window({ title: ARGV[0] });

let scroll = new Gtk.ScrolledWindow();
scroll.set_size_request(640, 640);

let textview = new Gtk.TextView();
textview.set_editable(false);
textview.buffer.text = new TextDecoder().decode(GLib.file_get_contents(ARGV[1])[1]);

scroll.add(textview);
win.add(scroll);

win.connect("delete-event", () => Gtk.main_quit());
win.connect("key-press-event", onKeyPress);

win.show_all();
Gtk.main();
5 changes: 5 additions & 0 deletions apt-updates@zamszowy/files/apt-updates@zamszowy/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"uuid": "apt-updates@zamszowy",
"name": "APT updates notifier",
"description": "Shows icons for pending updates in APT-based systems"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"section1": {
"type": "section",
"description": "Settings"
},
"update-refresh": {
"type": "entry",
"default": "60",
"description": "Minutes to wait before refreshing applet"
},
"hide-applet": {
"type": "switch",
"default": false,
"description": "Hide applet if there are no updates"
},
"different-levels": {
"type": "switch",
"default": false,
"description": "Show different applet icon for different updgradeable packages count"
},
"level-1": {
"type": "entry",
"default": "100",
"description": "Show low level icon when updates count is between 0 and this value ",
"dependency": "different-levels"
},
"level-2": {
"type": "entry",
"default": "200",
"description": "Show medium level icon when updates count is between low level value and this value. Show high level icon if it's higher than this value.",
"dependency": "different-levels"
},
"section2": {
"type": "section",
"description": "Commands to execute in popup menu"
},
"commandUpdate": {
"type": "entry",
"default": "sudo apt update",
"description": "Check for updates:"
},
"commandUpgrade": {
"type": "entry",
"default": "sudo apt -V upgrade",
"description": "Upgrade packages:"
}
}
23 changes: 23 additions & 0 deletions apt-updates@zamszowy/files/apt-updates@zamszowy/updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -eu

DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
readonly DIR

case "$1" in
check)
apt list --upgradable 2>/dev/null | tail -n +2 &> "$DIR"/updates
wc -l <"$DIR"/updates
;;
view)
/usr/bin/cjs "$DIR"/info-window.js "$(wc -l <"$DIR"/updates) updates" "$DIR"/updates
;;
command)
readonly cmd=$2
gnome-terminal --wait -- /bin/bash -c "echo \"Executing $cmd\"; $cmd; echo -en \"\nDone - press enter to exit\"; read"
;;
*)
exit 1
;;
esac
3 changes: 3 additions & 0 deletions apt-updates@zamszowy/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"author": "zamszowy"
}
Binary file added apt-updates@zamszowy/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.