mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-11 11:12:03 +02:00
Desktop: Turn old plugin deprecation notices into errors
This commit is contained in:
parent
8471be16aa
commit
7f00e4ea5b
@ -143,8 +143,12 @@ export default class Plugin {
|
||||
return this.viewControllers_[handle];
|
||||
}
|
||||
|
||||
public deprecationNotice(goneInVersion: string, message: string) {
|
||||
logger.warn(`"${this.id}": DEPRECATION NOTICE: ${message} This will stop working in version ${goneInVersion}.`);
|
||||
public deprecationNotice(goneInVersion: string, message: string, isError: boolean = false) {
|
||||
if (isError) {
|
||||
throw new Error(`"${this.id}": No longer supported: ${message} (deprecated since version ${goneInVersion})`);
|
||||
} else {
|
||||
logger.warn(`"${this.id}": DEPRECATION NOTICE: ${message} This will stop working in version ${goneInVersion}.`);
|
||||
}
|
||||
}
|
||||
|
||||
public emitMessage(message: any) {
|
||||
|
@ -262,16 +262,30 @@ export default class PluginService extends BaseService {
|
||||
|
||||
const manifestObj = JSON.parse(manifestText);
|
||||
|
||||
const deprecationNotices = [];
|
||||
interface DeprecationNotice {
|
||||
goneInVersion: string;
|
||||
message: string;
|
||||
isError: boolean;
|
||||
}
|
||||
|
||||
const deprecationNotices: DeprecationNotice[] = [];
|
||||
|
||||
if (!manifestObj.app_min_version) {
|
||||
manifestObj.app_min_version = '1.4';
|
||||
deprecationNotices.push('The manifest must contain an "app_min_version" key, which should be the minimum version of the app you support. It was automatically set to "1.4", but please update your manifest.json file.');
|
||||
deprecationNotices.push({
|
||||
message: 'The manifest must contain an "app_min_version" key, which should be the minimum version of the app you support.',
|
||||
goneInVersion: '1.4',
|
||||
isError: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (!manifestObj.id) {
|
||||
manifestObj.id = pluginIdIfNotSpecified;
|
||||
deprecationNotices.push(`The manifest must contain an "id" key, which should be a globally unique ID for your plugin, such as "com.example.MyPlugin" or a UUID. It was automatically set to "${manifestObj.id}", but please update your manifest.json file.`);
|
||||
deprecationNotices.push({
|
||||
message: 'The manifest must contain an "id" key, which should be a globally unique ID for your plugin, such as "com.example.MyPlugin" or a UUID.',
|
||||
goneInVersion: '1.4',
|
||||
isError: true,
|
||||
});
|
||||
}
|
||||
|
||||
const manifest = manifestFromObject(manifestObj);
|
||||
@ -280,8 +294,8 @@ export default class PluginService extends BaseService {
|
||||
|
||||
const plugin = new Plugin(baseDir, manifest, scriptText, (action: any) => this.store_.dispatch(action), dataDir);
|
||||
|
||||
for (const msg of deprecationNotices) {
|
||||
plugin.deprecationNotice('1.5', msg);
|
||||
for (const notice of deprecationNotices) {
|
||||
plugin.deprecationNotice(notice.goneInVersion, notice.message, notice.isError);
|
||||
}
|
||||
|
||||
// Sanity check, although at that point the plugin ID should have
|
||||
|
@ -54,7 +54,7 @@ export default class JoplinPlugins {
|
||||
* @deprecated Use joplin.contentScripts.register()
|
||||
*/
|
||||
public async registerContentScript(type: ContentScriptType, id: string, scriptPath: string) {
|
||||
this.plugin.deprecationNotice('1.8', 'joplin.plugins.registerContentScript() is deprecated in favour of joplin.contentScripts.register()');
|
||||
this.plugin.deprecationNotice('1.8', 'joplin.plugins.registerContentScript() is deprecated in favour of joplin.contentScripts.register()', true);
|
||||
return this.plugin.registerContentScript(type, id, scriptPath);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ export default class JoplinSettings {
|
||||
* Registers a new setting.
|
||||
*/
|
||||
public async registerSetting(key: string, settingItem: SettingItem) {
|
||||
this.plugin_.deprecationNotice('1.8', 'joplin.settings.registerSetting() is deprecated in favour of joplin.settings.registerSettings()');
|
||||
this.plugin_.deprecationNotice('1.8', 'joplin.settings.registerSetting() is deprecated in favour of joplin.settings.registerSettings()', true);
|
||||
await this.registerSettings({ [key]: settingItem });
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ export default class JoplinViewsDialogs {
|
||||
*/
|
||||
async create(id: string): Promise<ViewHandle> {
|
||||
if (!id) {
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.dialogs.create("my-unique-id")`');
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.dialogs.create("my-unique-id")`', true);
|
||||
id = `${this.plugin.viewCount}`;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export default class JoplinViewsMenuItems {
|
||||
*/
|
||||
public async create(id: string, commandName: string, location: MenuItemLocation = MenuItemLocation.Tools, options: CreateMenuItemOptions = null) {
|
||||
if (typeof location !== 'string') {
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.menuItem.create("my-unique-id", ...)`');
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.menuItem.create("my-unique-id", ...)`', true);
|
||||
options = location as any;
|
||||
location = commandName as any || MenuItemLocation.Tools;
|
||||
commandName = id as any;
|
||||
|
@ -37,7 +37,7 @@ export default class JoplinViewsMenus {
|
||||
*/
|
||||
public async create(id: string, label: string, menuItems: MenuItem[], location: MenuItemLocation = MenuItemLocation.Tools) {
|
||||
if (!Array.isArray(menuItems)) {
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.menus.create("my-unique-id", ...)`');
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.menus.create("my-unique-id", ...)`', true);
|
||||
location = menuItems as any || MenuItemLocation.Tools;
|
||||
menuItems = label as any;
|
||||
label = id as any;
|
||||
|
@ -31,7 +31,7 @@ export default class JoplinViewsPanels {
|
||||
*/
|
||||
public async create(id: string): Promise<ViewHandle> {
|
||||
if (!id) {
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.panels.create("my-unique-id")`');
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.panels.create("my-unique-id")`', true);
|
||||
id = `${this.plugin.viewCount}`;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ export default class JoplinViewsToolbarButtons {
|
||||
*/
|
||||
async create(id: string, commandName: string, location: ToolbarButtonLocation) {
|
||||
if (arguments.length < 3) {
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.toolbarButtons.create("my-unique-id", ...)`');
|
||||
this.plugin.deprecationNotice('1.5', 'Creating a view without an ID is deprecated. To fix it, change your call to `joplin.views.toolbarButtons.create("my-unique-id", ...)`', true);
|
||||
location = commandName as any;
|
||||
commandName = id as any;
|
||||
id = `${this.plugin.viewCount}`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user