Move desktop notifications to its own header

We'll need to use this from the chainloader.
This commit is contained in:
Robbert van der Helm
2022-04-16 14:57:26 +02:00
parent fde90d7bc3
commit 46af07748b
12 changed files with 246 additions and 193 deletions
+1 -3
View File
@@ -26,12 +26,10 @@
#include <version.h>
#include "../../common/configuration.h"
#include "../../common/notifications.h"
#include "../../common/utils.h"
#include "../host-process.h"
// FIXME: This should be passed as an argument instead
#include "../../common/linking.h"
/**
* If the amount of lockable memory is below this, then we'll warn about it
* during startup. Otherwise we may run into issues when mapping shared memory
+2
View File
@@ -10,6 +10,7 @@ vst2_plugin_sources = files(
'../common/logging/vst2.cpp',
'../common/audio-shm.cpp',
'../common/linking.cpp',
'../common/notifications.cpp',
'../common/plugins.cpp',
'../common/process.cpp',
'../common/utils.cpp',
@@ -82,6 +83,7 @@ vst3_plugin_sources = files(
'../common/audio-shm.cpp',
'../common/configuration.cpp',
'../common/linking.cpp',
'../common/notifications.cpp',
'../common/plugins.cpp',
'../common/process.cpp',
'../common/utils.cpp',
-46
View File
@@ -422,49 +422,3 @@ Configuration load_config_for(const fs::path& yabridge_path) {
return Configuration(*config_file, yabridge_path);
}
bool send_notification(const std::string& title,
const std::string body,
std::optional<ghc::filesystem::path> origin) {
// I think there's a zero chance that we're going to call this function with
// anything that even somewhat resembles HTML, but we should still do a
// basic XML escape anyways.
std::ostringstream formatted_body;
formatted_body << xml_escape(body);
// If the path to the current library file is provided, then we'll append
// the path to that library file to the message. In earlier versions we
// would detect the library path right here, but that will not work with
// chainloaded plugins as they will load the actual plugin libraries from
// fixed locations.
if (origin) {
try {
formatted_body << "\n"
<< "Source: <a href=\"file://"
<< url_encode_path(origin->parent_path().string())
<< "\">" << xml_escape(origin->filename().string())
<< "</a>";
} catch (const std::system_error&) {
// I don't think this can fail in the way we're using it, but the
// last thing we want is our notification informing the user of an
// exception to trigger another exception
}
}
Process process("notify-send");
process.arg("--urgency=normal");
process.arg("--app-name=yabridge");
process.arg(title);
process.arg(formatted_body.str());
// We will have printed the message to the terminal anyways, so if the user
// doesn't have libnotify installed we'll just fail silently
const auto result = process.spawn_get_status();
return std::visit(
overload{
[](int status) -> bool { return status == EXIT_SUCCESS; },
[](const Process::CommandNotFound&) -> bool { return false; },
[](const std::error_code&) -> bool { return false; },
},
result);
}
-20
View File
@@ -263,26 +263,6 @@ std::vector<ghc::filesystem::path> get_augmented_search_path();
*/
Configuration load_config_for(const ghc::filesystem::path& yabridge_path);
/**
* Send a desktop notification using `notify-send`. Used for diagnostics when a
* plugin fails to load since the user may not be checking the output in a
* terminal.
*
* @param title The title (or technically, summary) of the notification.
* @param body The message to display. This can contain line feeds, and it any
* HTML tags and XML escape sequences will be automatically escaped. The
* message can also be empty.
* @param origin If this is set to the current plugin's path, then the
* notification will append a 'Source: <XXX.so>' hyperlink to the body so the
* user can more easily navigate to the plugin's path.
*
* @return Whether the notification was sent. This will be false if
* `notify-send` is not available.
*/
bool send_notification(const std::string& title,
const std::string body,
std::optional<ghc::filesystem::path> origin);
/**
* Starting from the starting file or directory, go up in the directory
* hierarchy until we find a file named `filename`.
+1
View File
@@ -19,6 +19,7 @@
#include <iostream>
#include <memory>
#include "../common/linking.h"
#include "../common/logging/common.h"
#include "bridges/vst2.h"
+5 -4
View File
@@ -14,10 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "bridges/vst3.h"
using namespace std::literals::string_literals;
// FIXME: The VST3 SDK as of version 3.7.2 now includes multiple local functions
// called `InitModule` and `DeinitModule`: one in the new
// `public.sdk/source/main/initmodule.cpp`, and the existing ones in the
@@ -29,6 +25,9 @@ using namespace std::literals::string_literals;
// NOLINTNEXTLINE(bugprone-suspicious-include)
#include <public.sdk/source/main/linuxmain.cpp>
#include "../common/linking.h"
#include "bridges/vst3.h"
using namespace std::literals::string_literals;
namespace fs = ghc::filesystem;
@@ -49,6 +48,8 @@ namespace fs = ghc::filesystem;
std::unique_ptr<Vst3PluginBridge> bridge;
// These functions are called by the `ModuleEntry` and `ModuleExit` functions on
// the first load and load unload
bool InitModule() {
assert(!bridge);