Compare commits
No commits in common. "main" and "v1.3" have entirely different histories.
BIN
img/linux.png
BIN
img/linux.png
Binary file not shown.
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 42 KiB |
BIN
img/macos.png
BIN
img/macos.png
Binary file not shown.
Before Width: | Height: | Size: 692 KiB After Width: | Height: | Size: 135 KiB |
BIN
img/windows.png
BIN
img/windows.png
Binary file not shown.
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 53 KiB |
|
@ -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) {
|
||||
|
|
46
src/main.cpp
46
src/main.cpp
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -447,6 +434,7 @@ public:
|
|||
utils::saveSettings(settings);
|
||||
});
|
||||
|
||||
|
||||
wxBitmapButton* addButton = new wxBitmapButton(panel, wxID_ANY, add_button_texture);
|
||||
addButton->SetToolTip(_("Add application"));
|
||||
addButton->Bind(wxEVT_BUTTON, [this, panel, frameSizer, size, delete_button_texture, edit_button_texture,
|
||||
|
@ -467,6 +455,7 @@ public:
|
|||
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()) {
|
||||
|
|
Loading…
Reference in New Issue