Skip to content

Commit 11a8445

Browse files
FiniteSingularityPatTheMav
authored andcommitted
frontend: Update app module loading behavior
With this change module loading in the application is managed by the plugin manager and allows the application to explicitly load core modules independantly from 3rd party (plugin) modules. The implementation is split into separate files for different platforms to allow for cleaner code handling the different possible locations and path schemes used, including all possible legacy locations and plugin bundle formats. This change introduces new locations and directory formats for plugins: * WINDOWS: Portable plugins need to be placed in a directory called "plugins" adjacent to the "bin" directory of an OBS Studio installation. * WINDOWS: Plugins need to be packaged into their own directory "bundles", with the associated DLL in the root of the bundle and the associated "data" directory next to it. * WINDOWS: The "obs-plugins" directory adjacent to the "bin" directory is deprecated and considered a legacy location for all plugins. * MACOS: No changes in locations or formats. * LINUX: Plugins distributed via system package managers now need to use the "obs-modules/plugins" directory in the system library directory for binaries, and the "obs/obs-modules/plugins" directory in the system data directory for resources. * LINUX: The "obs-plugins" directories in the system library and system data directories are deprecated. * LINUX: Plugins distributed outside of system packages need to use the same directory format as plugins for Windows (see above). * LINUX: A "portable" plugin location like on Windows is not supported. * LINUX: Proper XDG directory locations are scanned for plugins, using XDG_CONFIG_HOME for the legacy plugin format and XDG_DATA_HOME for the new plugin structure. * LINUX: Changes Flatpak plugin loading to use the new plugin structure (while still supporting the legacy structure), and moves Flatpak specific plugin loading to its own source files. * ALL PLATFORMS: A single environment variable "OBS_PLUGINS_PATH" can now be used to provide a highest-priority location from which to load plugins. This directory needs to contain plugin bundles per the new format. The one exception is Flatpak which does not support loading plugins from an env provided location. * ALL PLATFORMS: A custom legacy plugin locations can still be provided via the "OBS_LEGACY_PLUGINS_PATH" and "OBS_LEGACY_PLUGINS_DATA_PATH" environment variables. These are only compatible with plugins using the legacy format and are considered deprecated. The one exception is Flatpak which does not support loading plugins from an env provided location. Co-authored-by: PatTheMav <[email protected]>
1 parent 23bba44 commit 11a8445

24 files changed

Lines changed: 1472 additions & 270 deletions

‎build-aux/com.obsproject.Studio.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"versions": "stable;test",
2626
"subdirectories": true,
2727
"add-ld-path": "lib",
28-
"merge-dirs": "lib/obs-plugins;share/obs/obs-plugins",
28+
"merge-dirs": "lib/obs-modules/plugins;share/obs/obs-modules/plugins;lib/obs-plugins;share/obs/obs-plugins",
2929
"no-autodownload": true,
3030
"autodelete": true
3131
},
@@ -132,6 +132,7 @@
132132
"builddir": true,
133133
"config-opts": [
134134
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
135+
"-DENABLE_FLATPAK=ON",
135136
"-DENABLE_WAYLAND=ON",
136137
"-DENABLE_BROWSER=ON",
137138
"-DCEF_ROOT_DIR=/app/cef",

‎frontend/CMakeLists.txt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ foreach(graphics_library IN ITEMS opengl metal d3d11)
9999
endif()
100100
endforeach()
101101

102-
get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED)
103-
list(JOIN obs_module_list "|" SAFE_MODULES)
104-
target_compile_definitions(obs-studio PRIVATE "SAFE_MODULES=\"${SAFE_MODULES}\"")
105-
106102
get_target_property(target_sources obs-studio SOURCES)
107103
set(target_cpp_sources ${target_sources})
108104
set(target_hpp_sources ${target_sources})

‎frontend/OBSApp.cpp‎

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ typedef struct UncleanLaunchAction {
9090
bool sendCrashReport = false;
9191
} UncleanLaunchAction;
9292

93+
enum class PluginFailureAction { Continue, OpenPluginManager };
94+
95+
PluginFailureAction handlePluginFailure()
96+
{
97+
QMessageBox pluginWarning;
98+
99+
pluginWarning.setIcon(QMessageBox::Warning);
100+
101+
pluginWarning.setWindowTitle(QTStr("PluginFailure.Dialog.Title"));
102+
pluginWarning.setText(QTStr("PluginFailure.Labels.Text"));
103+
104+
QPushButton *continueButton =
105+
pluginWarning.addButton(QTStr("PluginFailure.Dialog.Continue"), QMessageBox::RejectRole);
106+
QPushButton *handleButton =
107+
pluginWarning.addButton(QTStr("PluginFailure.Dialog.Open"), QMessageBox::AcceptRole);
108+
109+
pluginWarning.setDefaultButton(continueButton);
110+
111+
pluginWarning.exec();
112+
113+
bool openPluginManager = pluginWarning.clickedButton() == handleButton;
114+
115+
if (openPluginManager) {
116+
return PluginFailureAction::OpenPluginManager;
117+
} else {
118+
return PluginFailureAction::Continue;
119+
}
120+
}
121+
93122
UncleanLaunchAction handleUncleanShutdown(bool enableCrashUpload)
94123
{
95124
UncleanLaunchAction launchAction;
@@ -2062,16 +2091,27 @@ void OBSApp::addLogLine(int logLevel, const QString &message)
20622091
emit logLineAdded(logLevel, message);
20632092
}
20642093

2065-
void OBSApp::loadAppModules(struct obs_module_failure_info &mfi)
2094+
void OBSApp::loadAppModules()
2095+
{
2096+
using PluginMode = OBS::PluginManager::Mode;
2097+
PluginMode mode = (disable_3p_plugins || safe_mode) ? PluginMode::CoreOnly : PluginMode::Full;
2098+
pluginManager_->setPluginMode(mode);
2099+
2100+
pluginManager_->loadAllPlugins(portable_mode);
2101+
}
2102+
2103+
void OBSApp::handlePluginLoadState()
20662104
{
2067-
pluginManager_->preLoad();
2068-
blog(LOG_INFO, "---------------------------------");
2069-
obs_load_all_modules2(&mfi);
2070-
blog(LOG_INFO, "---------------------------------");
2071-
obs_log_loaded_modules();
2072-
blog(LOG_INFO, "---------------------------------");
2073-
obs_post_load_modules();
2074-
pluginManager_->postLoad();
2105+
using PluginState = OBS::PluginManager::State;
2106+
PluginState loadState = pluginManager_->loadState();
2107+
2108+
if (loadState != PluginState::Success) {
2109+
PluginFailureAction action = handlePluginFailure();
2110+
2111+
if (action == PluginFailureAction::OpenPluginManager) {
2112+
pluginManagerOpenDialog();
2113+
}
2114+
}
20752115
}
20762116

20772117
void OBSApp::pluginManagerOpenDialog()

‎frontend/OBSApp.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,13 @@ private slots:
235235
static void sigQuitSignalHandler(int);
236236
#endif
237237

238-
void loadAppModules(struct obs_module_failure_info &mfi);
238+
void loadAppModules();
239239

240240
ThumbnailManager *thumbnails() const { return thumbnailManager; }
241241

242242
// Plugin Manager Accessors
243243
void pluginManagerOpenDialog();
244+
void handlePluginLoadState();
244245

245246
public slots:
246247
void addLogLine(int logLevel, const QString &message);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
find_package(nlohmann_json 3.11 REQUIRED)
22

3+
set(OBS_PLATFORM_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/")
4+
set(OBS_PLATFORM_LIBRARY_PATH "${CMAKE_INSTALL_LIBDIR}/")
5+
set(OBS_PLATFORM_DATA_PATH "${CMAKE_INSTALL_DATAROOTDIR}/")
6+
set(OBS_PLATFORM_CORE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/obs-modules/core")
7+
set(OBS_PLATFORM_CORE_DATA_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-modules/core")
8+
set(OBS_PLATFORM_PLUGIN_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/obs-modules/plugins")
9+
set(OBS_PLATFORM_PLUGIN_DATA_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-modules/plugins")
10+
311
target_sources(
412
obs-studio
513
PRIVATE
614
plugin-manager/PluginManager.cpp
715
plugin-manager/PluginManager.hpp
816
plugin-manager/PluginManagerWindow.cpp
917
plugin-manager/PluginManagerWindow.hpp
18+
plugin-manager/PluginModuleLoader.hpp
1019
)
1120

21+
if(OS_WINDOWS)
22+
target_sources(obs-studio PRIVATE plugin-manager/PluginModuleLoader_Windows.cpp)
23+
elseif(OS_MACOS)
24+
target_sources(obs-studio PRIVATE plugin-manager/PluginModuleLoader_MacOS.mm)
25+
elseif(OS_FLATPAK)
26+
configure_file(plugin-manager/LoaderPaths_Flatpak.hpp.in LoaderPaths_Flatpak.hpp @ONLY)
27+
target_sources(obs-studio PRIVATE plugin-manager/PluginModuleLoader_Flatpak.cpp LoaderPaths_Flatpak.hpp)
28+
elseif(OS_LINUX)
29+
configure_file(plugin-manager/LoaderPaths_Linux.hpp.in LoaderPaths_Linux.hpp @ONLY)
30+
target_sources(obs-studio PRIVATE plugin-manager/PluginModuleLoader_Linux.cpp LoaderPaths_Linux.hpp)
31+
elseif(OS_FREEBSD OR OS_OPENBSD)
32+
configure_file(plugin-manager/LoaderPaths_BSD.hpp.in LoaderPaths_BSD.hpp @ONLY)
33+
target_sources(obs-studio PRIVATE plugin-manager/PluginModuleLoader_BSD.cpp LoaderPaths_BSD.hpp)
34+
endif()
35+
1236
target_link_libraries(obs-studio PRIVATE nlohmann_json::nlohmann_json)

‎frontend/data/locale/en-US.ini‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ CrashHandling.Buttons.LaunchNormal="Run in Normal Mode"
141141
CrashHandling.Errors.UploadJSONError="An error occurred while trying to upload the most recent crash log. Please try again later."
142142
CrashHandling.Errors.Title="Crash Log Upload Error"
143143

144+
# Plugin Manager Load Failure
145+
PluginFailure.Dialog.Title="OBS Studio Plugin Loading Failure"
146+
PluginFailure.Labels.Text="OBS Studio was not able to load all third-party plugins.\n\nOpen Plugin Manager to check the state of third-party plugins?"
147+
PluginFailure.Dialog.Continue="Continue"
148+
PluginFailure.Dialog.Open="Open Plugin Manager"
149+
144150
# Safe Mode Restart Option
145151
SafeMode.Restart="Do you want to restart OBS in Safe Mode (third-party plugins, scripting, and WebSockets disabled)?"
146152
SafeMode.RestartNormal="Do you want to restart OBS in Normal Mode?"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/******************************************************************************
2+
Copyright (C) 2026 by FiniteSingularity <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
18+
#pragma once
19+
20+
#include <string_view>
21+
22+
namespace OBS::Constants {
23+
inline constexpr std::string_view kPlatformInstallPath{"@OBS_PLATFORM_INSTALL_PATH@"};
24+
inline constexpr std::string_view kPlatformLibraryPath{"@OBS_PLATFORM_LIBRARY_PATH@"};
25+
inline constexpr std::string_view kPlatformDataPath{"@OBS_PLATFORM_DATA_PATH@"};
26+
inline constexpr std::string_view kPlatformPluginModulePath{"@OBS_PLATFORM_PLUGIN_MODULE_PATH@"};
27+
inline constexpr std::string_view kPlatformPluginDataPath{"@OBS_PLATFORM_PLUGIN_DATA_PATH@"};
28+
} // namespace OBS::Constants
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
Copyright (C) 2026 by FiniteSingularity <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
18+
#pragma once
19+
20+
#include <string_view>
21+
22+
namespace OBS::Constants {
23+
inline constexpr std::string_view kPlatformInstallPath{"@OBS_PLATFORM_INSTALL_PATH@"};
24+
inline constexpr std::string_view kPlatformLibraryPath{"@OBS_PLATFORM_LIBRARY_PATH@"};
25+
inline constexpr std::string_view kPlatformDataPath{"@OBS_PLATFORM_DATA_PATH@"};
26+
inline constexpr std::string_view kPlatformPluginModulePath{"@OBS_PLATFORM_PLUGIN_MODULE_PATH@"};
27+
inline constexpr std::string_view kPlatformPluginDataPath{"@OBS_PLATFORM_PLUGIN_DATA_PATH@"};
28+
inline constexpr std::string_view kXDGConfigHomeVariable{"XDG_CONFIG_HOME"};
29+
inline constexpr std::string_view kXDGDataHomeVariable{"XDG_DATA_HOME"};
30+
} // namespace OBS::Constants
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
Copyright (C) 2026 by FiniteSingularity <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
18+
#pragma once
19+
20+
#include <string_view>
21+
22+
namespace OBS::Constants {
23+
inline constexpr std::string_view kPlatformInstallPath{"@OBS_PLATFORM_INSTALL_PATH@"};
24+
inline constexpr std::string_view kPlatformLibraryPath{"@OBS_PLATFORM_LIBRARY_PATH@"};
25+
inline constexpr std::string_view kPlatformDataPath{"@OBS_PLATFORM_DATA_PATH@"};
26+
inline constexpr std::string_view kPlatformPluginModulePath{"@OBS_PLATFORM_PLUGIN_MODULE_PATH@"};
27+
inline constexpr std::string_view kPlatformPluginDataPath{"@OBS_PLATFORM_PLUGIN_DATA_PATH@"};
28+
inline constexpr std::string_view kXDGConfigHomeVariable{"XDG_CONFIG_HOME"};
29+
inline constexpr std::string_view kXDGDataHomeVariable{"XDG_DATA_HOME"};
30+
} // namespace OBS::Constants

‎frontend/plugin-manager/PluginManager.cpp‎

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void addModuleToPluginManagerImpl(void *param, obs_module_t *newModule)
3939
std::string moduleName = obs_get_module_file_name(newModule);
4040
moduleName = moduleName.substr(0, moduleName.rfind("."));
4141

42-
if (!obs_get_module_allow_disable(moduleName.c_str())) {
42+
if (obs_is_core_module(newModule)) {
4343
return;
4444
}
4545

@@ -67,7 +67,7 @@ constexpr std::string_view OBSPluginManagerModulesFile = "modules.json";
6767

6868
void PluginManager::preLoad()
6969
{
70-
loadModules_();
70+
loadModuleConfiguration_();
7171
disableModules_();
7272
}
7373

@@ -82,6 +82,32 @@ void PluginManager::postLoad()
8282
linkUnloadedModules_();
8383
}
8484

85+
void PluginManager::loadAllPlugins(bool usePortableMode)
86+
{
87+
preLoad();
88+
bool coreModuleLoadSuccess = obs_load_core_modules();
89+
90+
if (!coreModuleLoadSuccess) {
91+
loadState_ = State::Failure;
92+
//TODO: Replace with structured exception type - https://github.com/obsproject/obs-studio/issues/13394
93+
throw "Failed to load core OBS modules. OBS cannot run without these modules. Please try reinstalling OBS.";
94+
}
95+
96+
if (loadMode_ == Mode::Full) {
97+
blog(LOG_INFO, "---------------------------------");
98+
State pluginState = loadPlugins(usePortableMode);
99+
State legacyPluginState = loadLegacyPlugins(usePortableMode);
100+
101+
loadState_ = (pluginState && legacyPluginState) ? State::Success : State::PartialFailure;
102+
}
103+
104+
blog(LOG_INFO, "---------------------------------");
105+
obs_log_loaded_modules();
106+
blog(LOG_INFO, "---------------------------------");
107+
obs_post_load_modules();
108+
postLoad();
109+
}
110+
85111
std::filesystem::path PluginManager::getConfigFilePath_()
86112
{
87113
std::filesystem::path path = App()->userPluginManagerSettingsLocation /
@@ -90,7 +116,7 @@ std::filesystem::path PluginManager::getConfigFilePath_()
90116
return path;
91117
}
92118

93-
void PluginManager::loadModules_()
119+
void PluginManager::loadModuleConfiguration_()
94120
{
95121
auto modulesFile = getConfigFilePath_();
96122
if (std::filesystem::exists(modulesFile)) {
@@ -282,7 +308,12 @@ void PluginManager::disableModules_()
282308
void PluginManager::open()
283309
{
284310
auto main = OBSBasic::Get();
285-
PluginManagerWindow pluginManagerWindow(modules_, main);
311+
PluginManagerWindow pluginManagerWindow(modules_, failedModules_, main);
312+
313+
if (loadState_ == State::PartialFailure) {
314+
pluginManagerWindow.setPage(PluginManagerWindow::Page::Failure);
315+
}
316+
286317
auto result = pluginManagerWindow.exec();
287318
if (result == QDialog::Accepted) {
288319
modules_ = pluginManagerWindow.result();
@@ -310,3 +341,45 @@ void PluginManager::open()
310341
}
311342

312343
}; // namespace OBS
344+
345+
bool operator&&(const OBS::PluginManager::State &lhs, const OBS::PluginManager::State &rhs)
346+
{
347+
using State = OBS::PluginManager::State;
348+
349+
if (lhs == State::Success && rhs == State::Success) {
350+
return true;
351+
}
352+
353+
return false;
354+
}
355+
356+
bool operator&&(const OBS::PluginManager::State &lhs, bool rhs)
357+
{
358+
return (lhs == OBS::PluginManager::State::Success && rhs);
359+
}
360+
361+
bool operator&&(bool lhs, const OBS::PluginManager::State &rhs)
362+
{
363+
return (lhs && rhs == OBS::PluginManager::State::Success);
364+
}
365+
366+
bool operator||(const OBS::PluginManager::State &lhs, const OBS::PluginManager::State &rhs)
367+
{
368+
using State = OBS::PluginManager::State;
369+
370+
if (lhs == State::Success || rhs == State::Success) {
371+
return true;
372+
}
373+
374+
return false;
375+
}
376+
377+
bool operator||(const OBS::PluginManager::State &lhs, bool rhs)
378+
{
379+
return (lhs == OBS::PluginManager::State::Success || rhs);
380+
}
381+
382+
bool operator||(bool lhs, const OBS::PluginManager::State &rhs)
383+
{
384+
return (lhs || rhs == OBS::PluginManager::State::Success);
385+
}

0 commit comments

Comments
 (0)