Skip to content

Commit

Permalink
#56
Browse files Browse the repository at this point in the history
Now if there is no avatar set, there will be a fallback, and also the icon will be correctly shown if a stock icon is set.
  • Loading branch information
Aylur committed May 26, 2023
1 parent 5e8d9e2 commit 69d51b3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
10 changes: 4 additions & 6 deletions widgets@aylur/extensions/dateMenuTweaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const DateMenu = Main.panel.statusArea.dateMenu;
const Media = Me.imports.shared.media;
const { Avatar } = Me.imports.shared.userWidget;
const SystemLevels = Me.imports.shared.systemLevels;

const _ = imports.gettext.domain(Me.metadata.uuid).gettext;
Expand Down Expand Up @@ -79,13 +80,10 @@ class CustomMenu extends St.BoxLayout{
let userBtn = new St.Button({
x_align: Clutter.ActorAlign.CENTER,
style_class: 'events-button',
child: new St.Widget({
y_expand: true,
x_expand: true,
style: 'background-image: url("/var/lib/AccountsService/icons/'+ GLib.get_user_name() +'"); background-size: cover;',
})
child: Avatar({ fallbackSize: 82 })
});
userBtn.connect('clicked', () => Shell.AppSystem.get_default().lookup_app('gnome-user-accounts-panel.desktop').activate());
userBtn.connect('clicked', () => Shell.AppSystem.get_default()
.lookup_app('gnome-user-accounts-panel.desktop').activate());

let userName = new St.Label({
x_align: Clutter.ActorAlign.CENTER,
Expand Down
12 changes: 5 additions & 7 deletions widgets@aylur/extensions/quickSettingsTweaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Media = Me.imports.shared.media;
const { NotificationList } = Me.imports.shared.notificationList;
const SystemLevels = Me.imports.shared.systemLevels;
const { VolumeMixer } = Me.imports.shared.volumeMixer;
const { Avatar } = Me.imports.shared.userWidget;

const { loadInterfaceXML } = imports.misc.fileUtils;
const DisplayDeviceInterface = loadInterfaceXML('org.freedesktop.UPower.Device');
Expand All @@ -27,13 +28,10 @@ class QuickSettingsSystem extends St.BoxLayout{
() => Shell.AppSystem.get_default().lookup_app('gnome-user-accounts-panel.desktop').activate()
);
userBtn.style_class = 'icon-button user-btn';
userBtn.set_child(new St.Widget({
y_expand: true,
style_class: 'user-icon icon-button',
style: `
background-image: url("/var/lib/AccountsService/icons/${GLib.get_user_name()}");
background-size: cover;`,
}));
userBtn.set_child(Avatar({
styleClass: 'user-icon icon-button',
fallbackSize: 42,
}))

let greetBox = new St.BoxLayout({
vertical: true,
Expand Down
12 changes: 5 additions & 7 deletions widgets@aylur/shared/dashWidgets.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const { GObject, St, Clutter, GLib, Gio, GnomeDesktop, Shell } = imports.gi;
const { GObject, St, Clutter, GLib, Gio, GnomeDesktop, Shell, AccountsService } = imports.gi;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const Util = imports.misc.util;
const AppFavorites = imports.ui.appFavorites;
const Dash = imports.ui.dash;
const { Avatar } = Me.imports.shared.userWidget;
const SystemActions = imports.misc.systemActions;
const Media = Me.imports.shared.media;
const SystemLevels = Me.imports.shared.systemLevels;
Expand Down Expand Up @@ -140,12 +141,9 @@ class UserWidget extends DashWidget{
x_expand: true,
y_expand: true,
style_class: 'user-icon-button button',
child: new St.Widget({
style: `
background-image: url("/var/lib/AccountsService/icons/${GLib.get_user_name()}");
background-size: cover;
border-radius: ${this._settings.get_int(`dash-user-icon-roundness`)}px;
`,
child: Avatar({
radius: this._settings.get_int(`dash-user-icon-roundness`),
fallbackSize: this._settings.get_int(`dash-user-icon-width`)*0.7,
}),
style: `
border-radius: ${this._settings.get_int(`dash-user-icon-roundness`)}px;
Expand Down
25 changes: 25 additions & 0 deletions widgets@aylur/shared/userWidget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { GLib, St, AccountsService } = imports.gi;

var Avatar = ({ radius, fallbackSize, styleClass } = {}) => {
let icon = AccountsService.UserManager.get_default().list_users()
.filter(user => user.user_name === GLib.get_user_name())[0].icon_file;

let avatar = new St.Widget({
x_expand: true,
y_expand: true,
style_class: styleClass || '',
style: `
background-image: url("${icon}");
background-size: cover;
${radius ? `border-radius: ${radius}px;` : ''}
`,
});

let fallback = new St.Icon({
icon_name: 'avatar-default-symbolic',
icon_size: fallbackSize || 64,
});

return icon ? avatar : fallback;
}

0 comments on commit 69d51b3

Please sign in to comment.