Skip to content

Commit 9d0bd40

Browse files
committed
Fix req for Plex player clients to be available during auth.
Fixes #48. Previously, if no player clients were found during the setup process, the authorization would fail and quit. Now, if no players are found, the authorization process continues without saving a default player. This allows things like checking what's On Deck and Recently Added to work without a default player saved.
1 parent ef996a9 commit 9d0bd40

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

lib/states/not-authed.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,21 @@ var setupIntent = function(request, response) {
101101
if (result === 'authorized') {
102102
db.updateAuthToken(app.user, app.plex.pinAuth.token).then(function() {
103103
app.user.setupDefaults(true).then(function() {
104-
response.say("Congratulations! I am now linked to your Plex account. To save you some time, I went ahead and made some " +
105-
"assumptions about which server and which player you want to use. For the server, I picked " + app.user.serverName +
106-
". And for the player, I picked " + app.user.playerName + ". If you'd like to change this, simply say 'Alexa, ask " +
107-
"" + app.INVOCATION_NAME + " to change some settings.");
104+
var responseText = "Congratulations! I am now linked to your Plex account. To save you some time, I went ahead and made some " +
105+
"assumptions about which server and which player you want to use.";
106+
107+
if (app.user.serverName) {
108+
responseText += " For the server, I picked " + app.user.serverName + "."
109+
}
110+
111+
if (app.user.playerName) {
112+
responseText += " And for the player, I picked " + app.user.playerName + ".";
113+
}
114+
115+
responseText += " If you'd like to change this, simply say 'Alexa, ask " +
116+
"" + app.INVOCATION_NAME + " to change some settings.";
117+
118+
response.say(responseText);
108119
return response.send();
109120
});
110121
}).catch(function(err) {

lib/user.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ var User = function(app, dbobject) {
131131

132132
Object.defineProperty(this, 'playerName', {
133133
get: function() {
134-
return context.dbobject.player.name;
134+
if (context.dbobject.player) {
135+
return context.dbobject.player.name;
136+
} else {
137+
return null;
138+
}
135139
}
136140
});
137141

@@ -199,10 +203,14 @@ User.prototype.setDefaultPlayer = function(forceReset) {
199203
if (!this.player || forceReset) {
200204
return plexutils.getPlayers(context._app)
201205
.then(function(players) {
202-
return db.updateUserPlayer(context, players[0])
203-
.then(function() {
204-
return true;
205-
})
206+
if (players && players.length) {
207+
return db.updateUserPlayer(context, players[0])
208+
.then(function() {
209+
return true;
210+
})
211+
} else {
212+
return Q.resolve(true);
213+
}
206214
})
207215
}
208216

0 commit comments

Comments
 (0)