Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Add Playback requires user gesture setting
Browse files Browse the repository at this point in the history
Close #130
  • Loading branch information
ColinDuquesnoy committed Jul 8, 2018
1 parent b425593 commit 7e8fcef
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/lib/domain/src/Settings/Setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <MellowPlayer/Domain/Settings/ISettingsStore.hpp>
#include <MellowPlayer/Domain/Settings/Settings.hpp>
#include <MellowPlayer/Domain/Settings/SettingsCategory.hpp>
#include <QVersionNumber>

using namespace std;
using namespace MellowPlayer::Domain;
Expand Down Expand Up @@ -75,6 +76,13 @@ bool Setting::isEnabled() const
{
QString cond = data_.enableCondition;

if (cond.contains("qtVersion >="))
{
QVersionNumber requiredQtVersion = QVersionNumber::fromString(cond.split(">=")[1].trimmed().toLower());
QVersionNumber qtVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR);
return qtVersion >= requiredQtVersion;
}

if (parentSetting_ == nullptr)
return true;

Expand Down
10 changes: 9 additions & 1 deletion src/lib/infrastructure/resources/Settings/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@
"default": 0,
"key": "update-channel",
"enabled": "main/check-for-updates"
}
},
{
"name": "Playback requires user gesture",
"tooltip": "Inhibits playback of media content until the user interacts with the page. This is similar to how Chrome on Android behaves, while the default behavior when it is disabled is similar to Chrome on desktop",
"type": "bool",
"default": false,
"key": "playback-requires-user-gesture",
"enabled": "qtVersion >= 5.11"
}
]
},
{
Expand Down
45 changes: 17 additions & 28 deletions src/lib/presentation/imports/MellowPlayer/Controls/WebView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ WebEngineView {
onFullScreenRequested: mainWindow.toggleFullScreen(request)
onNewViewRequested: mainWindow.openWebPopup(request, profile)

Component.onCompleted: d.updatePlaybackRequiresUserGesture()

ValidationMessage {
id: validationMessage
}
Expand Down Expand Up @@ -274,6 +276,11 @@ WebEngineView {
onChangeVolumeRequest: playerBridge.changeVolume(newVolume)
}

Connections {
target: _settings.get(SettingKey.MAIN_PLAYBACK_REQUIRES_USER_GESTURE)
onValueChanged: d.updatePlaybackRequiresUserGesture()
}

QtObject {
id: d

Expand All @@ -283,6 +290,16 @@ WebEngineView {

onZoomFactorIndexChanged: root.service.zoomFactor = zoomFactorIndex

function updatePlaybackRequiresUserGesture() {
try {
root.settings.playbackRequiresUserGesture = _settings.get(SettingKey.MAIN_PLAYBACK_REQUIRES_USER_GESTURE).value
root.reload()
console.log("playbackRequiresUserGesture: " + root.settings.playbackRequiresUserGesture)
} catch(e) {
console.log("playbackRequiresUserGesture setting not supported with this version of Qt.")
}
}

function checkForCustomUrlRequired() {
var match = service.url.match("(@.*@)");
if (match !== null) {
Expand Down Expand Up @@ -343,32 +360,4 @@ WebEngineView {
return webEngineScript;
}
}

// QtObject {
// id: nullService

// property int zoomFactor: 1
// property QtObject player: QtObject {
// property string sourceCode: ""

// signal play()
// signal pause()
// signal next()
// signal previous()
// signal addToFavorites()
// signal removeFromFavorites()
// signal seekToPositionRequest(var position)
// signal changeVolumeRequest(double newVolume)
// }

// property QtObject networkProxy: QtObject {
// signal changed();
// }
// property QtObject userScripts: QtObject {
// property var model: []
// }

// property string url: ""
// property string name: ""
// }
}
23 changes: 23 additions & 0 deletions tests/UnitTests/Domain/Settings/SettingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <MellowPlayer/Domain/Settings/SettingsCategory.hpp>
#include <QtTest/QSignalSpy>
#include <Utils/DependencyPool.hpp>
#include <QVersionNumber>

using namespace std;
using namespace MellowPlayer::Domain;
Expand Down Expand Up @@ -154,6 +155,28 @@ TEST_CASE("SettingsTests")
REQUIRE(spy.count() == 1);
REQUIRE(accent.isEnabled());
}

SECTION("qtVersion condition, require >= 5.11")
{
Setting::Data data;
data.enableCondition = "qtVersion >= 5.11";
data.key = "test";
Setting setting(settings, *mainCategory, data);
QVersionNumber qtVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR);
if (qtVersion >= QVersionNumber::fromString("5.11"))
REQUIRE(setting.isEnabled());
else
REQUIRE(!setting.isEnabled());
}

SECTION("qtVersion condition, require >= 6.5")
{
Setting::Data data;
data.enableCondition = "qtVersion >= 6.5";
data.key = "test";
Setting setting(settings, *mainCategory, data);
REQUIRE(!setting.isEnabled());
}
}

SECTION("get invalid setting key throws")
Expand Down

0 comments on commit 7e8fcef

Please sign in to comment.