2018-07-20 10:50:50 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported RemoteAccessApplet */
|
2018-07-20 10:50:50 -04:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
const { GObject, Meta } = imports.gi;
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
var RemoteAccessApplet = GObject.registerClass({
|
|
|
|
GTypeName: 'RemoteAccess_Indicator'
|
|
|
|
}, class RemoteAccessApplet extends PanelMenu.SystemIndicator {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
let backend = Meta.get_backend();
|
|
|
|
let controller = backend.get_remote_access_controller();
|
|
|
|
|
|
|
|
if (!controller)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We can't possibly know about all types of screen sharing on X11, so
|
|
|
|
// showing these controls on X11 might give a false sense of security.
|
|
|
|
// Thus, only enable these controls when using Wayland, where we are
|
|
|
|
// in control of sharing.
|
|
|
|
if (!Meta.is_wayland_compositor())
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._handles = new Set();
|
|
|
|
this._indicator = null;
|
|
|
|
this._menuSection = null;
|
|
|
|
|
|
|
|
controller.connect('new-handle', (controller, handle) => {
|
|
|
|
this._onNewHandle(handle);
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
_ensureControls() {
|
|
|
|
if (this._indicator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'screen-shared-symbolic';
|
2018-07-27 12:07:52 -04:00
|
|
|
this._indicator.add_style_class_name('remote-access-indicator');
|
2018-07-20 10:50:50 -04:00
|
|
|
this._item =
|
|
|
|
new PopupMenu.PopupSubMenuMenuItem(_("Screen is Being Shared"),
|
|
|
|
true);
|
|
|
|
this._item.menu.addAction(_("Turn off"),
|
|
|
|
() => {
|
|
|
|
for (let handle of this._handles)
|
2019-01-29 14:36:54 -05:00
|
|
|
handle.stop();
|
2018-07-20 10:50:50 -04:00
|
|
|
});
|
|
|
|
this._item.icon.icon_name = 'screen-shared-symbolic';
|
|
|
|
this.menu.addMenuItem(this._item);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
_sync() {
|
|
|
|
if (this._handles.size == 0) {
|
|
|
|
this._indicator.visible = false;
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.visible = false;
|
2018-07-20 10:50:50 -04:00
|
|
|
} else {
|
|
|
|
this._indicator.visible = true;
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.visible = true;
|
2018-07-20 10:50:50 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
_onStopped(handle) {
|
|
|
|
this._handles.delete(handle);
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2018-07-20 10:50:50 -04:00
|
|
|
|
|
|
|
_onNewHandle(handle) {
|
|
|
|
this._handles.add(handle);
|
|
|
|
handle.connect('stopped', this._onStopped.bind(this));
|
|
|
|
|
|
|
|
if (this._handles.size == 1) {
|
|
|
|
this._ensureControls();
|
|
|
|
this._sync();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|