Finished mac os support
This commit is contained in:
parent
ab09fa1a6f
commit
26c1e8cc8a
|
@ -3,3 +3,4 @@ build/*
|
||||||
.cache/*
|
.cache/*
|
||||||
src/rsrc.hpp
|
src/rsrc.hpp
|
||||||
PlayerLink.exe
|
PlayerLink.exe
|
||||||
|
.vscode/*
|
|
@ -1,90 +0,0 @@
|
||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"iostream": "cpp",
|
|
||||||
"thread": "cpp",
|
|
||||||
"algorithm": "cpp",
|
|
||||||
"array": "cpp",
|
|
||||||
"atomic": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"cctype": "cpp",
|
|
||||||
"charconv": "cpp",
|
|
||||||
"chrono": "cpp",
|
|
||||||
"clocale": "cpp",
|
|
||||||
"cmath": "cpp",
|
|
||||||
"compare": "cpp",
|
|
||||||
"concepts": "cpp",
|
|
||||||
"condition_variable": "cpp",
|
|
||||||
"coroutine": "cpp",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
|
||||||
"cstdlib": "cpp",
|
|
||||||
"cstring": "cpp",
|
|
||||||
"ctime": "cpp",
|
|
||||||
"cwchar": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"format": "cpp",
|
|
||||||
"forward_list": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"iomanip": "cpp",
|
|
||||||
"ios": "cpp",
|
|
||||||
"iosfwd": "cpp",
|
|
||||||
"istream": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"limits": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"locale": "cpp",
|
|
||||||
"map": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"mutex": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"random": "cpp",
|
|
||||||
"ratio": "cpp",
|
|
||||||
"regex": "cpp",
|
|
||||||
"sstream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"stop_token": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"typeinfo": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"utility": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"xfacet": "cpp",
|
|
||||||
"xhash": "cpp",
|
|
||||||
"xiosbase": "cpp",
|
|
||||||
"xlocale": "cpp",
|
|
||||||
"xlocbuf": "cpp",
|
|
||||||
"xlocinfo": "cpp",
|
|
||||||
"xlocmes": "cpp",
|
|
||||||
"xlocmon": "cpp",
|
|
||||||
"xlocnum": "cpp",
|
|
||||||
"xloctime": "cpp",
|
|
||||||
"xmemory": "cpp",
|
|
||||||
"xstring": "cpp",
|
|
||||||
"xtr1common": "cpp",
|
|
||||||
"xtree": "cpp",
|
|
||||||
"xutility": "cpp",
|
|
||||||
"xstddef": "cpp",
|
|
||||||
"fstream": "cpp",
|
|
||||||
"any": "cpp",
|
|
||||||
"csignal": "cpp",
|
|
||||||
"cstdarg": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"filesystem": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"numeric": "cpp",
|
|
||||||
"ranges": "cpp",
|
|
||||||
"set": "cpp",
|
|
||||||
"span": "cpp",
|
|
||||||
"unordered_set": "cpp",
|
|
||||||
"valarray": "cpp",
|
|
||||||
"variant": "cpp",
|
|
||||||
"codecvt": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,17 +5,22 @@ file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
|
|
||||||
#enable objective c support on mac os, needed for wxwidgets and compile for both intel macs and apple sillicon macs
|
#enable objective c support on mac os, needed for wxwidgets and compile for both intel macs and apple sillicon macs
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
list(APPEND SOURCES "src/backends/darwin.mm")
|
list(APPEND SOURCES "src/backends/darwin.mm" ${CMAKE_SOURCE_DIR}/osx/icon.icns)
|
||||||
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
|
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
|
||||||
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
|
||||||
project ("PlayerLink" LANGUAGES C CXX OBJCXX)
|
project ("PlayerLink" LANGUAGES C CXX OBJCXX)
|
||||||
else()
|
else()
|
||||||
project ("PlayerLink" LANGUAGES C CXX)
|
project ("PlayerLink" LANGUAGES C CXX)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND SOURCES ${CMAKE_SOURCE_DIR}/win/app_icon.rc)
|
||||||
|
endif()
|
||||||
|
|
||||||
create_resources("rsrc" "src/rsrc.hpp")
|
create_resources("rsrc" "src/rsrc.hpp")
|
||||||
|
|
||||||
add_executable (PlayerLink ${SOURCES})
|
add_executable (PlayerLink ${SOURCES})
|
||||||
set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 20)
|
set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 17)
|
||||||
add_subdirectory("vendor")
|
add_subdirectory("vendor")
|
||||||
set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono)
|
set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono)
|
||||||
set(INCLUDES vendor vendor/wxWidgets/include)
|
set(INCLUDES vendor vendor/wxWidgets/include)
|
||||||
|
@ -33,6 +38,9 @@ elseif(APPLE)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "MediaRemote framework not found.")
|
message(FATAL_ERROR "MediaRemote framework not found.")
|
||||||
endif()
|
endif()
|
||||||
|
set_target_properties(PlayerLink PROPERTIES MACOSX_BUNDLE TRUE)
|
||||||
|
set_source_files_properties(${CMAKE_SOURCE_DIR}/osx/icon.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
|
||||||
|
set_target_properties(PlayerLink PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/osx/Info.plist)
|
||||||
elseif(UNIX AND NOT APPLE)
|
elseif(UNIX AND NOT APPLE)
|
||||||
list(APPEND LIBRARIES dbus)
|
list(APPEND LIBRARIES dbus)
|
||||||
list(APPEND INCLUDES "${CMAKE_BINARY_DIR}/vendor/dbus" vendor/libdbus)
|
list(APPEND INCLUDES "${CMAKE_BINARY_DIR}/vendor/dbus" vendor/libdbus)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>dev.eintim.playerlink</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>PlayerLink</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>icon</string>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
Binary file not shown.
|
@ -4,30 +4,11 @@
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <dispatch/dispatch.h>
|
#include <dispatch/dispatch.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <format>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "../MediaRemote.hpp"
|
#include "../MediaRemote.hpp"
|
||||||
#include "../backend.hpp"
|
#include "../backend.hpp"
|
||||||
|
|
||||||
#define LAUNCH_AGENT_TEMPLATE \
|
|
||||||
R"(<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>Label</key>
|
|
||||||
<string>{}</string>
|
|
||||||
<key>ProgramArguments</key>
|
|
||||||
<array>
|
|
||||||
<string>{}</string>
|
|
||||||
</array>
|
|
||||||
<key>RunAtLoad</key>
|
|
||||||
<true/>
|
|
||||||
<key>AbandonProcessGroup</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>)"
|
|
||||||
|
|
||||||
void hideDockIcon(bool shouldHide) {
|
void hideDockIcon(bool shouldHide) {
|
||||||
if (shouldHide)
|
if (shouldHide)
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
||||||
|
@ -104,7 +85,16 @@ bool backend::toggleAutostart(bool enabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
NSString *binaryPath = [[[NSProcessInfo processInfo] arguments][0] stringByStandardizingPath];
|
NSString *binaryPath = [[[NSProcessInfo processInfo] arguments][0] stringByStandardizingPath];
|
||||||
std::string formattedPlist = std::format(LAUNCH_AGENT_TEMPLATE, "PlayerLink", binaryPath.UTF8String);
|
|
||||||
|
//I would also like to use std::format here, but well I also want to support older mac os versions.
|
||||||
|
std::string formattedPlist =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
|
||||||
|
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n <dict>\n\n "
|
||||||
|
"<key>Label</key>\n <string>PlayerLink</string>\n <key>ProgramArguments</key>\n <array>\n "
|
||||||
|
"<string>" +
|
||||||
|
std::string(binaryPath.UTF8String) +
|
||||||
|
"</string>\n </array>\n <key>RunAtLoad</key>\n <true/>\n <key>AbandonProcessGroup</key>\n "
|
||||||
|
"<true/>\n </dict>\n</plist>";
|
||||||
std::ofstream o(launchAgentPath);
|
std::ofstream o(launchAgentPath);
|
||||||
o.write(formattedPlist.c_str(), formattedPlist.size());
|
o.write(formattedPlist.c_str(), formattedPlist.size());
|
||||||
o.close();
|
o.close();
|
||||||
|
@ -113,7 +103,7 @@ bool backend::toggleAutostart(bool enabled) {
|
||||||
|
|
||||||
bool backend::init() {
|
bool backend::init() {
|
||||||
hideDockIcon(true);
|
hideDockIcon(true);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef LAUNCH_AGENT_TEMPLATE
|
#undef LAUNCH_AGENT_TEMPLATE
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -258,6 +258,11 @@ public:
|
||||||
class PlayerLink : public wxApp {
|
class PlayerLink : public wxApp {
|
||||||
public:
|
public:
|
||||||
virtual bool OnInit() override {
|
virtual bool OnInit() override {
|
||||||
|
if (!backend::init()) {
|
||||||
|
wxMessageBox(_("Error initializing platform backend!"), _("PlayerLink"), wxOK | wxICON_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (wxSystemSettings::GetAppearance().IsSystemDark()) // To support the native dark mode on windows 10 and up
|
if (wxSystemSettings::GetAppearance().IsSystemDark()) // To support the native dark mode on windows 10 and up
|
||||||
this->SetAppearance(wxAppBase::Appearance::Dark);
|
this->SetAppearance(wxAppBase::Appearance::Dark);
|
||||||
|
|
||||||
|
@ -269,7 +274,7 @@ public:
|
||||||
frame->Hide();
|
frame->Hide();
|
||||||
event.Veto();
|
event.Veto();
|
||||||
} else
|
} else
|
||||||
this->ExitMainLoop();
|
std::exit(0);
|
||||||
});
|
});
|
||||||
wxIcon icon = utils::loadIconFromMemory(icon_png, icon_png_size);
|
wxIcon icon = utils::loadIconFromMemory(icon_png, icon_png_size);
|
||||||
trayIcon->SetIcon(icon, _("PlayerLink"));
|
trayIcon->SetIcon(icon, _("PlayerLink"));
|
||||||
|
@ -283,10 +288,6 @@ private:
|
||||||
wxIMPLEMENT_APP_NO_MAIN(PlayerLink);
|
wxIMPLEMENT_APP_NO_MAIN(PlayerLink);
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (!backend::init()) {
|
|
||||||
wxMessageBox(_("Error initializing platform backend!"), _("PlayerLink"), wxOK | wxICON_ERROR);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
std::thread rpcThread(handleRPCTasks);
|
std::thread rpcThread(handleRPCTasks);
|
||||||
rpcThread.detach();
|
rpcThread.detach();
|
||||||
std::thread mediaThread(handleMediaTasks);
|
std::thread mediaThread(handleMediaTasks);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
IDI_ICON1 ICON "win/icon.ico"
|
Binary file not shown.
After Width: | Height: | Size: 260 KiB |
Loading…
Reference in New Issue