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
|
- Pretty much any linux distribution with gtk3 and dbus support
|
||||||
|
|
||||||
## Showcase
|
## 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%">
|
<p align="center" width="100%">
|
||||||
<img src="img/showcase.png" alt="rich presence" />
|
<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
|
### 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.
|
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
|
## Config
|
||||||
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.
|
**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
|
## Building
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
struct MediaInfo {
|
struct MediaInfo {
|
||||||
bool paused;
|
bool paused;
|
||||||
|
@ -30,6 +31,7 @@ struct MediaInfo {
|
||||||
namespace backend {
|
namespace backend {
|
||||||
bool init();
|
bool init();
|
||||||
bool toggleAutostart(bool enabled);
|
bool toggleAutostart(bool enabled);
|
||||||
|
std::filesystem::path getConfigDirectory();
|
||||||
std::shared_ptr<MediaInfo> getMediaInformation();
|
std::shared_ptr<MediaInfo> getMediaInformation();
|
||||||
} // namespace backend
|
} // namespace backend
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,12 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||||
durationMs, elapsedTimeMs);
|
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) {
|
bool backend::toggleAutostart(bool enabled) {
|
||||||
std::filesystem::path launchAgentPath = std::getenv("HOME");
|
std::filesystem::path launchAgentPath = std::getenv("HOME");
|
||||||
launchAgentPath = launchAgentPath / "Library" / "LaunchAgents";
|
launchAgentPath = launchAgentPath / "Library" / "LaunchAgents";
|
||||||
|
|
|
@ -215,6 +215,12 @@ std::shared_ptr<MediaInfo> backend::getMediaInformation() {
|
||||||
return std::make_shared<MediaInfo>(ret);
|
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) {
|
bool backend::toggleAutostart(bool enabled) {
|
||||||
const char* xdgHome = std::getenv("XDG_CONFIG_HOME");
|
const char* xdgHome = std::getenv("XDG_CONFIG_HOME");
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,18 @@ bool CreateShortcut(std::string source, std::string target) {
|
||||||
return SUCCEEDED(hr);
|
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) {
|
bool backend::toggleAutostart(bool enabled) {
|
||||||
std::filesystem::path shortcutPath = std::getenv("APPDATA");
|
std::filesystem::path shortcutPath = std::getenv("APPDATA");
|
||||||
shortcutPath = shortcutPath / "Microsoft" / "Windows" / "Start Menu" / "Programs" / "Startup";
|
shortcutPath = shortcutPath / "Microsoft" / "Windows" / "Start Menu" / "Programs" / "Startup";
|
||||||
std::filesystem::create_directories(shortcutPath);
|
std::filesystem::create_directories(shortcutPath);
|
||||||
shortcutPath = shortcutPath / "PlayerLink.lnk";
|
shortcutPath = shortcutPath / "PlayerLink.lnk";
|
||||||
|
|
||||||
if (!enabled && std::filesystem::exists(shortcutPath)) {
|
if (!enabled && std::filesystem::exists(shortcutPath)) {
|
||||||
std::filesystem::remove(shortcutPath);
|
std::filesystem::remove(shortcutPath);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,9 +11,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "backend.hpp"
|
||||||
|
|
||||||
#define DEFAULT_CLIENT_ID "1301849203378622545"
|
#define DEFAULT_CLIENT_ID "1301849203378622545"
|
||||||
#define DEFAULT_APP_NAME "Music"
|
#define DEFAULT_APP_NAME "Music"
|
||||||
#define CONFIG_FILENAME "settings.json"
|
#define CONFIG_FILENAME backend::getConfigDirectory() / "settings.json"
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
struct App {
|
struct App {
|
||||||
|
@ -177,9 +179,14 @@ namespace utils {
|
||||||
o.close();
|
o.close();
|
||||||
}
|
}
|
||||||
inline Settings getSettings() {
|
inline Settings getSettings() {
|
||||||
|
std::filesystem::create_directories(backend::getConfigDirectory());
|
||||||
Settings ret;
|
Settings ret;
|
||||||
if (!std::filesystem::exists(CONFIG_FILENAME))
|
if (!std::filesystem::exists(CONFIG_FILENAME)) {
|
||||||
|
ret.anyOtherEnabled = true;
|
||||||
|
ret.autoStart = false;
|
||||||
|
saveSettings(ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::ifstream i(CONFIG_FILENAME);
|
std::ifstream i(CONFIG_FILENAME);
|
||||||
|
@ -200,8 +207,7 @@ namespace utils {
|
||||||
|
|
||||||
ret.apps.push_back(a);
|
ret.apps.push_back(a);
|
||||||
}
|
}
|
||||||
} catch (const nlohmann::json::parse_error&) {
|
} catch (const nlohmann::json::parse_error&) {}
|
||||||
} // TODO: handle error
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue