1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Desktop: Fixed error when exporting certain notes that contain plugin content

This commit is contained in:
Laurent Cozic
2024-03-25 12:50:33 +00:00
parent 0839b0314e
commit f85db1496e
9 changed files with 38 additions and 25 deletions

View File

@ -3,6 +3,8 @@
import eventManager, { EventName } from '../../../eventManager';
import Setting, { SettingItem as InternalSettingItem, SettingSectionSource } from '../../../models/Setting';
import Plugin from '../Plugin';
import getPluginNamespacedSettingKey from '../utils/getPluginNamespacedSettingKey';
import getPluginSettingKeyPrefix from '../utils/getPluginSettingKeyPrefix';
import { SettingItem, SettingSection } from './types';
// That's all the plugin as of 27/08/21 - any new plugin after that will not be
@ -70,17 +72,6 @@ export interface ChangeEvent {
export type ChangeHandler = (event: ChangeEvent)=> void;
const keyPrefix = (pluginId: string): string => {
return `plugin-${pluginId}.`;
};
// Ensures that the plugin settings and sections are within their own namespace,
// to prevent them from overwriting other plugin settings or the default
// settings.
export const namespacedKey = (pluginId: string, key: string): string => {
return `${keyPrefix(pluginId)}${key}`;
};
/**
* This API allows registering new settings and setting sections, as well as getting and setting settings. Once a setting has been registered it will appear in the config screen and be editable by the user.
*
@ -117,7 +108,7 @@ export default class JoplinSettings {
if ('subType' in setting) internalSettingItem.subType = setting.subType;
if ('isEnum' in setting) internalSettingItem.isEnum = setting.isEnum;
if ('section' in setting) internalSettingItem.section = namespacedKey(this.plugin_.id, setting.section);
if ('section' in setting) internalSettingItem.section = getPluginNamespacedSettingKey(this.plugin_.id, setting.section);
if ('options' in setting) internalSettingItem.options = () => setting.options;
if ('appTypes' in setting) internalSettingItem.appTypes = setting.appTypes;
if ('secure' in setting) internalSettingItem.secure = setting.secure;
@ -127,7 +118,7 @@ export default class JoplinSettings {
if ('step' in setting) internalSettingItem.step = setting.step;
if ('storage' in setting) internalSettingItem.storage = setting.storage;
await Setting.registerSetting(namespacedKey(this.plugin_.id, key), internalSettingItem);
await Setting.registerSetting(getPluginNamespacedSettingKey(this.plugin_.id, key), internalSettingItem);
}
}
@ -151,21 +142,21 @@ export default class JoplinSettings {
* Registers a new setting section. Like for registerSetting, it is dynamic and needs to be done every time the plugin starts.
*/
public async registerSection(name: string, section: SettingSection) {
return Setting.registerSection(namespacedKey(this.plugin_.id, name), SettingSectionSource.Plugin, section);
return Setting.registerSection(getPluginNamespacedSettingKey(this.plugin_.id, name), SettingSectionSource.Plugin, section);
}
/**
* Gets a setting value (only applies to setting you registered from your plugin)
*/
public async value(key: string): Promise<any> {
return Setting.value(namespacedKey(this.plugin_.id, key));
return Setting.value(getPluginNamespacedSettingKey(this.plugin_.id, key));
}
/**
* Sets a setting value (only applies to setting you registered from your plugin)
*/
public async setValue(key: string, value: any) {
return Setting.setValue(namespacedKey(this.plugin_.id, key), value);
return Setting.setValue(getPluginNamespacedSettingKey(this.plugin_.id, key), value);
}
/**
@ -188,8 +179,8 @@ export default class JoplinSettings {
// Filter out keys that are not related to this plugin
eventManager.on(EventName.SettingsChange, (event: ChangeEvent) => {
const keys = event.keys
.filter(k => k.indexOf(keyPrefix(this.plugin_.id)) === 0)
.map(k => k.substr(keyPrefix(this.plugin_.id).length));
.filter(k => k.indexOf(getPluginSettingKeyPrefix(this.plugin_.id)) === 0)
.map(k => k.substr(getPluginSettingKeyPrefix(this.plugin_.id).length));
if (!keys.length) return;
handler({ keys });
});