-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextension.js
89 lines (78 loc) · 2.65 KB
/
extension.js
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
const Main = imports.ui.main;
const Lang = imports.lang;
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;
const Util = imports.misc.util;
var iconMenuItem = null;
let shell_Version = Config.PACKAGE_VERSION;
function init() {
}
function enable() {
this.iconMenuItem = new UserIconMenuItem();
Main.panel.statusArea.aggregateMenu.menu.addMenuItem(this.iconMenuItem,0);
this.systemMenu = Main.panel.statusArea['aggregateMenu']._system;
this._menuOpenStateChangedId = this.systemMenu.menu.connect('open-state-changed', Lang.bind(this,
function(menu, open) {
if (!open)
return;
var userManager = AccountsService.UserManager.get_default();
var user = userManager.get_user(GLib.get_user_name());
var avatar = new Avatar(user, {
iconSize: 128
});
avatar.update();
this.iconMenuItem.actor.get_last_child().remove_all_children();
this.iconMenuItem.actor.get_last_child().add_child(avatar.actor);
if ( shell_Version < '3.36' ) {
this.systemMenu.menu.box.get_child_at_index(0).get_child_at_index(1).set_icon_name('avatar-default-symbolic');
}
}));
}
function openUserAccount() {
Util.spawn(['/bin/bash', '-c', "gnome-control-center user-accounts"]);
}
function disable() {
if (this._menuOpenStateChangedId) {
this.systemMenu.menu.disconnect(this._menuOpenStateChangedId);
this._menuOpenStateChangedId = 0;
}
iconMenuItem.destroy();
}
if (shell_Version < '3.36') {
var UserIconMenuItem = class UserIconMenuItem extends PopupMenu.PopupBaseMenuItem {
constructor() {
super({
reactive: false
});
super._init();
this.actor.connect('button-press-event', openUserAccount);
var box = new St.BoxLayout({
x_align: Clutter.ActorAlign.CENTER,
});
this.actor.add(box, {
expand: true
});
}
}
} else {
var UserIconMenuItem = GObject.registerClass(
{
GTypeName: 'UserIconMenuItem'
},
class UserIconMenuItem extends PopupMenu.PopupBaseMenuItem {
_init() {
super._init();
this.actor.connect('button-press-event', openUserAccount);
var box = new St.BoxLayout({
x_align: Clutter.ActorAlign.CENTER,
});
this.actor.add(box, {
expand: true
});
}
}
);
}