Launch Config on Plugin Installation

Posted on
Thu Jan 13, 2022 2:11 pm
ryanbuckner offline
Posts: 1075
Joined: Oct 08, 2011
Location: Northern Virginia

Launch Config on Plugin Installation

I have a plugin that requires configuration to work. I'm hearing from users that the plugin is throwing errors upon installation before they have a chance to configure it.

Is there something I should include in the init to launch the config screen upon first installation or does the framework handle that automatically?

Posted on
Thu Jan 13, 2022 9:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Launch Config on Plugin Installation

The config dialog will open the first time a plugin launches. It won't automatically open when a new version is installed, so if you change the config then you need to add logic to migrate from older versions to the new version.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 14, 2022 9:44 am
ryanbuckner offline
Posts: 1075
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Launch Config on Plugin Installation

Thanks Jay,

I must be doing something wrong then. I had a user report that upon first installation, the config didn't launch and so the plugin errored and stopped. He didn't have a preferences file for the plugin on his computer so I walked him through manually creating one and now it's working.

I also tried to delete my preferences and the plugin and do a fresh install and replicated that problem.

If you find a few free minutes, would you mind installing the life360 plugin from the plugin store and see if the config launches for you?

Posted on
Fri Jan 14, 2022 11:19 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Launch Config on Plugin Installation

The problem is that you're assuming that there are valid plugin prefs in the __init__ method:

Code: Select all
      self.authorization_token = self.pluginPrefs['authorizationtoken']
      self.username = self.pluginPrefs['life360_username']
      self.password = self.pluginPrefs['life360_password']
      self.refresh_frequency = self.pluginPrefs['refresh_frequency']


But on first launch, those don't exist yet. The config dialog can't even run because it's failing plugin initialization (the __init__ method is the absolute first thing in your plugin to get called, well before config dialog etc). You have to rework your logic knowing that when the plugin first initializes, you won't have valid values. To fix the obvious issue:

Code: Select all
      self.authorization_token = self.pluginPrefs.get('authorizationtoken', None)
      self.username = self.pluginPrefs.get('life360_username', None)
      self.password = self.pluginPrefs.get('life360_password', None)
      self.refresh_frequency = self.pluginPrefs.get('refresh_frequency', 30)


I took a stab at a reasonable default for refresh_frequency mostly to show how you could do that. I doubt that will fully solve your problem though, you'll likely need further refactoring to make sure that on first run everything does (or doesn't) do what's expected.

You will also need to handle a config dialog close without valid values (the user clicks the Cancel button), which will continue to result in missing stuff. You need to programmatically make sure that before you use any of those values that they are present, OR handle the failures that will happen if they are missing or invalid.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 14, 2022 1:03 pm
ryanbuckner offline
Posts: 1075
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Launch Config on Plugin Installation

This is really helpful. Thanks.

Posted on
Fri Jan 14, 2022 2:49 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Launch Config on Plugin Installation

Or don't try to read the preferences until the start() method...

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests

cron