Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
7d4bc6dd89 | |
|
fa29020cea | |
|
36be257462 | |
|
958def7527 |
BIN
img/linux.png
BIN
img/linux.png
Binary file not shown.
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 263 KiB |
BIN
img/macos.png
BIN
img/macos.png
Binary file not shown.
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 692 KiB |
BIN
img/windows.png
BIN
img/windows.png
Binary file not shown.
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 39 KiB |
|
@ -44,13 +44,17 @@ public:
|
||||||
parameters["api_sig"] = getApiSignature(parameters);
|
parameters["api_sig"] = getApiSignature(parameters);
|
||||||
std::string postBody = utils::getURLEncodedPostBody(parameters);
|
std::string postBody = utils::getURLEncodedPostBody(parameters);
|
||||||
std::string response = utils::httpRequest(api_base, "POST", postBody);
|
std::string response = utils::httpRequest(api_base, "POST", postBody);
|
||||||
auto j = nlohmann::json::parse(response);
|
try {
|
||||||
if (j.contains("error"))
|
auto j = nlohmann::json::parse(response);
|
||||||
return j["error"].get<LASTFM_STATUS>();
|
if (j.contains("error"))
|
||||||
|
return j["error"].get<LASTFM_STATUS>();
|
||||||
|
|
||||||
session_token = j["session"]["key"].get<std::string>();
|
session_token = j["session"]["key"].get<std::string>();
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
return LASTFM_STATUS::SUCCESS;
|
return LASTFM_STATUS::SUCCESS;
|
||||||
|
} catch (...) {
|
||||||
|
return LASTFM_STATUS::UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LASTFM_STATUS scrobble(std::string artist, std::string track) {
|
LASTFM_STATUS scrobble(std::string artist, std::string track) {
|
||||||
|
|
48
src/main.cpp
48
src/main.cpp
|
@ -7,6 +7,7 @@
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "backend.hpp"
|
#include "backend.hpp"
|
||||||
|
@ -50,17 +51,22 @@ void initLastFM(bool checkMode = false) {
|
||||||
lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key,
|
lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key,
|
||||||
settings.lastfm.api_secret);
|
settings.lastfm.api_secret);
|
||||||
LastFM::LASTFM_STATUS status = lastfm->authenticate();
|
LastFM::LASTFM_STATUS status = lastfm->authenticate();
|
||||||
if (status)
|
if (status) {
|
||||||
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
|
delete lastfm;
|
||||||
else if (checkMode)
|
lastfm = nullptr;
|
||||||
|
if (checkMode)
|
||||||
|
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
|
||||||
|
} else if (checkMode)
|
||||||
wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);
|
wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMediaTasks() {
|
void handleMediaTasks() {
|
||||||
initLastFM();
|
|
||||||
int64_t lastMs = 0;
|
int64_t lastMs = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
if (!lastfm)
|
||||||
|
initLastFM();
|
||||||
|
|
||||||
auto mediaInformation = backend::getMediaInformation();
|
auto mediaInformation = backend::getMediaInformation();
|
||||||
auto settings = utils::getSettings();
|
auto settings = utils::getSettings();
|
||||||
if (!mediaInformation) {
|
if (!mediaInformation) {
|
||||||
|
@ -87,14 +93,6 @@ void handleMediaTasks() {
|
||||||
if (shouldContinue)
|
if (shouldContinue)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (lastPlayingSong.find(mediaInformation->songTitle + mediaInformation->songArtist +
|
|
||||||
mediaInformation->songAlbum) == std::string::npos &&
|
|
||||||
lastfm)
|
|
||||||
lastfm->scrobble(mediaInformation->songArtist, mediaInformation->songTitle);
|
|
||||||
|
|
||||||
lastPlayingSong = currentlyPlayingSong;
|
|
||||||
currentSongTitle = mediaInformation->songArtist + " - " + mediaInformation->songTitle;
|
|
||||||
|
|
||||||
std::string currentMediaSource = mediaInformation->playbackSource;
|
std::string currentMediaSource = mediaInformation->playbackSource;
|
||||||
|
|
||||||
if (currentMediaSource != lastMediaSource) {
|
if (currentMediaSource != lastMediaSource) {
|
||||||
|
@ -104,6 +102,14 @@ void handleMediaTasks() {
|
||||||
|
|
||||||
auto app = utils::getApp(lastMediaSource);
|
auto app = utils::getApp(lastMediaSource);
|
||||||
|
|
||||||
|
if (lastPlayingSong.find(mediaInformation->songTitle + mediaInformation->songArtist +
|
||||||
|
mediaInformation->songAlbum) == std::string::npos &&
|
||||||
|
lastfm && app.enabled)
|
||||||
|
lastfm->scrobble(mediaInformation->songArtist, mediaInformation->songTitle);
|
||||||
|
|
||||||
|
lastPlayingSong = currentlyPlayingSong;
|
||||||
|
currentSongTitle = mediaInformation->songArtist + " - " + mediaInformation->songTitle;
|
||||||
|
|
||||||
if (!app.enabled) {
|
if (!app.enabled) {
|
||||||
Discord_ClearPresence();
|
Discord_ClearPresence();
|
||||||
continue;
|
continue;
|
||||||
|
@ -154,11 +160,17 @@ void handleMediaTasks() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetWindowIcon(wxTopLevelWindow* win) {
|
||||||
|
const wxIcon icon = utils::loadIconFromMemory(icon_png, icon_png_size);
|
||||||
|
win->SetIcon(icon);
|
||||||
|
}
|
||||||
|
|
||||||
class AboutDialog : public wxDialog {
|
class AboutDialog : public wxDialog {
|
||||||
public:
|
public:
|
||||||
AboutDialog(wxWindow* parent)
|
AboutDialog(wxWindow* parent)
|
||||||
: wxDialog(parent, wxID_ANY, _("About PlayerLink"), wxDefaultPosition, wxDefaultSize,
|
: wxDialog(parent, wxID_ANY, _("About PlayerLink"), wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
|
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
|
||||||
|
SetWindowIcon(this);
|
||||||
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
wxStaticText* label = new wxStaticText(this, wxID_ANY, _("Made with <3 by EinTim"));
|
wxStaticText* label = new wxStaticText(this, wxID_ANY, _("Made with <3 by EinTim"));
|
||||||
label->Wrap(300);
|
label->Wrap(300);
|
||||||
|
@ -192,6 +204,7 @@ public:
|
||||||
EditAppDialog(wxWindow* parent, const wxString title, utils::App* app)
|
EditAppDialog(wxWindow* parent, const wxString title, utils::App* app)
|
||||||
: wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
|
: wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
|
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
|
||||||
|
SetWindowIcon(this);
|
||||||
Bind(wxEVT_CLOSE_WINDOW, &EditAppDialog::OnClose, this);
|
Bind(wxEVT_CLOSE_WINDOW, &EditAppDialog::OnClose, this);
|
||||||
|
|
||||||
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
@ -288,7 +301,7 @@ public:
|
||||||
addButton->SetToolTip(_("Add process to list"));
|
addButton->SetToolTip(_("Add process to list"));
|
||||||
wxBitmapButton* removeButton = new wxBitmapButton(this, wxID_ANY, delete_button_texture);
|
wxBitmapButton* removeButton = new wxBitmapButton(this, wxID_ANY, delete_button_texture);
|
||||||
removeButton->SetToolTip(_("Remove process from list"));
|
removeButton->SetToolTip(_("Remove process from list"));
|
||||||
|
|
||||||
addSizer->Add(processNameInput, 1, wxALL | wxEXPAND, 5);
|
addSizer->Add(processNameInput, 1, wxALL | wxEXPAND, 5);
|
||||||
addSizer->Add(addButton, 0, wxALL, 5);
|
addSizer->Add(addButton, 0, wxALL, 5);
|
||||||
addSizer->Add(removeButton, 0, wxALL, 5);
|
addSizer->Add(removeButton, 0, wxALL, 5);
|
||||||
|
@ -378,12 +391,12 @@ private:
|
||||||
|
|
||||||
class PlayerLinkFrame : public wxFrame {
|
class PlayerLinkFrame : public wxFrame {
|
||||||
public:
|
public:
|
||||||
PlayerLinkFrame(wxWindow* parent, wxIcon& icon, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString,
|
PlayerLinkFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString,
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(300, 200),
|
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(300, 200),
|
||||||
long style = wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER & ~wxMAXIMIZE_BOX)
|
long style = wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER & ~wxMAXIMIZE_BOX)
|
||||||
: wxFrame(parent, id, title, pos, size, style) {
|
: wxFrame(parent, id, title, pos, size, style) {
|
||||||
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
|
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
|
||||||
this->SetIcon(icon);
|
SetWindowIcon(this);
|
||||||
|
|
||||||
auto mainContainer = new wxBoxSizer(wxVERTICAL);
|
auto mainContainer = new wxBoxSizer(wxVERTICAL);
|
||||||
wxPanel* panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
wxPanel* panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||||
|
@ -433,7 +446,6 @@ public:
|
||||||
settings.anyOtherEnabled = isChecked;
|
settings.anyOtherEnabled = isChecked;
|
||||||
utils::saveSettings(settings);
|
utils::saveSettings(settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
wxBitmapButton* addButton = new wxBitmapButton(panel, wxID_ANY, add_button_texture);
|
wxBitmapButton* addButton = new wxBitmapButton(panel, wxID_ANY, add_button_texture);
|
||||||
addButton->SetToolTip(_("Add application"));
|
addButton->SetToolTip(_("Add application"));
|
||||||
|
@ -454,7 +466,6 @@ public:
|
||||||
} else
|
} else
|
||||||
delete app;
|
delete app;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
checkboxRowSizer->Add(anyOtherCheckbox, 1, wxALL | wxALIGN_CENTER_VERTICAL);
|
checkboxRowSizer->Add(anyOtherCheckbox, 1, wxALL | wxALIGN_CENTER_VERTICAL);
|
||||||
checkboxRowSizer->Add(addButton, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
|
checkboxRowSizer->Add(addButton, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
|
||||||
|
@ -666,9 +677,8 @@ public:
|
||||||
this->SetAppearance(wxAppBase::Appearance::Dark);
|
this->SetAppearance(wxAppBase::Appearance::Dark);
|
||||||
|
|
||||||
wxInitAllImageHandlers();
|
wxInitAllImageHandlers();
|
||||||
wxIcon icon = utils::loadIconFromMemory(icon_png, icon_png_size);
|
|
||||||
wxIcon tray_icon = utils::loadIconFromMemory(menubar_icon_png, menubar_icon_png_size);
|
wxIcon tray_icon = utils::loadIconFromMemory(menubar_icon_png, menubar_icon_png_size);
|
||||||
PlayerLinkFrame* frame = new PlayerLinkFrame(nullptr, icon, wxID_ANY, _("PlayerLink"));
|
PlayerLinkFrame* frame = new PlayerLinkFrame(nullptr, wxID_ANY, _("PlayerLink"));
|
||||||
trayIcon = new PlayerLinkIcon(frame);
|
trayIcon = new PlayerLinkIcon(frame);
|
||||||
frame->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& event) {
|
frame->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& event) {
|
||||||
if (event.CanVeto()) {
|
if (event.CanVeto()) {
|
||||||
|
|
Loading…
Reference in New Issue