Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calling companion function from settings event

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.

Peter McLennan
Gondwana Software
Best Answer
2 REPLIES 2

Did you figure this out? I am trying to do this as well.

Best Answer
0 Votes

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(); }

 

Peter McLennan
Gondwana Software
Best Answer
0 Votes