aboutsummaryrefslogtreecommitdiff
path: root/mpc-bar.m
diff options
context:
space:
mode:
authorSpencer Williams <spnw@plexwave.org>2025-07-10 21:38:17 -0400
committerSpencer Williams <spnw@plexwave.org>2025-07-10 21:41:47 -0400
commit24e74445453d50f24dac9dd6432bc4bc83702a29 (patch)
treef24b6f15ef59e04b6182b2580caaeb22a1c0648b /mpc-bar.m
parent875bde4ee716c90399f94c2dc4300ec85e7869e1 (diff)
Add password supportHEADv0.4main
Diffstat (limited to 'mpc-bar.m')
-rw-r--r--mpc-bar.m19
1 files changed, 16 insertions, 3 deletions
diff --git a/mpc-bar.m b/mpc-bar.m
index 3892e9b..c9decd4 100644
--- a/mpc-bar.m
+++ b/mpc-bar.m
@@ -29,7 +29,7 @@
#include "ini.h"
#include "mpc/song_format.h"
-#define VERSION "0.3"
+#define VERSION "0.4"
#define TITLE_MAX_LENGTH 96
#define SLEEP_INTERVAL 0.2
@@ -48,7 +48,7 @@ static NSString *formatTime(unsigned int t) {
}
struct config {
- const char *host, *format, *idle_message;
+ const char *host, *password, *format, *idle_message;
int show_queue, show_queue_idle;
unsigned port;
};
@@ -61,6 +61,8 @@ static int handler(void *userdata, const char *section, const char *name,
c->host = strdup(value);
} else if (MATCH("connection", "port")) {
c->port = atoi(value);
+ } else if (MATCH("connection", "password")) {
+ c->password = strdup(value);
} else if (MATCH("display", "format")) {
c->format = strdup(value);
} else if (MATCH("display", "idle_message")) {
@@ -84,6 +86,7 @@ static int handler(void *userdata, const char *section, const char *name,
struct mpd_connection *connection;
BOOL songMenuNeedsUpdate;
+ NSString *errorMessage;
NSMenu *controlMenu;
NSMenuItem *timeItem, *timeSeparator, *playPauseItem, *stopItem, *nextItem,
*previousItem, *singleItem, *clearItem, *updateDatabaseItem,
@@ -123,6 +126,16 @@ static int handler(void *userdata, const char *section, const char *name,
exit(1);
}
+ errorMessage = @"Failed to get status (is MPD running?)";
+
+ if (mpd_connection_get_error(connection) == MPD_ERROR_SUCCESS) {
+ if (config.password != NULL) {
+ if (!mpd_run_password(connection, config.password)) {
+ errorMessage = @"Auth failed (please fix password and restart service)";
+ }
+ }
+ }
+
songMenuNeedsUpdate = YES;
}
- (void)disconnect {
@@ -146,7 +159,7 @@ static int handler(void *userdata, const char *section, const char *name,
[NSThread sleepForTimeInterval:SLEEP_INTERVAL];
if (!connection) {
[self disableAllItems];
- [self showError:@"Failed to get status (is MPD running?)"];
+ [self showError:errorMessage];
[self connect];
}
if (!mpd_send_idle(connection)) {