You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Desktop: Turn old plugin deprecation notices into errors
This commit is contained in:
@ -143,8 +143,12 @@ export default class Plugin {
|
|||||||
return this.viewControllers_[handle];
|
return this.viewControllers_[handle];
|
||||||
}
|
}
|
||||||
|
|
||||||
public deprecationNotice(goneInVersion: string, message: string) {
|
public deprecationNotice(goneInVersion: string, message: string, isError: boolean = false) {
|
||||||
logger.warn(`"${this.id}": DEPRECATION NOTICE: ${message} This will stop working in version ${goneInVersion}.`);
|
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) {
|
public emitMessage(message: any) {
|
||||||
|
@ -262,16 +262,30 @@ export default class PluginService extends BaseService {
|
|||||||
|
|
||||||
const manifestObj = JSON.parse(manifestText);
|
const manifestObj = JSON.parse(manifestText);
|
||||||
|
|
||||||
const deprecationNotices = [];
|
interface DeprecationNotice {
|
||||||
|
goneInVersion: string;
|
||||||
|
message: string;
|
||||||
|
isError: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deprecationNotices: DeprecationNotice[] = [];
|
||||||
|
|
||||||
if (!manifestObj.app_min_version) {
|
if (!manifestObj.app_min_version) {
|
||||||
manifestObj.app_min_version = '1.4';
|
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) {
|
if (!manifestObj.id) {
|
||||||
manifestObj.id = pluginIdIfNotSpecified;
|
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);
|
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);
|
const plugin = new Plugin(baseDir, manifest, scriptText, (action: any) => this.store_.dispatch(action), dataDir);
|
||||||
|
|
||||||
for (const msg of deprecationNotices) {
|
for (const notice of deprecationNotices) {
|
||||||
plugin.deprecationNotice('1.5', msg);
|
plugin.deprecationNotice(notice.goneInVersion, notice.message, notice.isError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check, although at that point the plugin ID should have
|
// Sanity check, although at that point the plugin ID should have
|
||||||
|
@ -54,7 +54,7 @@ export default class JoplinPlugins {
|
|||||||
* @deprecated Use joplin.contentScripts.register()
|
* @deprecated Use joplin.contentScripts.register()
|
||||||
*/
|
*/
|
||||||
public async registerContentScript(type: ContentScriptType, id: string, scriptPath: string) {
|
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);
|
return this.plugin.registerContentScript(type, id, scriptPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ export default class JoplinSettings {
|
|||||||
* Registers a new setting.
|
* Registers a new setting.
|
||||||
*/
|
*/
|
||||||
public async registerSetting(key: string, settingItem: SettingItem) {
|
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 });
|
await this.registerSettings({ [key]: settingItem });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export default class JoplinViewsDialogs {
|
|||||||
*/
|
*/
|
||||||
async create(id: string): Promise<ViewHandle> {
|
async create(id: string): Promise<ViewHandle> {
|
||||||
if (!id) {
|
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}`;
|
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) {
|
public async create(id: string, commandName: string, location: MenuItemLocation = MenuItemLocation.Tools, options: CreateMenuItemOptions = null) {
|
||||||
if (typeof location !== 'string') {
|
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;
|
options = location as any;
|
||||||
location = commandName as any || MenuItemLocation.Tools;
|
location = commandName as any || MenuItemLocation.Tools;
|
||||||
commandName = id as any;
|
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) {
|
public async create(id: string, label: string, menuItems: MenuItem[], location: MenuItemLocation = MenuItemLocation.Tools) {
|
||||||
if (!Array.isArray(menuItems)) {
|
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;
|
location = menuItems as any || MenuItemLocation.Tools;
|
||||||
menuItems = label as any;
|
menuItems = label as any;
|
||||||
label = id as any;
|
label = id as any;
|
||||||
|
@ -31,7 +31,7 @@ export default class JoplinViewsPanels {
|
|||||||
*/
|
*/
|
||||||
public async create(id: string): Promise<ViewHandle> {
|
public async create(id: string): Promise<ViewHandle> {
|
||||||
if (!id) {
|
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}`;
|
id = `${this.plugin.viewCount}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export default class JoplinViewsToolbarButtons {
|
|||||||
*/
|
*/
|
||||||
async create(id: string, commandName: string, location: ToolbarButtonLocation) {
|
async create(id: string, commandName: string, location: ToolbarButtonLocation) {
|
||||||
if (arguments.length < 3) {
|
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;
|
location = commandName as any;
|
||||||
commandName = id as any;
|
commandName = id as any;
|
||||||
id = `${this.plugin.viewCount}`;
|
id = `${this.plugin.viewCount}`;
|
||||||
|
Reference in New Issue
Block a user