Properly store and restore last volume value on startup

We cannot depend on the value saved by GStreamer, cause it is shared with all GStreamer based apps. Lets save the last value to gsettings instead to make sure this is the volume we used with this app. With this change we can also see the right volume on startup before media file is loaded (previously it was shown always as muted).
This commit is contained in:
Rafostar
2020-11-30 11:16:21 +01:00
parent af6814bace
commit 5206dc543d
3 changed files with 16 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ const CONTROLS_MARGIN = 4;
const CONTROLS_SPACING = 4;
let { debug } = Debug;
let { settings } = Misc;
var Controls = GObject.registerClass(
class ClapperControls extends Gtk.Box
@@ -317,9 +318,6 @@ class ClapperControls extends Gtk.Box
draw_value: false,
vexpand: true,
});
this.volumeScale.connect(
'value-changed', this._onVolumeScaleValueChanged.bind(this)
);
this.volumeScale.add_css_class('volumescale');
this.volumeAdjustment = this.volumeScale.get_adjustment();
@@ -332,6 +330,9 @@ class ClapperControls extends Gtk.Box
this.volumeScale.add_mark(i, Gtk.PositionType.LEFT, text);
}
this.volumeScale.connect(
'value-changed', this._onVolumeScaleValueChanged.bind(this)
);
this.volumeButton.popoverBox.append(this.volumeScale);
}
@@ -368,6 +369,10 @@ class ClapperControls extends Gtk.Box
);
scrollController.connect('scroll', player._onScroll.bind(player));
this.volumeButton.add_controller(scrollController);
let lastVolume = settings.get_double('volume-last');
let cubicVolume = Misc.getCubicValue(lastVolume);
this.volumeScale.set_value(cubicVolume);
}
_onUnfullscreenClicked(button)

View File

@@ -628,10 +628,11 @@ class ClapperPlayer extends PlayerBase
let clapperWidget = this.widget.get_ancestor(Gtk.Grid);
if(!clapperWidget.fullscreenMode) {
let size = window.get_size();
if(size[0] > 0 && size[1] > 0) {
if(size[0] > 0 && size[1] > 0)
clapperWidget._saveWindowSize(size);
}
}
settings.set_double('volume-last', this.volume);
clapperWidget.controls._onCloseRequest();
if(this.state === GstPlayer.PlayerState.STOPPED)

View File

@@ -12,7 +12,7 @@
</key>
<key name="volume-value" type="i">
<default>100</default>
<summary>Custom initial volume value after startup</summary>
<summary>Custom initial volume value in percentage after startup</summary>
</key>
<key name="dark-theme" type="b">
<default>true</default>
@@ -74,5 +74,9 @@
<default>'[480, 270]'</default>
<summary>Stores floating window size to restore on next launch</summary>
</key>
<key name="volume-last" type="d">
<default>1</default>
<summary>Stores last linear volume value to apply on startup</summary>
</key>
</schema>
</schemalist>