Save config in a proper location
This commit is contained in:
parent
7b5666a906
commit
26af0323f2
13
README.md
13
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.
|
||||
|
||||
<p align="center" width="100%">
|
||||
<img src="img/showcase.png" alt="rich presence" />
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
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<MediaInfo> getMediaInformation();
|
||||
} // namespace backend
|
||||
|
||||
|
|
|
@ -77,6 +77,12 @@ std::shared_ptr<MediaInfo> 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";
|
||||
|
|
|
@ -215,6 +215,12 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
|||
return std::make_shared<MediaInfo>(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");
|
||||
|
||||
|
|
|
@ -54,6 +54,12 @@ 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";
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue