This is probably a dumb question, but is there an elegant way to call a function in companion/index.js in response to an event (eg, button onclick) in settings/index.jsx? I can get the companion to respond to changes in settings, but I'd like to be able to get the companion to respond to event handlers.
Not exactly, but I came up with a kludge that seems to work. In index.jsx:
<Button
label="Create/Update"
onClick={() => {
props.settingsStorage.setItem('createAccount', 'true');
}}
/>In companion/index.js:
if (me.launchReasons.settingsChanged) {
let createAccountSetting = settingsStorage.getItem('createAccount');
if (createAccountSetting === 'true') createAccount();
}
settingsStorage.onchange = function(evt) {
if (evt.key === "createAccount" && evt.newValue === "true") createAccount();
}
Best Answer