Skip to content

Commit

Permalink
fix: Indiquer que Kodi v19+ est nécessaire.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Sep 10, 2021
1 parent 56f9bfc commit 88be23e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 30 deletions.
7 changes: 7 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
}
},

"notifications_notSupported_title": {
"message": "Kodi version not supported"
},
"notifications_notSupported_message": {
"message": "Kodi version 19 (Matrix) is required."
},

"notifications_noLink_title": {
"message": "Unsupported link"
},
Expand Down
7 changes: 7 additions & 0 deletions src/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
}
},

"notifications_notSupported_title": {
"message": "Version de Kodi non supportée"
},
"notifications_notSupported_message": {
"message": "La version 19 (Matrix) de Kodi est nécessaire."
},

"notifications_noLink_title": {
"message": "Lien invalide"
},
Expand Down
7 changes: 7 additions & 0 deletions src/_locales/sk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
}
},

"notifications_notSupported_title": {
"message": "Nepodporovaná verzia Kodi"
},
"notifications_notSupported_message": {
"message": "Je potrebná verzia Kodi 19 (Matrix)."
},

"notifications_noLink_title": {
"message": "Nepodporovaný odkaz"
},
Expand Down
8 changes: 1 addition & 7 deletions src/core/jsonrpc/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,7 @@ export const Application = class {
}
switch (method) {
case "Application.OnVolumeChanged":
this.onPropertyChanged.dispatch({
...data,
// Convertir le volume en entier.
// https://github.com/xbmc/xbmc/issues/17894.
..."volume" in data ? { volume: Math.trunc(data.volume) }
: {},
});
this.onPropertyChanged.dispatch(data);
break;
default:
// Ignorer les autres notifications.
Expand Down
19 changes: 15 additions & 4 deletions src/core/jsonrpc/kodi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { Input } from "./input.js";
import { Player } from "./player.js";
import { Playlist } from "./playlist.js";

/**
* La version minimale de l'API JSON-RPC de Kodi nécessaire.
*
* @type {number}
*/
const KODI_JSONRPC_API_VERSION = 12;

/**
* Le client JSON-RPC pour contacter Kodi.
*
Expand All @@ -18,18 +25,22 @@ import { Playlist } from "./playlist.js";
export const Kodi = class {

/**
* Vérifie la connexion à Kodi.
* Vérifie la connexion et la version de Kodi.
*
* @param {string} address L'adresse IP ou l'adresse complète du service de
* Kodi.
* @returns {Promise<Object>} Une promesse tenue si Kodi est accessible ;
* sinon une promesse rompue.
* @returns {Promise<string>} Une promesse contenant <code>"OK"</code> si
* Kodi est accessible et a une version
* supportée ;
*/
static async check(address) {
const kodi = new Kodi(address);
const result = await kodi.send("JSONRPC.Version");
kodi.close();
return result;
if (KODI_JSONRPC_API_VERSION > result.version.major) {
throw new PebkacError("notSupported");
}
return "OK";
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/core/jsonrpc/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ export const Player = class {
* seconde.
*/
async seek(time) {
// Attention ! Kodi n'accepte pas des positions supérieures à 24h.
// https://github.com/xbmc/xbmc/issues/17907
const result = await this._kodi.send("Player.Seek", {
playerid: 1,
value: { time: toTime(time) },
Expand Down
2 changes: 1 addition & 1 deletion src/options/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const check = async function (input) {
// renseignée. Si une autre valeur est en cours de vérification :
// ignorer cette erreur.
if (address === input.value) {
if ("notFound" === err.type) {
if ("notFound" === err.type || "notSupported" === err.type) {
input.title = err.message;
input.style.backgroundImage =
`url("/design/icon/warning-yellow.svg")`;
Expand Down
15 changes: 1 addition & 14 deletions test/unit/core/jsonrpc/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,7 @@ describe("core/jsonrpc/application.js", function () {
});
application.handleNotification({
method: "Application.OnVolumeChanged",
params: { data: { foo: "bar", volume: 98.7 } },
});
assert.fail();
});

it("should handle 'OnVolumeChanged' without volume", function (done) {
const application = new Application({ send: Function.prototype });
application.onPropertyChanged.addListener((data) => {
assert.deepStrictEqual(data, { muted: true });
done();
});
application.handleNotification({
method: "Application.OnVolumeChanged",
params: { data: { muted: true } },
params: { data: { foo: "bar", volume: 98 } },
});
assert.fail();
});
Expand Down
31 changes: 29 additions & 2 deletions test/unit/core/jsonrpc/kodi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,43 @@ describe("core/jsonrpc/kodi.js", function () {
});
});

it("should return promise rejected with old version",
async function () {
const fake = sinon.fake.resolves({ version: { major: 11 } });
const stub = sinon.stub(JSONRPC, "open").resolves({
addEventListener: () => {},
send: fake,
close: () => {},
});

await assert.rejects(() => Kodi.check("foo.com"), {
name: "PebkacError",
type: "notSupported",
});

assert.strictEqual(stub.callCount, 1);
assert.deepStrictEqual(stub.firstCall.args, [
new URL("ws://foo.com:9090/jsonrpc"),
]);
assert.strictEqual(fake.callCount, 1);
assert.deepStrictEqual(fake.firstCall.args, [
"JSONRPC.Version",
undefined,
]);

stub.restore();
});

it("should return promise fulfilled", async function () {
const fake = sinon.fake.resolves({ bar: "baz" });
const fake = sinon.fake.resolves({ version: { major: 12 } });
const stub = sinon.stub(JSONRPC, "open").resolves({
addEventListener: () => {},
send: fake,
close: () => {},
});

const result = await Kodi.check("foo.com");
assert.deepStrictEqual(result, { bar: "baz" });
assert.strictEqual(result, "OK");

assert.strictEqual(stub.callCount, 1);
assert.deepStrictEqual(stub.firstCall.args, [
Expand Down

0 comments on commit 88be23e

Please sign in to comment.