From 03617eb8a761859ce4848495cbb3028f8a0cd84b Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sat, 27 Apr 2024 03:43:25 -0700 Subject: [PATCH] Mobile: Resolves #10360: Make most plugins default to being desktop-only (#10376) --- .eslintignore | 1 + .gitignore | 1 + .../tests/services/plugins/PluginService.ts | 3 +- .../utils/isCompatible/getDefaultPlatforms.ts | 43 +++++++++++++++++++ .../plugins/utils/isCompatible/index.test.ts | 12 ++++-- .../isCompatible/minVersionForPlatform.ts | 9 +++- .../plugins/utils/isCompatible/types.ts | 2 +- readme/api/references/plugin_manifest.md | 2 +- 8 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.ts diff --git a/.eslintignore b/.eslintignore index 48009d676..61d47a8e4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1071,6 +1071,7 @@ packages/lib/services/plugins/utils/getPluginIssueReportUrl.js packages/lib/services/plugins/utils/getPluginNamespacedSettingKey.js packages/lib/services/plugins/utils/getPluginSettingKeyPrefix.js packages/lib/services/plugins/utils/getPluginSettingValue.js +packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.js packages/lib/services/plugins/utils/isCompatible/index.test.js packages/lib/services/plugins/utils/isCompatible/index.js packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.js diff --git a/.gitignore b/.gitignore index 08fcdf4df..508ee3cd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1051,6 +1051,7 @@ packages/lib/services/plugins/utils/getPluginIssueReportUrl.js packages/lib/services/plugins/utils/getPluginNamespacedSettingKey.js packages/lib/services/plugins/utils/getPluginSettingKeyPrefix.js packages/lib/services/plugins/utils/getPluginSettingValue.js +packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.js packages/lib/services/plugins/utils/isCompatible/index.test.js packages/lib/services/plugins/utils/isCompatible/index.js packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.js diff --git a/packages/app-cli/tests/services/plugins/PluginService.ts b/packages/app-cli/tests/services/plugins/PluginService.ts index 814761263..7bd5b1b9f 100644 --- a/packages/app-cli/tests/services/plugins/PluginService.ts +++ b/packages/app-cli/tests/services/plugins/PluginService.ts @@ -283,10 +283,11 @@ describe('services_PluginService', () => { shouldRun: true, }, { + // Should default to desktop-only manifestPlatforms: [], isDesktop: false, appVersion: '3.0.8', - shouldRun: true, + shouldRun: false, }, ])('should enable and disable plugins depending on what platform(s) they support (case %#: %j)', async ({ manifestPlatforms, isDesktop, appVersion, shouldRun }) => { const pluginScript = ` diff --git a/packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.ts b/packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.ts new file mode 100644 index 000000000..f7b8162c9 --- /dev/null +++ b/packages/lib/services/plugins/utils/isCompatible/getDefaultPlatforms.ts @@ -0,0 +1,43 @@ + +// Although `platforms: ['desktop', 'mobile']` is required to support both mobile +// and desktop, no plugin authors have done this as of 04/25/2024. As such, we include +// a list of plugins that have "platforms" default to ['desktop', 'mobile'] rather +// than just ['desktop']. +// cSpell:disable +const defaultSupportMobile = [ + 'com.github.joplin.kanban', + 'com.hieuthi.joplin.function-plot', + 'com.hieuthi.joplin.markdown-table-colorize', + 'com.joplin.copy.codeBlocks', + 'com.whatever.inline-tags', + 'com.whatever.quick-links', + 'cx.evermeet.tessus.menu-shortcut-toolbar', + 'io.github.personalizedrefrigerator.codemirror6-settings', + 'io.github.personalizedrefrigerator.revealjs-integration', + 'io.treymo.LinkGraph', + 'jl15988.JoplinAlertsPerfectPlugin', + 'jl15988.JoplinCodePerfectPlugin', + 'joplin.plugin.alondmnt.history-panel', + 'joplin.plugin.ambrt.backlinksToNote', + 'joplin.plugin.ambrt.embedSearch', + 'joplin.plugin.note.tabs', + 'joplin.plugin.spoiler.cards', + 'net.cwesson.joplin-plugin-typograms', + 'org.joplinapp.plugins.AbcSheetMusic', + 'org.joplinapp.plugins.admonition', + 'org.joplinapp.plugins.joplin-calendar', + 'outline', + 'plugin.calebjohn.MathMode', + 'plugin.calebjohn.rich-markdown', +]; +// cSpell:enable + +const getDefaultPluginPlatforms = (id: string) => { + if (defaultSupportMobile.includes(id)) { + return ['desktop', 'mobile']; + } else { + return ['desktop']; + } +}; + +export default getDefaultPluginPlatforms; diff --git a/packages/lib/services/plugins/utils/isCompatible/index.test.ts b/packages/lib/services/plugins/utils/isCompatible/index.test.ts index 8df5c9d20..f4c650597 100644 --- a/packages/lib/services/plugins/utils/isCompatible/index.test.ts +++ b/packages/lib/services/plugins/utils/isCompatible/index.test.ts @@ -8,7 +8,7 @@ describe('isCompatible', () => { manifest: { app_min_version: '2.0' }, appVersion: '2.1.0', shouldSupportDesktop: true, - shouldSupportMobile: true, + shouldSupportMobile: false, }, { manifest: { app_min_version: '2.0' }, @@ -20,7 +20,7 @@ describe('isCompatible', () => { manifest: { app_min_version: '3.0.2' }, appVersion: '3.0.2', shouldSupportDesktop: true, - shouldSupportMobile: true, + shouldSupportMobile: false, }, // Should support the case where only one platform is provided, with no version @@ -83,9 +83,13 @@ describe('isCompatible', () => { shouldSupportMobile: true, }, ])('should correctly return whether a plugin is compatible with a given version of Joplin (case %#: %j)', ({ manifest, appVersion, shouldSupportDesktop, shouldSupportMobile }) => { - const mobileCompatible = isCompatible(appVersion, AppType.Mobile, manifest); + const fullManifest = { + id: 'com.example.id', + ...manifest, + }; + const mobileCompatible = isCompatible(appVersion, AppType.Mobile, fullManifest); expect(mobileCompatible).toBe(shouldSupportMobile); - const desktopCompatible = isCompatible(appVersion, AppType.Desktop, manifest); + const desktopCompatible = isCompatible(appVersion, AppType.Desktop, fullManifest); expect(desktopCompatible).toBe(shouldSupportDesktop); }); }); diff --git a/packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.ts b/packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.ts index 8012f7102..f7682fb9c 100644 --- a/packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.ts +++ b/packages/lib/services/plugins/utils/isCompatible/minVersionForPlatform.ts @@ -1,10 +1,15 @@ import { AppType } from '../../../../models/Setting'; +import getDefaultPlatforms from './getDefaultPlatforms'; import { ManifestSlice } from './types'; // Returns false if the platform isn't supported at all, const minVersionForPlatform = (appPlatform: AppType, manifest: ManifestSlice): string|false => { - const platforms = manifest.platforms ?? []; - // If platforms is not specified (or empty), default to supporting all platforms. + let platforms = manifest.platforms; + + if (!platforms || platforms.length === 0) { + platforms = getDefaultPlatforms(manifest.id); + } + const supported = platforms.length === 0 || platforms.includes(appPlatform); if (!supported) { return false; diff --git a/packages/lib/services/plugins/utils/isCompatible/types.ts b/packages/lib/services/plugins/utils/isCompatible/types.ts index b400ffe6a..fefb02d6f 100644 --- a/packages/lib/services/plugins/utils/isCompatible/types.ts +++ b/packages/lib/services/plugins/utils/isCompatible/types.ts @@ -1,3 +1,3 @@ import { PluginManifest } from '../types'; -export type ManifestSlice = Pick; +export type ManifestSlice = Pick; diff --git a/readme/api/references/plugin_manifest.md b/readme/api/references/plugin_manifest.md index afd93d3f1..86161341d 100644 --- a/readme/api/references/plugin_manifest.md +++ b/readme/api/references/plugin_manifest.md @@ -22,7 +22,7 @@ Name | Type | Required? | Description ## Platforms -A list that can contain `"desktop"` and/or `"mobile"`. +A list that can contain `"desktop"` and/or `"mobile"`. If not given, it defaults to `[ "desktop" ]` for most plugins. ## Categories