Merge pull request #700 from overte-org/fix/oculus_plugin

Disable Oculus plugin by default and add a setting to enable it
This commit is contained in:
ksuprynowicz 2023-11-05 22:41:29 +01:00 committed by GitHub
commit e08aa2f1a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 16 deletions

View file

@ -17,7 +17,7 @@ PreferencesDialog {
id: root
objectName: "GeneralPreferencesDialog"
title: "General Settings"
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy"]
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy", "Plugins"]
property var settings: Settings {
category: root.objectName
property alias x: root.x

View file

@ -38,6 +38,6 @@ StackView {
TabletPreferencesDialog {
id: root
objectName: "TabletGeneralPreferences"
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy"]
showCategories: ["User Interface", "Mouse Sensitivity", "HMD", "Snapshots", "Privacy", "Plugins"]
}
}

View file

@ -15,6 +15,7 @@
#include <OffscreenUi.h>
#include <Preferences.h>
#include <plugins/PluginUtils.h>
#include <plugins/PluginManager.h>
#include <display-plugins/CompositorHelper.h>
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include "scripting/RenderScriptingInterface.h"
@ -637,4 +638,12 @@ void setupPreferences() {
preferences->addPreference(preference);
}
}
static const QString PLUGIN_CATEGORY{ "Plugins" };
auto pluginManager = PluginManager::getInstance();
{
auto getter = [pluginManager]()->bool { return pluginManager->getEnableOculusPluginSetting(); };
auto setter = [pluginManager](bool value) { pluginManager->setEnableOculusPluginSetting(value); };
preferences->addPreference(new CheckPreference(PLUGIN_CATEGORY, "Enable Oculus Platform Plugin", getter, setter));
}
}

View file

@ -211,18 +211,27 @@ const OculusPlatformPluginPointer PluginManager::getOculusPlatformPlugin() {
static OculusPlatformPluginPointer oculusPlatformPlugin;
static std::once_flag once;
std::call_once(once, [&] {
// Now grab the dynamic plugins
for (auto loader : getLoadedPlugins()) {
OculusPlatformProvider* oculusPlatformProvider = qobject_cast<OculusPlatformProvider*>(loader->instance());
if (oculusPlatformProvider) {
oculusPlatformPlugin = oculusPlatformProvider->getOculusPlatformPlugin();
break;
// Now grab the dynamic plugins if the setting allows it
if (_enableOculusPluginSetting.get()) {
qCDebug(plugins) << "PluginManager::getOculusPlatformPlugin: Oculus plugin enabled by a setting";
for (auto loader : getLoadedPlugins()) {
OculusPlatformProvider* oculusPlatformProvider = qobject_cast<OculusPlatformProvider*>(loader->instance());
if (oculusPlatformProvider) {
oculusPlatformPlugin = oculusPlatformProvider->getOculusPlatformPlugin();
break;
}
}
} else {
qCDebug(plugins) << "PluginManager::getOculusPlatformPlugin: Oculus plugin disabled by a setting";
}
});
return oculusPlatformPlugin;
}
void PluginManager::setEnableOculusPluginSetting(bool value) {
_enableOculusPluginSetting.set(value);
}
DisplayPluginList PluginManager::getAllDisplayPlugins() {
return _displayPlugins;
}

View file

@ -54,6 +54,9 @@ public:
void setPluginFilter(PluginFilter pluginFilter) { _pluginFilter = pluginFilter; }
Q_INVOKABLE DisplayPluginList getAllDisplayPlugins();
bool getEnableOculusPluginSetting() { return _enableOculusPluginSetting.get(); }
void setEnableOculusPluginSetting(bool value);
signals:
void inputDeviceRunningChanged(const QString& pluginName, bool isRunning, const QStringList& runningDevices);
@ -76,6 +79,8 @@ private:
Setting::Handle<bool> _enableScriptingPlugins {
"private/enableScriptingPlugins", (bool)qgetenv("enableScriptingPlugins").toInt()
};
Setting::Handle<bool> _enableOculusPluginSetting { "enableOculusPluginSetting", false };
};
// TODO: we should define this value in CMake, and then use CMake

View file

@ -23,6 +23,8 @@
#include <controllers/Pose.h>
#include <NumericalConstants.h>
#include <ui-plugins/PluginContainer.h>
#include <plugins/PluginManager.h>
#include <ui/Menu.h>
#include "../../interface/src/Menu.h"
@ -50,15 +52,21 @@ static const uint32_t RELEASE_OPENVR_HMD_DELAY_MS = 5000;
bool isOculusPresent() {
bool result = false;
#ifdef Q_OS_WIN
HANDLE oculusServiceEvent = ::OpenEventW(SYNCHRONIZE, FALSE, L"OculusHMDConnected");
// The existence of the service indicates a running Oculus runtime
if (oculusServiceEvent) {
// A signaled event indicates a connected HMD
if (WAIT_OBJECT_0 == ::WaitForSingleObject(oculusServiceEvent, 0)) {
result = true;
#ifdef Q_OS_WIN
// Only check for Oculus presence if Oculus plugin is enabled
if (PluginManager::getInstance()->getEnableOculusPluginSetting()) {
qDebug() << "isOculusPresent: Oculus plugin enabled by a setting";
HANDLE oculusServiceEvent = ::OpenEventW(SYNCHRONIZE, FALSE, L"OculusHMDConnected");
// The existence of the service indicates a running Oculus runtime
if (oculusServiceEvent) {
// A signaled event indicates a connected HMD
if (WAIT_OBJECT_0 == ::WaitForSingleObject(oculusServiceEvent, 0)) {
result = true;
}
::CloseHandle(oculusServiceEvent);
}
::CloseHandle(oculusServiceEvent);
} else {
qDebug() << "isOculusPresent: Oculus plugin disabled by a setting";
}
#endif
return result;