diff --git a/.gitignore b/.gitignore index 5475bbd..69f8986 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build/* .DS_Store .cache/* src/rsrc.hpp -PlayerLink.exe \ No newline at end of file +PlayerLink.exe +.vscode/* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index adae005..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -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" - } -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a61dcc7..ef2b4da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/osx/Info.plist b/osx/Info.plist new file mode 100644 index 0000000..31b0816 --- /dev/null +++ b/osx/Info.plist @@ -0,0 +1,18 @@ + + + + + CFBundleIdentifier + dev.eintim.playerlink + CFBundleName + PlayerLink + CFBundleVersion + 1.0 + CFBundleShortVersionString + 1.0 + CFBundleIconFile + icon + NSHighResolutionCapable + + + diff --git a/osx/icon.icns b/osx/icon.icns new file mode 100644 index 0000000..7bb9cb3 Binary files /dev/null and b/osx/icon.icns differ diff --git a/src/backends/darwin.mm b/src/backends/darwin.mm index 835a547..6c587f5 100644 --- a/src/backends/darwin.mm +++ b/src/backends/darwin.mm @@ -4,30 +4,11 @@ #include #include #include -#include #include #include "../MediaRemote.hpp" #include "../backend.hpp" -#define LAUNCH_AGENT_TEMPLATE \ - R"( - - - - Label - {} - ProgramArguments - - {} - - RunAtLoad - - AbandonProcessGroup - - -)" - 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 = + "\n\n\n \n\n " + "Label\n PlayerLink\n ProgramArguments\n \n " + "" + + std::string(binaryPath.UTF8String) + + "\n \n RunAtLoad\n \n AbandonProcessGroup\n " + "\n \n"; 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 diff --git a/src/main.cpp b/src/main.cpp index 53794de..4854874 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/win/app_icon.rc b/win/app_icon.rc new file mode 100644 index 0000000..cfc93e2 --- /dev/null +++ b/win/app_icon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "win/icon.ico" \ No newline at end of file diff --git a/win/icon.ico b/win/icon.ico new file mode 100644 index 0000000..70a651c Binary files /dev/null and b/win/icon.ico differ