From 5206dc543d30db89661d923effae8b2a0a4409f2 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Mon, 30 Nov 2020 11:16:21 +0100 Subject: [PATCH] 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). --- clapper_src/controls.js | 11 ++++++++--- clapper_src/player.js | 5 +++-- data/com.github.rafostar.Clapper.gschema.xml | 6 +++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clapper_src/controls.js b/clapper_src/controls.js index dec39228..2f8b48e5 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -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) diff --git a/clapper_src/player.js b/clapper_src/player.js index a58ffcc6..9a6f72b0 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -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) diff --git a/data/com.github.rafostar.Clapper.gschema.xml b/data/com.github.rafostar.Clapper.gschema.xml index 124748bd..52ef1eaa 100644 --- a/data/com.github.rafostar.Clapper.gschema.xml +++ b/data/com.github.rafostar.Clapper.gschema.xml @@ -12,7 +12,7 @@ 100 - Custom initial volume value after startup + Custom initial volume value in percentage after startup true @@ -74,5 +74,9 @@ '[480, 270]' Stores floating window size to restore on next launch + + 1 + Stores last linear volume value to apply on startup +