Compare commits

..

No commits in common. "main" and "v1.3" have entirely different histories.
main ... v1.3

5 changed files with 25 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 KiB

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -44,17 +44,13 @@ 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);
try { auto j = nlohmann::json::parse(response);
auto j = nlohmann::json::parse(response); if (j.contains("error"))
if (j.contains("error")) return j["error"].get<LASTFM_STATUS>();
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) {

View File

@ -7,7 +7,6 @@
#include <wx/wx.h> #include <wx/wx.h>
#include <chrono> #include <chrono>
#include <cstddef>
#include <thread> #include <thread>
#include "backend.hpp" #include "backend.hpp"
@ -51,22 +50,17 @@ 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)
delete lastfm; wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
lastfm = nullptr; else if (checkMode)
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) {
@ -93,6 +87,14 @@ 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) {
@ -102,14 +104,6 @@ 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;
@ -160,17 +154,11 @@ 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);
@ -204,7 +192,6 @@ 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);
@ -391,12 +378,12 @@ private:
class PlayerLinkFrame : public wxFrame { class PlayerLinkFrame : public wxFrame {
public: public:
PlayerLinkFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, PlayerLinkFrame(wxWindow* parent, wxIcon& icon, 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);
SetWindowIcon(this); this->SetIcon(icon);
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);
@ -447,6 +434,7 @@ public:
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"));
addButton->Bind(wxEVT_BUTTON, [this, panel, frameSizer, size, delete_button_texture, edit_button_texture, addButton->Bind(wxEVT_BUTTON, [this, panel, frameSizer, size, delete_button_texture, edit_button_texture,
@ -467,6 +455,7 @@ public:
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);
@ -677,8 +666,9 @@ 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, wxID_ANY, _("PlayerLink")); PlayerLinkFrame* frame = new PlayerLinkFrame(nullptr, icon, 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()) {