Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile: Resolves #10360: Make most plugins default to being desktop-only #10376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/app-cli/tests/services/plugins/PluginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 8 additions & 4 deletions packages/lib/services/plugins/utils/isCompatible/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/plugins/utils/isCompatible/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { PluginManifest } from '../types';

export type ManifestSlice = Pick<PluginManifest, 'app_min_version'|'app_min_version_mobile'|'platforms'>;
export type ManifestSlice = Pick<PluginManifest, 'id'|'app_min_version'|'app_min_version_mobile'|'platforms'>;
2 changes: 1 addition & 1 deletion readme/api/references/plugin_manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading