Skip to content

Commit

Permalink
added broken status for plugin
Browse files Browse the repository at this point in the history
- hiding plugins if broken in available tab
- new broken button when plugin has been set to broken
  • Loading branch information
error7404 committed Oct 20, 2024
1 parent 6cfa656 commit 641e4d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/hooks/persisted/usePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function usePlugins() {
installedPlugin => installedPlugin.id === avalilablePlugin.id,
),
)
.filter(plg => filter.includes(plg.lang)),
.filter(plg => filter.includes(plg.lang))
.filter(plg => plg.down === false),
'name',
),
);
Expand All @@ -67,6 +68,9 @@ export default function usePlugins() {
fetchedPlugins.filter(plg => {
const finded = installedPlugins.find(v => v.id === plg.id);
if (finded) {
if (plg.version === finded.version) {
finded.down = plg.down;
}
if (!finded.newVersion || newer(plg.version, finded.version)) {
finded.newVersion = plg.version;
finded.iconUrl = plg.iconUrl;
Expand Down Expand Up @@ -109,6 +113,7 @@ export default function usePlugins() {
...plugin,
version: _plg.version,
newVersion: _plg.version,
down: _plg.down,
};
// safe
if (!installedPlugins.some(plg => plg.id === plugin.id)) {
Expand Down Expand Up @@ -157,6 +162,7 @@ export default function usePlugins() {
name: _plg.name,
version: _plg.version,
newVersion: _plg.version,
down: _plg.down,
};
if (newPlugin.id === lastUsedPlugin?.id) {
setLastUsedPlugin(newPlugin);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface PluginItem {
iconUrl: string;
customJS?: string;
customCSS?: string;
down?: boolean;
}

export interface ImageRequestInit {
Expand Down
43 changes: 36 additions & 7 deletions src/screens/browse/components/BrowseTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Button, EmptyView, IconButtonV2 } from '@components';
import TrackerCard from '../discover/TrackerCard';
import { showToast } from '@utils/showToast';
import Animated, { useSharedValue, withTiming } from 'react-native-reanimated';
import { newer } from '@utils/compareVersion';

interface AvailableTabProps {
searchText: string;
Expand Down Expand Up @@ -151,15 +152,15 @@ export const InstalledTab = memo(
style={[{ color: theme.onSurfaceVariant }, styles.addition]}
>
{`${item.lang}\n${item.version}${
item.newVersion != item.version
newer(item.newVersion, item.version)
? ` → ${item.newVersion}`
: ''
}`}
</Text>
</View>
</View>
<View style={{ flex: 1 }} />
{item.newVersion != item.version || __DEV__ ? (
{newer(item.newVersion, item.version) || __DEV__ ? (
<IconButtonV2
name="download-outline"
size={22}
Expand All @@ -176,11 +177,39 @@ export const InstalledTab = memo(
theme={theme}
/>
) : null}
<Button
title={getString('browseScreen.latest')}
textColor={theme.primary}
onPress={() => navigateToSource(item, true)}
/>
{!item.down ? (
<Button
title={getString('browseScreen.latest')}
textColor={theme.primary}
onPress={() => navigateToSource(item, true)}
style={{ paddingVertical: 4, paddingHorizontal: 8 }}
/>
) : (
<Button
title={'Broken'}
textColor={theme.onError}
style={{
backgroundColor: theme.error,
}}
onPress={() =>
newer(item.newVersion, item.version)
? updatePlugin(item).then(() =>
showToast(
getString('browseScreen.updatedTo', {
version: item.newVersion,
}),
),
)
: uninstallPlugin(item).then(() =>
showToast(
getString('browseScreen.uninstalledPlugin', {
name: item.name,
}),
),
)
}
/>
)}
</Pressable>
</Swipeable>
);
Expand Down

0 comments on commit 641e4d5

Please sign in to comment.