summaryrefslogtreecommitdiffstats
path: root/js/dbusServices/extensions/extensionsService.js
blob: d8234d2acb6779189d9abff49725f0858cd7ddba (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported ExtensionsService */

const { Gio, GLib, Shew } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;

const { loadInterfaceXML } = imports.misc.dbusUtils;
const { ExtensionPrefsDialog } = imports.extensionPrefsDialog;
const { ServiceImplementation } = imports.dbusService;

const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions');
const ExtensionsProxy = Gio.DBusProxy.makeProxyWrapper(ExtensionsIface);

var ExtensionsService = class extends ServiceImplementation {
    constructor() {
        super(ExtensionsIface, '/org/gnome/Shell/Extensions');

        this._proxy = new ExtensionsProxy(Gio.DBus.session,
            'org.gnome.Shell', '/org/gnome/Shell');

        this._proxy.connectSignal('ExtensionStateChanged',
            (proxy, sender, params) => {
                this._dbusImpl.emit_signal('ExtensionStateChanged',
                    new GLib.Variant('(sa{sv})', params));
            });

        this._proxy.connect('g-properties-changed', () => {
            this._dbusImpl.emit_property_changed('UserExtensionsEnabled',
                new GLib.Variant('b', this._proxy.UserExtensionsEnabled));
        });
    }

    get ShellVersion() {
        return this._proxy.ShellVersion;
    }

    get UserExtensionsEnabled() {
        return this._proxy.UserExtensionsEnabled;
    }

    set UserExtensionsEnabled(enable) {
        this._proxy.UserExtensionsEnabled = enable;
    }

    async ListExtensionsAsync(params, invocation) {
        try {
            const res = await this._proxy.ListExtensionsAsync(...params);
            invocation.return_value(new GLib.Variant('(a{sa{sv}})', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async GetExtensionInfoAsync(params, invocation) {
        try {
            const res = await this._proxy.GetExtensionInfoAsync(...params);
            invocation.return_value(new GLib.Variant('(a{sv})', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async GetExtensionErrorsAsync(params, invocation) {
        try {
            const res = await this._proxy.GetExtensionErrorsAsync(...params);
            invocation.return_value(new GLib.Variant('(as)', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async InstallRemoteExtensionAsync(params, invocation) {
        try {
            const res = await this._proxy.InstallRemoteExtensionAsync(...params);
            invocation.return_value(new GLib.Variant('(s)', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async UninstallExtensionAsync(params, invocation) {
        try {
            const res = await this._proxy.UninstallExtensionAsync(...params);
            invocation.return_value(new GLib.Variant('(b)', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async EnableExtensionAsync(params, invocation) {
        try {
            const res = await this._proxy.EnableExtensionAsync(...params);
            invocation.return_value(new GLib.Variant('(b)', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async DisableExtensionAsync(params, invocation) {
        try {
            const res = await this._proxy.DisableExtensionAsync(...params);
            invocation.return_value(new GLib.Variant('(b)', res));
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    LaunchExtensionPrefsAsync([uuid], invocation) {
        this.OpenExtensionPrefsAsync([uuid, '', {}], invocation);
    }

    async OpenExtensionPrefsAsync(params, invocation) {
        const [uuid, parentWindow, options] = params;

        try {
            const [serialized] = await this._proxy.GetExtensionInfoAsync(uuid);

            if (this._prefsDialog)
                throw new Error('Already showing a prefs dialog');

            const extension = ExtensionUtils.deserializeExtension(serialized);

            this._prefsDialog = new ExtensionPrefsDialog(extension);
            this._prefsDialog.connect('realize', () => {
                let externalWindow = null;

                if (parentWindow)
                    externalWindow = Shew.ExternalWindow.new_from_handle(parentWindow);

                if (externalWindow)
                    externalWindow.set_parent_of(this._prefsDialog.get_surface());
            });

            if (options.modal)
                this._prefsDialog.modal = options.modal.get_boolean();

            this._prefsDialog.connect('close-request', () => {
                delete this._prefsDialog;
                this.release();
                return false;
            });
            this.hold();

            this._prefsDialog.show();

            invocation.return_value(null);
        } catch (error) {
            this._handleError(invocation, error);
        }
    }

    async CheckForUpdatesAsync(params, invocation) {
        try {
            await this._proxy.CheckForUpdatesAsync(...params);
            invocation.return_value(null);
        } catch (error) {
            this._handleError(invocation, error);
        }
    }
};