Skip to content

Commit

Permalink
show real name option #58 #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Jun 8, 2023
1 parent c636998 commit 8ee990a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 80 deletions.
41 changes: 10 additions & 31 deletions widgets@aylur/extensions/dateMenuTweaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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 {Avatar, Greetings, UserName} = Me.imports.shared.userWidget;
const SystemLevels = Me.imports.shared.systemLevels;

const _ = imports.gettext.domain(Me.metadata.uuid).gettext;
Expand Down Expand Up @@ -89,24 +89,19 @@ class CustomMenu extends St.BoxLayout {
userBtn.connect('clicked', () => Shell.AppSystem.get_default()
.lookup_app('gnome-user-accounts-panel.desktop').activate());

const userName = new St.Label({
x_align: Clutter.ActorAlign.CENTER,
text: GLib.get_user_name(),
style_class: 'datemenu-user-name',
});

this.greet = new St.Label({
x_align: Clutter.ActorAlign.CENTER,
style_class: 'datemenu-greet',
});

const userBox = new St.BoxLayout({
vertical: true,
style_class: 'datemenu-user',
});
userBox.add_child(userBtn);
userBox.add_child(userName);
userBox.add_child(this.greet);
userBox.add_child(new UserName(settings, 'date-menu', {
x_align: Clutter.ActorAlign.CENTER,
style_class: 'datemenu-user-name',
}));
userBox.add_child(new Greetings({
x_align: Clutter.ActorAlign.CENTER,
style_class: 'datemenu-greet',
}));

// calendar
const calendarBox = new St.Bin({
Expand Down Expand Up @@ -156,7 +151,6 @@ class CustomMenu extends St.BoxLayout {
const now = new Date();
calendar.setDate(now);
eventsItem.setDate(now);
this._setGreet();
}, this);

Main.layoutManager.connectObject('monitors-changed', () => this.tweaks.reload(), this);
Expand All @@ -183,22 +177,6 @@ class CustomMenu extends St.BoxLayout {
this.levels.startTimeout();
}

_setGreet() {
const time = new Date();
const hour = time.getHours();

let greet = _('Good Evening!');
if (hour > 6)
greet = _('Good Morning!');

if (hour > 12)
greet = _('Good Afternoon!');
if (hour > 18)
greet = _('Good Evening!');

this.greet.text = greet;
}

_buildPlayerUI() {
const elements = this.player;

Expand Down Expand Up @@ -267,6 +245,7 @@ var Extension = class Extension {
'changed::date-menu-show-weather', this._reload.bind(this),
'changed::date-menu-show-media', this._reload.bind(this),
'changed::date-menu-show-system-levels', this._reload.bind(this),
'changed::date-menu-user-real-name', this._reload.bind(this),
'changed::date-menu-date-format', () => {
this._dateFormat = this._settings.get_string('date-menu-date-format');
this._updateClock();
Expand Down
33 changes: 9 additions & 24 deletions widgets@aylur/extensions/quickSettingsTweaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 {Avatar, UserName, Greetings} = Me.imports.shared.userWidget;

const {loadInterfaceXML} = imports.misc.fileUtils;
const DisplayDeviceInterface = loadInterfaceXML('org.freedesktop.UPower.Device');
Expand All @@ -23,12 +23,12 @@ const NIGHT_LIGHT_MIN = 1400;

const QuickSettingsSystem = GObject.registerClass(
class QuickSettingsSystem extends St.BoxLayout {
_init() {
_init(settings) {
super._init({style_class: 'container'});

const userBtn = this._addBtn('',
() => Shell.AppSystem.get_default().lookup_app('gnome-user-accounts-panel.desktop').activate()
);
const userBtn = this._addBtn('', () => {
Shell.AppSystem.get_default().lookup_app('gnome-user-accounts-panel.desktop').activate();
});
userBtn.style_class = 'icon-button user-btn';
userBtn.set_child(Avatar({
styleClass: 'user-icon icon-button',
Expand All @@ -39,8 +39,8 @@ class QuickSettingsSystem extends St.BoxLayout {
vertical: true,
y_align: Clutter.ActorAlign.CENTER,
});
greetBox.add_child(new St.Label({text: GLib.get_user_name()}));
greetBox.add_child(new St.Label({text: this._greet()}));
greetBox.add_child(new UserName(settings, 'quick-settings'));
greetBox.add_child(new Greetings());

this.add_child(userBtn);
this.add_child(greetBox);
Expand All @@ -55,22 +55,6 @@ class QuickSettingsSystem extends St.BoxLayout {
() => SystemActions.getDefault().activateAction('power-off')));
}

_greet() {
const time = new Date();
const hour = time.getHours();

let greet = _('Good Evening!');
if (hour > 6)
greet = _('Good Morning!');

if (hour > 12)
greet = _('Good Afternoon!');
if (hour > 18)
greet = _('Good Evening!');

return greet;
}

_addBtn(iconName, callback) {
const btn = new St.Button({
y_align: Clutter.ActorAlign.CENTER,
Expand Down Expand Up @@ -637,7 +621,7 @@ class QuickSettingsTweaks {
sliders.add_child(this.toggles.brightness);
sliders.add_child(new NightLightSlider());

this.normalBox.add_child(new QuickSettingsSystem());
this.normalBox.add_child(new QuickSettingsSystem(this.settings));
this.normalBox.add_child(sliders);
this.normalBox.add_child(new SmallToggleRow(false));
this.normalBox.add_child(this.toggles.grid);
Expand Down Expand Up @@ -819,6 +803,7 @@ var Extension = class Extension {
'changed::quick-settings-show-airplane', () => this.tweaks.reload(),
'changed::quick-settings-show-rotate', () => this.tweaks.reload(),
'changed::quick-settings-show-bg-apps', () => this.tweaks.reload(),
'changed::quick-settings-user-real-name', () => this.tweaks.reload(),
this
);

Expand Down
8 changes: 6 additions & 2 deletions widgets@aylur/pref/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class DashBoardPage extends SubPage {
user.add_row(new SpinButtonRow(_('Icon Width'), settings, 'dash-user-icon-width', 10, 500, 2));
user.add_row(new SpinButtonRow(_('Icon Height'), settings, 'dash-user-icon-height', 10, 500, 2));
user.add_row(new SwitchRow(_('Vertical'), settings, 'dash-user-vertical'));
user.add_row(new SwitchRow(_('Show Real Name'), settings, 'dash-user-real-name'));

const levels = this._makeExpander(_('System Levels'), 'levels', settings);
levels.add_row(new SwitchRow(_('Vertical'), settings, 'dash-levels-vertical'));
Expand Down Expand Up @@ -243,7 +244,9 @@ class DateMenuTweakPage extends SubPage {
this.add(customMenuGroup);

const expander = new ExpanderRow(_('Enable Custom Menu'), settings, 'date-menu-custom-menu');
expander.add_row(new SwitchRow(_('Show User Icon'), settings, 'date-menu-show-user'));
const userExpander = new ExpanderRow(_('Show User Icon'), settings, 'date-menu-show-user');
userExpander.add_row(new SwitchRow(_('Show Real Name'), settings, 'date-menu-user-real-name'));
expander.add_row(userExpander);
expander.add_row(new SwitchRow(_('Show Events'), settings, 'date-menu-show-events'));
expander.add_row(new SwitchRow(_('Show Clocks'), settings, 'date-menu-show-clocks'));
expander.add_row(new SwitchRow(_('Show Weather'), settings, 'date-menu-show-weather'));
Expand Down Expand Up @@ -313,7 +316,7 @@ class DateMenuTweakPage extends SubPage {
var DynamicPanelPage = GObject.registerClass(
class DynamicPanelPage extends SubPage {
_init(settings) {
super._init(_('Dynaimc Panel'), settings);
super._init(_('Dynamic Panel'), settings);

const group = new Adw.PreferencesGroup();
this.add(group);
Expand Down Expand Up @@ -591,6 +594,7 @@ class QuickSettingsTweaksPage extends SubPage {
group.add(new SpinButtonRow(_('Menu Width'), settings, 'quick-settings-menu-width', 250, 500, 5));
group.add(new DropDownRow(_('Style'), settings, 'quick-settings-style', [_('Stock'), _('Normal'), _('Compact'), _('Separated')]));
group.add(new SwitchRow(_('Adjust Roundness'), settings, 'quick-settings-adjust-roundness'));
group.add(new SwitchRow(_('Show Real Name'), settings, 'quick-settings-user-real-name', _('On Normal Style')));
group.add(new SwitchRow(_('Show Notifications'), settings, 'quick-settings-show-notifications'));

const levelsExpander = new ExpanderRow(_('Show System Levels'), settings, 'quick-settings-show-system-levels');
Expand Down
2 changes: 1 addition & 1 deletion widgets@aylur/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AboutPage extends Adw.PreferencesPage {
});

const versionGroup = new Adw.PreferencesGroup();
const versionRow = new Adw.ActionRow({title: _('Verison:')});
const versionRow = new Adw.ActionRow({title: _('Version:')});
versionRow.add_suffix(new Gtk.Label({valign: Gtk.Align.CENTER, label: `${Me.metadata.version}`}));
versionGroup.add(versionRow);
this.add(versionGroup);
Expand Down
Binary file modified widgets@aylur/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<key name="dash-user-icon-roundness" type="i"> <default>13</default></key>
<key name="dash-user-icon-width" type="i"> <default>100</default></key>
<key name="dash-user-icon-height" type="i"> <default>100</default></key>
<key name="dash-user-real-name" type="b"> <default>false</default></key>

<!-- date-menu-tweak -->
<key name="date-menu-hide-stock-mpris" type="b"> <default>false</default></key>
Expand All @@ -207,6 +208,7 @@
<key name="date-menu-show-media" type="b"> <default>true</default></key>
<key name="date-menu-show-system-levels" type="b"> <default>true</default></key>
<key name="date-menu-show-user" type="b"> <default>true</default></key>
<key name="date-menu-user-real-name" type="b"> <default>false</default></key>
<key name="date-menu-levels-show-battery" type="b"> <default>true</default></key>
<key name="date-menu-levels-show-storage" type="b"> <default>true</default></key>
<key name="date-menu-levels-show-cpu" type="b"> <default>true</default></key>
Expand Down Expand Up @@ -330,6 +332,7 @@
<key name="quick-settings-show-airplane" type="b"> <default>false</default></key>
<key name="quick-settings-show-rotate" type="b"> <default>true</default></key>
<key name="quick-settings-show-bg-apps" type="b"> <default>true</default></key>
<key name="quick-settings-user-real-name" type="b"> <default>false</default></key>

</schema>
</schemalist>
24 changes: 4 additions & 20 deletions widgets@aylur/shared/dashWidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 {Avatar, Greetings, UserName} = 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 @@ -124,6 +124,7 @@ class UserWidget extends DashWidget {
this._connect('icon-width');
this._connect('icon-height');
this._connect('vertical');
this._connect('real-name');
this._sync();
}

Expand Down Expand Up @@ -165,35 +166,18 @@ class UserWidget extends DashWidget {
x_expand: true,
y_expand: true,
});
textBox.add_child(new St.Label({
text: GLib.get_user_name(),
textBox.add_child(new UserName(this._settings, 'dash', {
y_align: Clutter.ActorAlign.END,
x_align: this.vertical ? Clutter.ActorAlign.CENTER : Clutter.ActorAlign.START,
}));
textBox.add_child(new St.Label({
text: this._greet(),
textBox.add_child(new Greetings({
y_align: Clutter.ActorAlign.START,
x_align: this.vertical ? Clutter.ActorAlign.CENTER : Clutter.ActorAlign.START,
}));

this.add_child(userBtn);
this.add_child(textBox);
}

_greet() {
const time = new Date();
const hour = time.getHours();

let greet = _('Good Evening!');
if (hour > 6)
greet = _('Good Morning!');
if (hour > 12)
greet = _('Good Afternoon!');
if (hour > 18)
greet = _('Good Evening!');

return greet;
}
});

var LevelsWidget = GObject.registerClass(
Expand Down
42 changes: 40 additions & 2 deletions widgets@aylur/shared/userWidget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* exported Avatar */
/* exported Avatar, UserName, Greetings */

const {GLib, St, AccountsService} = imports.gi;
const {GLib, St, AccountsService, GObject} = imports.gi;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const _ = imports.gettext.domain(Me.metadata.uuid).gettext;

var Avatar = ({radius, fallbackSize, styleClass} = {}) => {
const icon = AccountsService.UserManager.get_default().list_users()
Expand All @@ -25,3 +27,39 @@ var Avatar = ({radius, fallbackSize, styleClass} = {}) => {
return icon ? avatar : fallback;
};

var UserName = GObject.registerClass(
class UserName extends St.Label {
constructor(settings, name, props) {
super(props);

settings.get_boolean(`${name}-user-real-name`)
? this.text = GLib.get_real_name()
: this.text = GLib.get_user_name();
}
});

var Greetings = GObject.registerClass(
class Greetings extends St.Label {
constructor(props) {
super(props);

const id = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 60, this._greet.bind(this));
this.connect('destroy', () => GLib.source_remove(id));
this._greet();
}

_greet() {
const time = new Date();
const hour = time.getHours();

let greet = _('Good Evening!');
if (hour > 6)
greet = _('Good Morning!');
if (hour > 12)
greet = _('Good Afternoon!');
if (hour > 18)
greet = _('Good Evening!');

this.text = greet;
}
});

0 comments on commit 8ee990a

Please sign in to comment.