Skip to content

Commit

Permalink
user applet: Allow to display the profile picture on the panel (#12149)
Browse files Browse the repository at this point in the history
* feat: Allow to display the profile picture on the panel

* refactor: Move setting bind to the most adequate place

* chore: User better text for consistency

* chore: Fallback to the default img if user is not loaded yet

* refactor: Remove unnecessary bind use
  • Loading branch information
anaximeno committed May 8, 2024
1 parent b6661f6 commit f07ec24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 21 additions & 2 deletions files/usr/share/cinnamon/applets/user@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Settings = imports.ui.settings;
const UserWidget = imports.ui.userWidget;

const DIALOG_ICON_SIZE = 64;
const USER_DEFAULT_IMG_PATH = "/usr/share/cinnamon/faces/user-generic.png";

class CinnamonUserApplet extends Applet.TextIconApplet {
constructor(orientation, panel_height, instance_id) {
Expand All @@ -23,8 +24,6 @@ class CinnamonUserApplet extends Applet.TextIconApplet {
this._screenSaverProxy = new ScreenSaver.ScreenSaverProxy();
this.settings = new Settings.AppletSettings(this, "user@cinnamon.org", instance_id);

this.set_applet_icon_symbolic_name("avatar-default");

this.menuManager = new PopupMenu.PopupMenuManager(this);
this.menu = new Applet.AppletPopupMenu(this, orientation);
this.menuManager.addMenu(this.menu);
Expand All @@ -40,6 +39,7 @@ class CinnamonUserApplet extends Applet.TextIconApplet {
this._userIcon = new UserWidget.Avatar(this._user, { iconSize: DIALOG_ICON_SIZE });

this.settings.bind("display-name", "disp_name", this._updateLabel);
this.settings.bind("display-image", "display_image", this._setIcon);

userBox.connect('button-press-event', Lang.bind(this, function() {
this.menu.toggle();
Expand Down Expand Up @@ -150,6 +150,7 @@ class CinnamonUserApplet extends Applet.TextIconApplet {
}

_onUserChanged() {
this._setIcon();
if (this._user.is_loaded) {
this.set_applet_tooltip(this._user.get_real_name());
this.userLabel.set_text (this._user.get_real_name());
Expand All @@ -161,6 +162,24 @@ class CinnamonUserApplet extends Applet.TextIconApplet {
}
}

_setIcon() {
if (this.display_image) {
if (this._user && this._user.is_loaded) {
let iconFileName = this._user.get_icon_file();
if (GLib.file_test(iconFileName, GLib.FileTest.EXISTS)) {

Check failure on line 169 in files/usr/share/cinnamon/applets/user@cinnamon.org/applet.js

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

FileTest ==> file test
this.set_applet_icon_path(iconFileName);
return;
}
}
if (GLib.file_test(USER_DEFAULT_IMG_PATH, GLib.FileTest.EXISTS)) {

Check failure on line 174 in files/usr/share/cinnamon/applets/user@cinnamon.org/applet.js

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

FileTest ==> file test
this.set_applet_icon_path(USER_DEFAULT_IMG_PATH);
return;
}
}

this.set_applet_icon_symbolic_name("avatar-default");
}

on_applet_removed_from_panel() {
this.settings.finalize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"type" : "switch",
"default" : false,
"description": "Display user name on panel"
},
"display-image" : {
"type" : "switch",
"default" : false,
"description": "Display the user image on the panel"
}
}

0 comments on commit f07ec24

Please sign in to comment.