-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathextension.js
59 lines (47 loc) · 1.7 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
const Main = imports.ui.main;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const St = imports.gi.St;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Indicator = Me.imports.indicator;
function init(extensionMeta) {
let theme = new Gtk.IconTheme();
theme.set_theme_name(St.Settings.get().gtk_icon_theme);
theme.add_search_path(extensionMeta.path + "/icons");
let cacheDir = GLib.build_filenamev([GLib.get_user_cache_dir(), Me.metadata.uuid]);
GLib.mkdir_with_parents(cacheDir, parseInt("0755", 8));
}
let _indicator;
let _settings;
let _settingsChangedSignalId;
function _updatePanelPosition() {
let panelPosition = _settings.get_string('panel-position');
let container = _indicator.actor.container;
let parent = container.get_parent();
if (parent)
parent.remove_actor(container);
let box;
if (panelPosition == 'left')
box = Main.panel._leftBox;
else if (panelPosition == 'center')
box = Main.panel._centerBox;
else
box = Main.panel._rightBox;
// Avoid positioning the icon on the leftmost side of the panel.
let index = panelPosition == 'left' ? box.get_n_children() : 0;
box.insert_child_at_index(container, index);
}
function enable() {
_indicator = new Indicator.TimezoneIndicator;
_settings = Convenience.getSettings();
_settingsChangedSignalId = _settings.connect('changed::panel-position', _updatePanelPosition);
_updatePanelPosition();
}
function disable() {
_settings.disconnect(_settingsChangedSignalId);
_settings = null;
_indicator.actor.destroy();
_indicator = null;
}