added platform specific initialization function
This commit is contained in:
parent
9e13a8f4fe
commit
1be868acaf
|
@ -18,7 +18,7 @@ add_executable (PlayerLink ${SOURCES})
|
|||
set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 20)
|
||||
add_subdirectory("vendor")
|
||||
set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono)
|
||||
set(INCLUDES vendor vendor/libdbus vendor/wxWidgets/include)
|
||||
set(INCLUDES vendor vendor/wxWidgets/include)
|
||||
|
||||
#use windows subsystem to disable console window and link winrt
|
||||
if(WIN32)
|
||||
|
@ -35,7 +35,7 @@ elseif(APPLE)
|
|||
endif()
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
list(APPEND LIBRARIES dbus)
|
||||
list(APPEND INCLUDES "${CMAKE_BINARY_DIR}/vendor/dbus")
|
||||
list(APPEND INCLUDES "${CMAKE_BINARY_DIR}/vendor/dbus" vendor/libdbus)
|
||||
endif()
|
||||
|
||||
#search directories for the autogenerated wxwidgets setup.h file for all plattforms
|
||||
|
|
|
@ -27,8 +27,9 @@ struct MediaInfo {
|
|||
};
|
||||
|
||||
namespace backend {
|
||||
bool init();
|
||||
bool toggleAutostart(bool enabled);
|
||||
std::shared_ptr<MediaInfo> getMediaInformation();
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#ifdef __APPLE__
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <filesystem>
|
||||
|
@ -27,6 +28,13 @@
|
|||
</dict>
|
||||
</plist>)"
|
||||
|
||||
void hideDockIcon(bool shouldHide) {
|
||||
if (shouldHide)
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
||||
else
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||
__block NSString *appName = nil;
|
||||
__block NSDictionary *playingInfo = nil;
|
||||
|
@ -87,6 +95,7 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
|||
return std::make_shared<MediaInfo>(paused, songTitle, songArtist, songAlbum, appNameString, thumbnailData,
|
||||
durationMs, elapsedTimeMs);
|
||||
}
|
||||
|
||||
bool backend::toggleAutostart(bool enabled) {
|
||||
std::filesystem::path launchAgentPath = std::getenv("HOME");
|
||||
launchAgentPath = launchAgentPath / "Library" / "LaunchAgents" / "PlayerLink.plist";
|
||||
|
@ -101,5 +110,11 @@ bool backend::toggleAutostart(bool enabled) {
|
|||
o.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool backend::init() {
|
||||
hideDockIcon(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef LAUNCH_AGENT_TEMPLATE
|
||||
#endif
|
|
@ -4,7 +4,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "../backend.hpp"
|
||||
bool initialized = false;
|
||||
|
||||
DBusConnection* conn = nullptr;
|
||||
|
||||
std::string getActivePlayer(DBusConnection* conn) {
|
||||
|
@ -202,18 +202,19 @@ void getNowPlaying(DBusConnection* conn, const std::string& player) {
|
|||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||
if (!initialized) {
|
||||
DBusError err;
|
||||
dbus_error_init(&err);
|
||||
bool backend::init() {
|
||||
DBusError err;
|
||||
dbus_error_init(&err);
|
||||
|
||||
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
||||
if (!conn) {
|
||||
dbus_error_free(&err);
|
||||
return nullptr;
|
||||
}
|
||||
initialized = true;
|
||||
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
|
||||
if (!conn) {
|
||||
dbus_error_free(&err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||
std::string player = getActivePlayer(conn);
|
||||
if (player == "")
|
||||
return nullptr;
|
||||
|
|
|
@ -116,5 +116,8 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
|||
toStdString(mediaProperties.Title()), artist, albumName, toStdString(currentSession.SourceAppUserModelId()),
|
||||
thumbnailData, endTime, elapsedTime);
|
||||
}
|
||||
|
||||
bool backend::init() { return true; }
|
||||
|
||||
#undef EM_DASH
|
||||
#endif
|
|
@ -283,6 +283,10 @@ private:
|
|||
wxIMPLEMENT_APP_NO_MAIN(PlayerLink);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (!backend::init()) {
|
||||
wxMessageBox(_("Error initializing platform backend!"), _("PlayerLink"), wxOK | wxICON_ERROR);
|
||||
return -1;
|
||||
}
|
||||
std::thread rpcThread(handleRPCTasks);
|
||||
rpcThread.detach();
|
||||
std::thread mediaThread(handleMediaTasks);
|
||||
|
|
Loading…
Reference in New Issue