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

Desktop: Resolves #7934: Don't create an extra copy of default plugins (load directly from the app bundle) #9508

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert update-button-related changes
These changes will be moved to a separate pull request after discussion.
  • Loading branch information
personalizedrefrigerator committed Dec 14, 2023
commit 52673515f621764b13b7d196edbe9485bfaed240
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface Props {
item?: PluginItem;
manifest?: PluginManifest;
installState?: InstallState;
builtInEquivalentInstalledAndLoaded?: boolean;
updateState?: UpdateState;
themeId: number;
isCompatible: boolean;
Expand Down Expand Up @@ -212,30 +211,14 @@ export default function(props: Props) {
function renderUpdateButton() {
if (!props.onUpdate) return null;

// We show a different title when updating from a built-in version of a plugin
// to an NPM version.
let title;
if (props.updateState === UpdateState.Updating) {
title = _('Updating...');
} else if (props.updateState === UpdateState.Idle) {
title = _('Updated');
} else if (props.updateState === UpdateState.HasBeenUpdated) {
if (props.builtInEquivalentInstalledAndLoaded) {
title = _('Replaced built-in');
} else {
title = _('Updated');
}
} else {
title = _('Update');

if (props.builtInEquivalentInstalledAndLoaded) {
title = _('Replace built-in');
}
}
let title = _('Update');
if (props.updateState === UpdateState.Updating) title = _('Updating...');
if (props.updateState === UpdateState.Idle) title = _('Updated');
if (props.updateState === UpdateState.HasBeenUpdated) title = _('Updated');

return <Button
ml={1}
level={props.builtInEquivalentInstalledAndLoaded ? ButtonLevel.Secondary : ButtonLevel.Recommended}
level={ButtonLevel.Recommended}
onClick={() => props.onUpdate({ item })}
title={title}
disabled={props.updateState === UpdateState.HasBeenUpdated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import styled from 'styled-components';
import RepositoryApi from '@joplin/lib/services/plugins/RepositoryApi';
import AsyncActionQueue from '@joplin/lib/AsyncActionQueue';
import { PluginManifest } from '@joplin/lib/services/plugins/utils/types';
import PluginBox, { InstallState, ItemEvent, UpdateState } from './PluginBox';
import PluginBox, { InstallState } from './PluginBox';
import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService';
import { _ } from '@joplin/lib/locale';
import useOnInstallHandler from './useOnInstallHandler';
import { themeStyle } from '@joplin/lib/theme';
import bridge from '../../../../services/bridge';

const Root = styled.div`
`;
Expand Down Expand Up @@ -50,19 +49,6 @@ export default function(props: Props) {

const onInstall = useOnInstallHandler(setInstallingPluginIds, props.pluginSettings, props.repoApi, props.onPluginSettingsChange, false);

// We use an onUpdate callback to replace built-in plugins with non-built-in plugins
const onUpdate = useOnInstallHandler(setInstallingPluginIds, props.pluginSettings, props.repoApi, props.onPluginSettingsChange, true);
const onReplaceDefault = useCallback(async (event: ItemEvent) => {
const itemId = event.item.manifest.id;

const confirmResult = bridge().showConfirmMessageBox(
_('Override the built-in version of %s?\n\nThe Joplin team may not have reviewed this version for stability or security.', itemId),
);
if (confirmResult) {
await onUpdate(event);
}
}, [onUpdate]);

useEffect(() => {
setSearchResultCount(null);
asyncSearchQueue.current.push(async () => {
Expand All @@ -89,10 +75,10 @@ export default function(props: Props) {
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
}, []);

function getInstallState(pluginId: string): InstallState {
function installState(pluginId: string): InstallState {
const settings = props.pluginSettings[pluginId];
if (installingPluginsIds[pluginId]) return InstallState.Installing;
if (settings && !settings.deleted) return InstallState.Installed;
if (installingPluginsIds[pluginId]) return InstallState.Installing;
return InstallState.NotInstalled;
}

Expand All @@ -104,36 +90,13 @@ export default function(props: Props) {
const output = [];

for (const manifest of manifests) {
const installState = getInstallState(manifest.id);
let updateState = UpdateState.Idle;

let hasBuiltInVersion = false;
if (installState === InstallState.Installed) {
const existingItem = PluginService.instance().pluginById(manifest.id);
hasBuiltInVersion = existingItem.builtIn ?? false;

if (hasBuiltInVersion) {
updateState = UpdateState.CanUpdate;
}

if (props.pluginSettings[manifest.id]?.hasBeenUpdated) {
updateState = UpdateState.HasBeenUpdated;
}
}

const installCallback = !hasBuiltInVersion ? onInstall : undefined;
const updateCallback = hasBuiltInVersion ? onReplaceDefault : undefined;

output.push(<PluginBox
key={manifest.id}
manifest={manifest}
themeId={props.themeId}
isCompatible={PluginService.instance().isCompatible(manifest.app_min_version)}
onInstall={installCallback}
onUpdate={updateCallback}
updateState={updateState}
installState={installState}
builtInEquivalentInstalledAndLoaded={hasBuiltInVersion}
onInstall={onInstall}
installState={installState(manifest.id)}
/>);
}

Expand Down
Loading