Managing Plugin Settings
Overview
For each plugin, Logi Plugin Service stores a collection of setting names and values. Here are some characteristics of plugin settings:
- Both setting names and values are of
String
type. - The setting names are case-insensitive.
- Plugin settings are persistent and are stored encrypted.
- Any setting can be marked to be backed up in the cloud for the logged-in Logi user.
Usage
The following methods are available in the Plugin
class.
Read setting
Returns a plugin setting.
Returns true
if the setting exists and false
otherwise.
If the setting does not exist, then settingValue
is set to null
.
Write setting
Saves a plugin setting.
Set backupOnline
to true
to backup this setting in the cloud and false
to keep it only locally.
Delete setting
Deletes a plugin setting.
List all settings
Returns a list of plugin setting names.
Example
private String GetUserId()
{
const String SettingName = "UserId";
// first try to get existing user ID
if (this.TryGetPluginSetting(SettingName, out var existingUserId))
{
return existingUserId;
}
// if it does not exist, generate a new one and save it
var newUserId = Guid.NewGuid().ToString("N");
this.SetPluginSetting(SettingName, newUserId, false);
return newUserId;
}
Note: The way you access plugin settings methods depends on the context of your code:
-
Plugin-level code: When your code is inside a class that inherits from
Plugin
class (such as your main plugin class), you can call the settings methods directly usingthis
, e.g.this.TryGetPluginSetting(settingName, out var settingValue)
. -
Action-level code: When your code is inside a class that inherits from classes such as
PluginDynamicCommand
, you need to access the settings methods through thePlugin
property, e.g.this.Plugin.TryGetPluginSetting(settingName, out var settingValue)
. This is because action classes have a reference to the plugin instance through theirPlugin
property, rather than inheriting from thePlugin
class directly.