Hi @ben,
I’m running into an issue with the settings API and I hope you can help me.
The issue is that opening the settings of extension A and then switching to the settings of extension B can make the remote crash. Whether it crashes seems to depend on the settings layout, especially the use of groups seems to be relevant.
I have been trying to track this issue down for a couple of hours, and at this point my impression is that the issue is not in my code. I succeeded in isolation the issue by creating 2 very basic extensions. I hope that you can reproduce the issue by running these extensions from the code below.
The steps I take are:
- Open the settings of extension 2 and open the drop down item
- Cancel the dialog by pressing outside the dialog (all is well)
- Open the settings of extension 1 and open the drop down item
- Cancel the dialog by pressing outside the dialog (all is well)
- Open the settings of extension 2 and try to open the drop down item (remote crashes)
I noticed that placing the zone picker of extension 1 in a group prevents the crash.
Extension 1:
"use strict";
var RoonApi = require("node-roon-api"),
RoonApiSettings = require('node-roon-api-settings');
var core = undefined;
var roon = new RoonApi({
extension_id: 'com.example.1',
display_name: 'Example 1',
display_version: '0.1.0',
publisher: 'Example',
email: 'one@example.com',
core_paired: function(core_) {
core = core_;
},
core_unpaired: function(core_) {
core = undefined;
}
});
var my_settings = roon.load_config("settings") || {
};
function makelayout(settings) {
let l = {
values: settings,
layout: [],
has_error: false
};
l.layout.push({
type: "zone",
title: "Zone",
setting: "zone"
});
return l;
}
var svc_settings = new RoonApiSettings(roon, {
get_settings: function(cb) {
cb(makelayout(my_settings));
},
save_settings: function(req, isdryrun, settings) {
let l = makelayout(settings.values);
req.send_complete(l.has_error ? "NotValid" : "Success", { settings: l });
if (!isdryrun && !l.has_error) {
my_settings = l.values;
svc_settings.update_settings(l);
roon.save_config("settings", my_settings);
}
}
});
roon.init_services({
required_services: [ ],
provided_services: [ svc_settings ]
});
roon.start_discovery();
Extension 2:
"use strict";
var RoonApi = require("node-roon-api"),
RoonApiSettings = require('node-roon-api-settings');
var core = undefined;
var roon = new RoonApi({
extension_id: 'com.example.2',
display_name: 'Example 2',
display_version: '0.1.0',
publisher: 'Example',
email: 'two@example.com',
core_paired: function(core_) {
core = core_;
},
core_unpaired: function(core_) {
core = undefined;
}
});
var my_settings = roon.load_config("settings") || {
};
function makelayout(settings) {
let l = {
values: settings,
layout: [],
has_error: false
};
l.layout.push({
type: "group",
title: "group1",
items: [{
type: "dropdown",
title: "Drop Down",
values: [
{ "title": "Off", "value": 0 },
{ "title": "On", "value": 1 }
],
setting: "dropdown"
}]
});
return l;
}
var svc_settings = new RoonApiSettings(roon, {
get_settings: function(cb) {
cb(makelayout(my_settings));
},
save_settings: function(req, isdryrun, settings) {
let l = makelayout(settings.values);
req.send_complete(l.has_error ? "NotValid" : "Success", { settings: l });
if (!isdryrun && !l.has_error) {
my_settings = l.values;
svc_settings.update_settings(l);
roon.save_config("settings", my_settings);
}
}
});
roon.init_services({
required_services: [ ],
provided_services: [ svc_settings ]
});
roon.start_discovery();