forked from therevoman/gnome-shell-rocketchat-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
71 lines (58 loc) · 1.75 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
'use strict';
var St = imports.gi.St;
var Main = imports.ui.main;
var Gio = imports.gi.Gio;
var ExtensionUtils = imports.misc.extensionUtils;
var Util = imports.misc.util;
var Shell = imports.gi.Shell;
var Me = ExtensionUtils.getCurrentExtension();
var app = Shell.AppSystem.get_default().lookup_app("rocket-chat.desktop");
var snap = false;
if (app === null || app === undefined) {
app = Shell.AppSystem.get_default().lookup_app("rocketchat-desktop_rocketchat-desktop.desktop");
if (app === null || app === undefined) {
var err_msg = "Could not load Rocket Chat Desktop App";
Main.notify(err_msg);
throw new Error(err_msg);
}
snap = true;
}
var text, button;
function _showRocketChat() {
if (app === null) {
throw new Error("Could not find RocketChat! Make sure that the Desktop entry file 'rocketchat.desktop' is available.");
}
if (app === undefined) {
throw new Error("Could not find RocketChat! Make sure that the Desktop entry file 'rocketchat.desktop' is available.");
}
if (app.get_state() === 0) {
if (snap) {
Util.spawn(['/snap/bin/rocketchat-desktop']);
} else {
Util.spawn(['/opt/Rocket.Chat+/rocketchat']);
}
}
if (app.get_state() === 2) {
app.activate();
}
}
function init() {
button = new St.Bin({
style_class: 'panel-button',
reactive: true,
can_focus: true,
x_fill: true,
y_fill: false,
track_hover: true
});
var gicon = Gio.icon_new_for_string(Me.path + "/icon.png");
var icon = new St.Icon({gicon: gicon, icon_size: '20'});
button.set_child(icon);
button.connect('button-press-event', _showRocketChat);
}
function enable() {
Main.panel._rightBox.insert_child_at_index(button, 0);
}
function disable() {
Main.panel._rightBox.remove_child(button);
}