-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
82 lines (60 loc) · 2.4 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
'use strict';
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const St = imports.gi.St;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const Config = imports.misc.config;
const SHELL_MINOR = parseInt(Config.PACKAGE_VERSION.split('.')[1]);
const Util = imports.misc.util;
var ExampleIndicator = class ExampleIndicator extends PanelMenu.Button {
_init() {
super._init(0.0, `${Me.metadata.name} Indicator`, false);
this._icon = new St.Icon({
style_class: 'system-status-icon'
});
this._icon.gicon = Gio.icon_new_for_string(`${Me.path}/icons/moon-dark.png`);
this.actor.add_child(this._icon);
this.menu.addAction('Enable Dark Mode', this.enableDarkMode, null);
this.menu.addAction('Disable Dark Mode', this.disableDarkMode, null);
}
enableDarkMode() {
Util.spawn(['/bin/bash', '-c', "gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'"]);
}
disableDarkMode() {
Util.spawn(['/bin/bash', '-c', "gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'"]);
}
}
// Compatibility with gnome-shell >= 3.32
if (SHELL_MINOR > 30) {
ExampleIndicator = GObject.registerClass(
{GTypeName: 'ExampleIndicator'},
ExampleIndicator
);
}
// We're going to declare `indicator` in the scope of the whole script so it can
// be accessed in both `enable()` and `disable()`
var indicator = null;
function init() {
log(`initializing ${Me.metadata.name} version ${Me.metadata.version}`);
}
function enable() {
log(`enabling ${Me.metadata.name} version ${Me.metadata.version}`);
indicator = new ExampleIndicator();
// The `main` import is an example of file that is mostly live instances of
// objects, rather than reusable code. `Main.panel` is the actual panel you
// see at the top of the screen.
Main.panel.addToStatusArea(`${Me.metadata.name} Indicator`, indicator);
}
function disable() {
log(`disabling ${Me.metadata.name} version ${Me.metadata.version}`);
// REMINDER: It's required for extensions to clean up after themselves when
// they are disabled. This is required for approval during review!
if (indicator !== null) {
indicator.destroy();
indicator = null;
}
}