diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 15:07:22 +0000 |
commit | f9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch) | |
tree | ce9e8db2d4e8799780fa72ae8f1953039373e2ee /js/ui/status/remoteAccess.js | |
parent | Initial commit. (diff) | |
download | gnome-shell-upstream.tar.xz gnome-shell-upstream.zip |
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/ui/status/remoteAccess.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/js/ui/status/remoteAccess.js b/js/ui/status/remoteAccess.js new file mode 100644 index 0000000..21f6581 --- /dev/null +++ b/js/ui/status/remoteAccess.js @@ -0,0 +1,97 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +/* exported RemoteAccessApplet */ + +const { GObject, Meta } = imports.gi; + +const PanelMenu = imports.ui.panelMenu; +const PopupMenu = imports.ui.popupMenu; + +var RemoteAccessApplet = GObject.registerClass( +class RemoteAccessApplet extends PanelMenu.SystemIndicator { + _init() { + super._init(); + + let controller = global.backend.get_remote_access_controller(); + + if (!controller) + return; + + this._handles = new Set(); + this._sharedIndicator = null; + this._recordingIndicator = null; + this._menuSection = null; + + controller.connect('new-handle', (o, handle) => { + this._onNewHandle(handle); + }); + } + + _ensureControls() { + if (this._sharedIndicator && this._recordingIndicator) + return; + + this._sharedIndicator = this._addIndicator(); + this._sharedIndicator.icon_name = 'screen-shared-symbolic'; + this._sharedIndicator.add_style_class_name('remote-access-indicator'); + + this._sharedItem = + new PopupMenu.PopupSubMenuMenuItem(_("Screen is Being Shared"), + true); + 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); + } + + _sync() { + if (this._isScreenShared()) { + this._sharedIndicator.visible = true; + this._sharedItem.visible = true; + } else { + this._sharedIndicator.visible = false; + this._sharedItem.visible = false; + } + + this._recordingIndicator.visible = this._isRecording(); + } + + _onStopped(handle) { + this._handles.delete(handle); + this._sync(); + } + + _onNewHandle(handle) { + // 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; + + this._handles.add(handle); + handle.connect('stopped', this._onStopped.bind(this)); + + this._ensureControls(); + this._sync(); + } +}); |