2018-07-20 14:50:50 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported RemoteAccessApplet */
|
2018-07-20 14:50:50 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
const { GObject, Meta } = imports.gi;
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var RemoteAccessApplet = GObject.registerClass(
|
|
|
|
class RemoteAccessApplet extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2018-07-20 14:50:50 +00:00
|
|
|
|
2020-04-21 16:04:56 +00:00
|
|
|
let controller = global.backend.get_remote_access_controller();
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
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();
|
2020-04-21 16:06:06 +00:00
|
|
|
this._sharedIndicator = null;
|
|
|
|
this._recordingIndicator = null;
|
2018-07-20 14:50:50 +00:00
|
|
|
this._menuSection = null;
|
|
|
|
|
2019-08-20 00:20:08 +00:00
|
|
|
controller.connect('new-handle', (o, handle) => {
|
2018-07-20 14:50:50 +00:00
|
|
|
this._onNewHandle(handle);
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
_ensureControls() {
|
2020-04-21 16:06:06 +00:00
|
|
|
if (this._sharedIndicator && this._recordingIndicator)
|
2018-07-20 14:50:50 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-21 16:06:06 +00:00
|
|
|
this._sharedIndicator = this._addIndicator();
|
|
|
|
this._sharedIndicator.icon_name = 'screen-shared-symbolic';
|
|
|
|
this._sharedIndicator.add_style_class_name('remote-access-indicator');
|
|
|
|
|
|
|
|
this._sharedItem =
|
2018-07-20 14:50:50 +00:00
|
|
|
new PopupMenu.PopupSubMenuMenuItem(_("Screen is Being Shared"),
|
|
|
|
true);
|
2020-04-21 16:06:06 +00:00
|
|
|
this._sharedItem.menu.addAction(_("Turn off"),
|
|
|
|
() => {
|
|
|
|
for (let handle of this._handles) {
|
|
|
|
if (!handle.is_recording)
|
|
|
|
handle.stop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._sharedItem.icon.icon_name = 'screen-shared-symbolic';
|
|
|
|
this.menu.addMenuItem(this._sharedItem);
|
|
|
|
|
|
|
|
this._recordingIndicator = this._addIndicator();
|
|
|
|
this._recordingIndicator.icon_name = 'media-record-symbolic';
|
|
|
|
this._recordingIndicator.add_style_class_name('screencast-indicator');
|
|
|
|
}
|
|
|
|
|
|
|
|
_isScreenShared() {
|
|
|
|
return [...this._handles].some(handle => !handle.is_recording);
|
|
|
|
}
|
|
|
|
|
|
|
|
_isRecording() {
|
|
|
|
return [...this._handles].some(handle => handle.is_recording);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
_sync() {
|
2020-04-21 16:06:06 +00:00
|
|
|
if (this._isScreenShared()) {
|
|
|
|
this._sharedIndicator.visible = true;
|
|
|
|
this._sharedItem.visible = true;
|
2018-07-20 14:50:50 +00:00
|
|
|
} else {
|
2020-04-21 16:06:06 +00:00
|
|
|
this._sharedIndicator.visible = false;
|
|
|
|
this._sharedItem.visible = false;
|
2018-07-20 14:50:50 +00:00
|
|
|
}
|
2020-04-21 16:06:06 +00:00
|
|
|
|
|
|
|
this._recordingIndicator.visible = this._isRecording();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
_onStopped(handle) {
|
|
|
|
this._handles.delete(handle);
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-20 14:50:50 +00:00
|
|
|
|
|
|
|
_onNewHandle(handle) {
|
|
|
|
this._handles.add(handle);
|
|
|
|
handle.connect('stopped', this._onStopped.bind(this));
|
|
|
|
|
2020-04-21 16:06:06 +00:00
|
|
|
this._ensureControls();
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|