Finished mac os support

This commit is contained in:
EinTim23 2024-11-06 13:01:34 +01:00
parent ab09fa1a6f
commit 26c1e8cc8a
9 changed files with 48 additions and 119 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ build/*
.DS_Store
.cache/*
src/rsrc.hpp
PlayerLink.exe
PlayerLink.exe
.vscode/*

90
.vscode/settings.json vendored
View File

@ -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"
}
}

View File

@ -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
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_DEPLOYMENT_TARGET "10.15")
project ("PlayerLink" LANGUAGES C CXX OBJCXX)
else()
project ("PlayerLink" LANGUAGES C CXX)
endif()
if(WIN32)
list(APPEND SOURCES ${CMAKE_SOURCE_DIR}/win/app_icon.rc)
endif()
create_resources("rsrc" "src/rsrc.hpp")
add_executable (PlayerLink ${SOURCES})
set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 20)
set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 17)
add_subdirectory("vendor")
set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono)
set(INCLUDES vendor vendor/wxWidgets/include)
@ -33,6 +38,9 @@ elseif(APPLE)
else()
message(FATAL_ERROR "MediaRemote framework not found.")
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)
list(APPEND LIBRARIES dbus)
list(APPEND INCLUDES "${CMAKE_BINARY_DIR}/vendor/dbus" vendor/libdbus)

18
osx/Info.plist Normal file
View File

@ -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>

BIN
osx/icon.icns Normal file

Binary file not shown.

View File

@ -4,30 +4,11 @@
#include <Foundation/Foundation.h>
#include <dispatch/dispatch.h>
#include <filesystem>
#include <format>
#include <fstream>
#include "../MediaRemote.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) {
if (shouldHide)
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
@ -104,7 +85,16 @@ bool backend::toggleAutostart(bool enabled) {
return true;
}
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);
o.write(formattedPlist.c_str(), formattedPlist.size());
o.close();
@ -113,7 +103,7 @@ bool backend::toggleAutostart(bool enabled) {
bool backend::init() {
hideDockIcon(true);
return true;
return false;
}
#undef LAUNCH_AGENT_TEMPLATE

View File

@ -258,6 +258,11 @@ public:
class PlayerLink : public wxApp {
public:
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
this->SetAppearance(wxAppBase::Appearance::Dark);
@ -269,7 +274,7 @@ public:
frame->Hide();
event.Veto();
} else
this->ExitMainLoop();
std::exit(0);
});
wxIcon icon = utils::loadIconFromMemory(icon_png, icon_png_size);
trayIcon->SetIcon(icon, _("PlayerLink"));
@ -283,10 +288,6 @@ 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);

1
win/app_icon.rc Normal file
View File

@ -0,0 +1 @@
IDI_ICON1 ICON "win/icon.ico"

BIN
win/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 KiB