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
|
|
|
|
2021-08-17 07:58:23 +00:00
|
|
|
const Main = imports.ui.main;
|
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;
|
|
|
|
|
|
|
|
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');
|
2021-08-17 07:58:23 +00:00
|
|
|
|
|
|
|
this._recordingItem = new PopupMenu.PopupSubMenuMenuItem(
|
|
|
|
_('Screen Recording in Progress'),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
this._recordingItem.menu.addAction(_('Stop'),
|
|
|
|
() => Main.screenshotUI.stopScreencast());
|
|
|
|
this._recordingItem.icon.icon_name = 'media-record-symbolic';
|
|
|
|
this.menu.addMenuItem(this._recordingItem);
|
2020-04-21 16:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_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();
|
2021-08-17 07:58:23 +00:00
|
|
|
this._recordingItem.visible = Main.screenshotUI.screencast_in_progress;
|
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) {
|
2020-10-13 14:28:51 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// We still want to show screen recordings though, to indicate when
|
|
|
|
// the built in screen recorder is active, no matter the session type.
|
|
|
|
if (!Meta.is_wayland_compositor() && !handle.is_recording)
|
|
|
|
return;
|
|
|
|
|
2018-07-20 14:50:50 +00:00
|
|
|
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
|
|
|
});
|