Skip to content

Commit

Permalink
Make auto-resume of paused media optional
Browse files Browse the repository at this point in the history
Add a new Telephony preference, 'after-unpause', default true.
(New UI in the preferences allows it to be switched on/off.)
When it's set to false, exiting the ringing and talking states
will still restore volume levels (if configured), but will leave
the media player(s) paused so the user can resume manually.
  • Loading branch information
ferdnyc committed Mar 30, 2022
1 parent a126eef commit fa8f2ad
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 7 deletions.
4 changes: 3 additions & 1 deletion data/org.gnome.Shell.Extensions.GSConnect.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
<key name="talking-pause" type="b">
<default>true</default>
</key>
<key name="after-unpause" type="b">
<default>true</default>
</key>
</schema>
</schemalist>

96 changes: 96 additions & 0 deletions data/ui/preferences-device-panel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="margin_bottom">32</property>
<child>
<object class="GtkListBox" id="talking-list">
<property name="visible">True</property>
Expand Down Expand Up @@ -1756,12 +1757,107 @@
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="after-list-label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="margin-bottom">12</property>
<property name="label" translatable="yes">After Calls</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label-xalign">0</property>
<child>
<object class="GtkListBox" id="after-list">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="selection-mode">none</property>
<signal name="keynav-failed" handler="_onKeynavFailed" swapped="no"/>
<signal name="row-activated" handler="_onToggleRowActivated" swapped="no"/>
<child>
<object class="GtkListBoxRow" id="after-unpause-row">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="height-request">56</property>
<property name="selectable">False</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="after-unpause-label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Resume Paused Media</property>
<accessibility>
<relation type="label-for" target="after-unpause-row"/>
<relation type="label-for" target="after-unpause"/>
</accessibility>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="after-unpause">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">center</property>
<property name="action-name">settings.after-unpause</property>
<accessibility>
<relation type="controlled-by" target="after-unpause-row"/>
<relation type="labelled-by" target="after-unpause-label"/>
</accessibility>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
</child>

</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
6 changes: 6 additions & 0 deletions src/preferences/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ var Panel = GObject.registerClass({
// Telephony
'telephony', 'telephony-page',
'ringing-list', 'ringing-volume', 'talking-list', 'talking-volume',
'after-list',

// Shortcuts
'shortcuts-page',
Expand Down Expand Up @@ -480,6 +481,7 @@ var Panel = GObject.registerClass({
this.actions.add_action(settings.create_action('talking-volume'));
this.actions.add_action(settings.create_action('talking-pause'));
this.actions.add_action(settings.create_action('talking-microphone'));
this.actions.add_action(settings.create_action('after-unpause'));

// Pair Actions
const encryption_info = new Gio.SimpleAction({name: 'encryption-info'});
Expand Down Expand Up @@ -899,8 +901,12 @@ var Panel = GObject.registerClass({
this.ringing_list.next = this.talking_list;
this.talking_list.prev = this.ringing_list;

this.talking_list.next = this.after_list;
this.after_list.prev = this.talking_list;

this.ringing_list.set_header_func(rowSeparators);
this.talking_list.set_header_func(rowSeparators);
this.after_list.set_header_func(rowSeparators);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/service/components/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ var Manager = GObject.registerClass({
if (player.PlaybackStatus === 'Playing' && player.CanPause) {
player.Pause();
this._paused.set(name, player);
debug(`Paused ${name}`);
}
}
}
Expand All @@ -1000,14 +1001,22 @@ var Manager = GObject.registerClass({
* A convenience function for restarting all players paused with pauseAll().
*/
unpauseAll() {
for (const player of this._paused.values()) {
if (player.PlaybackStatus === 'Paused' && player.CanPlay)
for (const [name, player] of this._paused) {
if (player.PlaybackStatus === 'Paused' && player.CanPlay) {
player.Play();
debug(`Unpaused ${name}`);
} else {
debug(`Cannot unpause ${name}, skipping`);
}
}

this._paused.clear();
}

clearPaused() {
this._paused.clear();
}

destroy() {
if (this._cancellable.is_cancelled())
return;
Expand Down
24 changes: 20 additions & 4 deletions src/service/plugins/telephony.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,32 @@ var Plugin = GObject.registerClass({
}

/**
* Restore volume, microphone and media player state (if changed), making
* sure to unpause before raising volume.
* Restore volume and microphone, plus media player state
* (if we changed it and restore is enabled).
*
* If we're going to auto-unpause, make sure to do that first
* before raising volume.
* Otherwise, still raise the volume (so the user can unpause).
*
* TODO: there's a possibility we might revert a media/mixer state set for
* another device.
*/
_restoreMediaState() {
// Media Playback
if (this._mpris)
this._mpris.unpauseAll();
if (this._mpris) {
if (this.settings.get_boolean('after-unpause')) {
this._mpris.unpauseAll();
} else {
/* Even if unpause is disabled, we still need to clear
* the list of which players we're holding paused
*
* TODO: This potentially worsens the multi-device
* problem, since we may be erasing the player
* list when another device still needs it.
*/
this._mpris.clearPaused();
}
}

// Mixer Volume
if (this._mixer)
Expand Down

0 comments on commit fa8f2ad

Please sign in to comment.