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);
std::string postBody = utils::getURLEncodedPostBody(parameters);
std::string response = utils::httpRequest(api_base, "POST", postBody);
try {
auto j = nlohmann::json::parse(response);
if (j.contains("error"))
return j["error"].get<LASTFM_STATUS>();
auto j = nlohmann::json::parse(response);
if (j.contains("error"))
return j["error"].get<LASTFM_STATUS>();
session_token = j["session"]["key"].get<std::string>();
authenticated = true;
return LASTFM_STATUS::SUCCESS;
} catch (...) {
return LASTFM_STATUS::UNKNOWN_ERROR;
}
session_token = j["session"]["key"].get<std::string>();
authenticated = true;
return LASTFM_STATUS::SUCCESS;
}
LASTFM_STATUS scrobble(std::string artist, std::string track) {

View File

@ -7,7 +7,6 @@
#include <wx/wx.h>
#include <chrono>
#include <cstddef>
#include <thread>
#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,
settings.lastfm.api_secret);
LastFM::LASTFM_STATUS status = lastfm->authenticate();
if (status) {
delete lastfm;
lastfm = nullptr;
if (checkMode)
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
} else if (checkMode)
if (status)
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
else if (checkMode)
wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);
}
void handleMediaTasks() {
initLastFM();
int64_t lastMs = 0;
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
if (!lastfm)
initLastFM();
auto mediaInformation = backend::getMediaInformation();
auto settings = utils::getSettings();
if (!mediaInformation) {
@ -93,6 +87,14 @@ void handleMediaTasks() {
if (shouldContinue)
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;
if (currentMediaSource != lastMediaSource) {
@ -102,14 +104,6 @@ void handleMediaTasks() {
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) {
Discord_ClearPresence();
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 {
public:
AboutDialog(wxWindow* parent)
: wxDialog(parent, wxID_ANY, _("About PlayerLink"), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
SetWindowIcon(this);
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText* label = new wxStaticText(this, wxID_ANY, _("Made with <3 by EinTim"));
label->Wrap(300);
@ -204,7 +192,6 @@ public:
EditAppDialog(wxWindow* parent, const wxString title, utils::App* app)
: wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE & ~wxRESIZE_BORDER) {
SetWindowIcon(this);
Bind(wxEVT_CLOSE_WINDOW, &EditAppDialog::OnClose, this);
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
@ -301,7 +288,7 @@ public:
addButton->SetToolTip(_("Add process to list"));
wxBitmapButton* removeButton = new wxBitmapButton(this, wxID_ANY, delete_button_texture);
removeButton->SetToolTip(_("Remove process from list"));
addSizer->Add(processNameInput, 1, wxALL | wxEXPAND, 5);
addSizer->Add(addButton, 0, wxALL, 5);
addSizer->Add(removeButton, 0, wxALL, 5);
@ -391,12 +378,12 @@ private:
class PlayerLinkFrame : public wxFrame {
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),
long style = wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER & ~wxMAXIMIZE_BOX)
: wxFrame(parent, id, title, pos, size, style) {
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
SetWindowIcon(this);
this->SetIcon(icon);
auto mainContainer = new wxBoxSizer(wxVERTICAL);
wxPanel* panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
@ -446,6 +433,7 @@ public:
settings.anyOtherEnabled = isChecked;
utils::saveSettings(settings);
});
wxBitmapButton* addButton = new wxBitmapButton(panel, wxID_ANY, add_button_texture);
addButton->SetToolTip(_("Add application"));
@ -466,6 +454,7 @@ public:
} else
delete app;
});
checkboxRowSizer->Add(anyOtherCheckbox, 1, wxALL | wxALIGN_CENTER_VERTICAL);
checkboxRowSizer->Add(addButton, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
@ -677,8 +666,9 @@ public:
this->SetAppearance(wxAppBase::Appearance::Dark);
wxInitAllImageHandlers();
wxIcon icon = utils::loadIconFromMemory(icon_png, 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);
frame->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& event) {
if (event.CanVeto()) {