diff --git a/README.md b/README.md
index 367e93b..77fcffe 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Cross platform, universal discord rich presence for media players.
- Pretty much any linux distribution with gtk3 and dbus support
## Showcase
-You can add predefined players to the settings.json to customise the name it shows in discord, edit the search button base url, and app icon. By default it will just display as "Music" without a search button or app icon. In the future I want to add an option to the ui to add custom apps.
+You can add predefined players to the settings.json to customise the name it shows in discord, edit the search button base url, and app icon. By default it will just display as "Music" without a search button or app icon.
@@ -32,8 +32,15 @@ The Mac OS backend is powered by the private MediaRemote framework. It provides
### Linux
The linux backend is powered by [MPRIS](https://specifications.freedesktop.org/mpris-spec/latest/). It allows to query the system wide media information via dbus.
-## Adding custom apps to the settings.json
-The config is currently located in the same folder as PlayerLink, this will be changed in a future release. An example on how to add custom apps to the json can be found [here](./settings.example.json). In the future there will be a UI to configure custom apps in a more user friendly way.
+## Config
+**Mac OS**
+`~/Library/Application Support/PlayerLink`
+**Linux**
+`~/.config/PlayerLink`
+**Windows**
+`%appdata%\PlayerLink`
+
+An example on how to add custom apps to the config can be found [here](./settings.example.json). In the future there will be a UI to configure custom apps in a more user friendly way.
## Building
diff --git a/src/backend.hpp b/src/backend.hpp
index 4d2eeef..4e40011 100644
--- a/src/backend.hpp
+++ b/src/backend.hpp
@@ -4,6 +4,7 @@
#include
#include
+#include
struct MediaInfo {
bool paused;
@@ -30,6 +31,7 @@ struct MediaInfo {
namespace backend {
bool init();
bool toggleAutostart(bool enabled);
+ std::filesystem::path getConfigDirectory();
std::shared_ptr getMediaInformation();
} // namespace backend
diff --git a/src/backends/darwin.mm b/src/backends/darwin.mm
index 7eccb3e..ee947b0 100644
--- a/src/backends/darwin.mm
+++ b/src/backends/darwin.mm
@@ -77,6 +77,12 @@ std::shared_ptr backend::getMediaInformation() {
durationMs, elapsedTimeMs);
}
+std::filesystem::path backend::getConfigDirectory() {
+ std::filesystem::path configDirectoryPath = std::getenv("HOME");
+ configDirectoryPath = configDirectoryPath / "Library" / "Application Support" / "PlayerLink";
+ return configDirectoryPath;
+}
+
bool backend::toggleAutostart(bool enabled) {
std::filesystem::path launchAgentPath = std::getenv("HOME");
launchAgentPath = launchAgentPath / "Library" / "LaunchAgents";
diff --git a/src/backends/linux.cpp b/src/backends/linux.cpp
index 4737728..6b91b30 100644
--- a/src/backends/linux.cpp
+++ b/src/backends/linux.cpp
@@ -215,6 +215,12 @@ std::shared_ptr backend::getMediaInformation() {
return std::make_shared(ret);
}
+std::filesystem::path backend::getConfigDirectory() {
+ std::filesystem::path configDirectoryPath = std::getenv("HOME");
+ configDirectoryPath = configDirectoryPath / ".config" / "PlayerLink";
+ return configDirectoryPath;
+}
+
bool backend::toggleAutostart(bool enabled) {
const char* xdgHome = std::getenv("XDG_CONFIG_HOME");
diff --git a/src/backends/windows.cpp b/src/backends/windows.cpp
index 8365cad..cef49e2 100644
--- a/src/backends/windows.cpp
+++ b/src/backends/windows.cpp
@@ -54,12 +54,18 @@ bool CreateShortcut(std::string source, std::string target) {
return SUCCEEDED(hr);
}
+std::filesystem::path backend::getConfigDirectory() {
+ std::filesystem::path configDirectoryPath = std::getenv("APPDATA");
+ configDirectoryPath = configDirectoryPath / "PlayerLink";
+ return configDirectoryPath;
+}
+
bool backend::toggleAutostart(bool enabled) {
std::filesystem::path shortcutPath = std::getenv("APPDATA");
shortcutPath = shortcutPath / "Microsoft" / "Windows" / "Start Menu" / "Programs" / "Startup";
std::filesystem::create_directories(shortcutPath);
shortcutPath = shortcutPath / "PlayerLink.lnk";
-
+
if (!enabled && std::filesystem::exists(shortcutPath)) {
std::filesystem::remove(shortcutPath);
return true;
diff --git a/src/utils.hpp b/src/utils.hpp
index 213b869..9677c07 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -11,9 +11,11 @@
#include
#include
+#include "backend.hpp"
+
#define DEFAULT_CLIENT_ID "1301849203378622545"
#define DEFAULT_APP_NAME "Music"
-#define CONFIG_FILENAME "settings.json"
+#define CONFIG_FILENAME backend::getConfigDirectory() / "settings.json"
namespace utils {
struct App {
@@ -177,9 +179,14 @@ namespace utils {
o.close();
}
inline Settings getSettings() {
+ std::filesystem::create_directories(backend::getConfigDirectory());
Settings ret;
- if (!std::filesystem::exists(CONFIG_FILENAME))
+ if (!std::filesystem::exists(CONFIG_FILENAME)) {
+ ret.anyOtherEnabled = true;
+ ret.autoStart = false;
+ saveSettings(ret);
return ret;
+ }
try {
std::ifstream i(CONFIG_FILENAME);
@@ -200,8 +207,7 @@ namespace utils {
ret.apps.push_back(a);
}
- } catch (const nlohmann::json::parse_error&) {
- } // TODO: handle error
+ } catch (const nlohmann::json::parse_error&) {}
return ret;
}