forked from GustavoPeredo/Big-Avatar-Gnome-Shell-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
138 lines (121 loc) · 4.82 KB
/
Copy pathextension.js
File metadata and controls
138 lines (121 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* extension.js
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/* exported init */
// Import nescessary libs
const Main = imports.ui.main;
const Lang = imports.lang;
const Util = imports.misc.util;
const PopupMenu = imports.ui.popupMenu;
const { AccountsService, Clutter, GLib, St } = imports.gi;
const { Avatar } = imports.ui.userWidget;
const Config = imports.misc.config;
const GObject = imports.gi.GObject;
//Import extension preferences
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
//Creates temporary iconMenuItem variable
var iconMenuItem = null;
//Creates some global variables
let shell_Version = Config.PACKAGE_VERSION;
let settings;
function init() {
}
//Run when enabled
function enable() {
//Get user preferences
settings = Convenience.getSettings();
//Connects changing any of the values to the resetPre function
settings.connect('changed::horizontalmode', resetPre);
settings.connect('changed::fontsize', resetPre);
settings.connect('changed::picturesize', resetPre);
//Calls the updateExtensionAppearence function to draw the first icon
updateExtensionAppearence();
}
//Run when disabled
function disable() {
//Disconnects systemMenu
if (this._menuOpenStateChangedId) {
this.systemMenu.menu.disconnect(this._menuOpenStateChangedId);
this._menuOpenStateChangedId = 0;
}
//Destroys iconMenuItem (basically removes the option from the menu)
iconMenuItem.destroy();
settings.run_dispose()
}
//Destroys everything and creates a new one
function resetPre() {
//Disconnects systemMenu
if (this._menuOpenStateChangedId) {
this.systemMenu.menu.disconnect(this._menuOpenStateChangedId);
this._menuOpenStateChangedId = 0;
}
//Destroys iconMenuItem (basically removes the option from the menu)
iconMenuItem.destroy();
updateExtensionAppearence()
}
function updateExtensionAppearence() {
//Creates new PopupMenuItem
this.iconMenuItem = new PopupMenu.PopupMenuItem('');
//Adds a box where we are going to store picture and avatar
this.iconMenuItem.add_child(
new St.BoxLayout({
x_align: Clutter.ActorAlign.CENTER,
x_expand: true,
y_expand: true,
vertical: true,
})
);
//Test if in horizontal mode and change vertical and alignment variables
if (settings.get_boolean('horizontalmode')) {
this.iconMenuItem.actor.get_last_child().set_vertical(!this.iconMenuItem.actor.get_last_child().get_vertical());
this.iconMenuItem.actor.get_last_child().x_align = Clutter.ActorAlign.START;
}
//Adds item to menu
Main.panel.statusArea.aggregateMenu.menu.addMenuItem(this.iconMenuItem, 0);
this.systemMenu = Main.panel.statusArea['aggregateMenu']._system;
//When the popup menu opens do this:
//Check if on compact mode
this._menuOpenStateChangedId = this.systemMenu.menu.connect('open-state-changed', Lang.bind(this,
function(menu, open) {
if (!open)
return;
//Get user avatar and name
var userManager = AccountsService.UserManager.get_default();
var user = userManager.get_user(GLib.get_user_name());
//Get user icon
var avatar = new Avatar(user, {
iconSize: settings.get_int('picturesize'),
});
//Get user name and center it vertically
var nameString = new St.Label ({
text: " " + GLib.get_real_name(),
y_align: Clutter.ActorAlign.CENTER,
x_align: Clutter.ActorAlign.Center
});
avatar.update();
//Remove all created menu itens
this.iconMenuItem.actor.get_last_child().remove_all_children();
//Add the avatar picture
this.iconMenuItem.actor.get_last_child().add_child(avatar.actor);
//Set font size
nameString.style = "font-size: " + settings.get_int('fontsize').toString() + "px; margin: 8px;";
//Add name
this.iconMenuItem.actor.get_last_child().add_child(nameString);
}));
}