Skip to content

Commit

Permalink
fix: disable Metal use for iOS < 18 (#220)
Browse files Browse the repository at this point in the history
* fix: prevent Metal use for ios < 18

* chore: disable sponsorship option for iOS users
  • Loading branch information
a-ghorbani authored Feb 22, 2025
1 parent 0ae0649 commit 5aa717d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/components/SidebarContent/SidebarContent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useContext, useEffect, useState} from 'react';
import {TouchableOpacity, View, Alert, Linking} from 'react-native';
import {TouchableOpacity, View, Alert, Linking, Platform} from 'react-native';

import {observer} from 'mobx-react';
import {Button, Divider, Drawer, Text} from 'react-native-paper';
Expand Down Expand Up @@ -93,13 +93,19 @@ export const SidebarContent: React.FC<DrawerContentComponentProps> = observer(
};

const openSponsorPage = async () => {
const link = 'https://buymeacoffee.com/aghorbani';
const link =
Platform.OS === 'ios' // Due to Apple's policies, we can't use Buy Me a Coffee on iOS.
? 'https://github.com/a-ghorbani/pocketpal-ai'
: 'https://buymeacoffee.com/aghorbani';
const canOpen = await Linking.canOpenURL(link);
if (canOpen) {
Linking.openURL(link);
}
};

const sponsorText =
Platform.OS === 'ios' ? 'Leave a star on GitHub' : 'Become a Sponsor';

return (
<GestureHandlerRootView style={styles.sidebarContainer}>
<View style={styles.contentWrapper}>
Expand Down Expand Up @@ -210,13 +216,13 @@ export const SidebarContent: React.FC<DrawerContentComponentProps> = observer(
style={{borderColor: theme.colors.onSurfaceDisabled}}
labelStyle={styles.sponsorButtonLabel}
onPress={openSponsorPage}>
<Text variant="bodySmall">Become a Sponsor</Text>
<Text variant="bodySmall">{sponsorText}</Text>
</Button>
<TouchableOpacity
onPress={copyVersionToClipboard}
style={styles.versionContainer}>
<View style={styles.versionRow}>
<Text style={styles.versionLabel}>Version</Text>
<Text style={styles.versionLabel}>v</Text>
<Text style={styles.versionText}>{appInfo.version}</Text>
<Text style={styles.buildText}>({appInfo.build})</Text>
</View>
Expand Down
8 changes: 4 additions & 4 deletions src/components/SidebarContent/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export const createStyles = (theme: MD3Theme) =>
alignItems: 'center',
justifyContent: 'center',
flexWrap: 'wrap',
gap: 10,
//gap: 10,
},
versionRow: {
flexDirection: 'row',
alignItems: 'center',
gap: 4,
//gap: 4,
justifyContent: 'center',
},
versionLabel: {
Expand Down Expand Up @@ -76,14 +76,14 @@ export const createStyles = (theme: MD3Theme) =>
},
versionSafeArea: {
flexDirection: 'row',
justifyContent: 'space-between',
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: theme.colors.surface,
flexShrink: 1,
paddingHorizontal: 16,
paddingVertical: 16,
flexWrap: 'wrap',
gap: 10,
//gap: 10,
},
sponsorButtonLabel: {
marginHorizontal: 16,
Expand Down
9 changes: 8 additions & 1 deletion src/screens/SettingsScreen/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export const SettingsScreen: React.FC = observer(() => {
);
};

const isIOS18OrHigher =
Platform.OS === 'ios' && parseInt(Platform.Version as string, 10) >= 18;

return (
<SafeAreaView style={styles.safeArea} edges={['bottom']}>
<TouchableWithoutFeedback onPress={handleOutsidePress}>
Expand All @@ -137,7 +140,9 @@ export const SettingsScreen: React.FC = observer(() => {
<Text
variant="labelSmall"
style={styles.textDescription}>
{l10n.metalDescription}
{isIOS18OrHigher
? l10n.metalDescription
: 'Metal acceleration requires iOS 18 or higher. Please upgrade your device to use this feature.'}
</Text>
</View>
<Switch
Expand All @@ -146,6 +151,8 @@ export const SettingsScreen: React.FC = observer(() => {
onValueChange={value =>
modelStore.updateUseMetal(value)
}
// disabled={!isIOS18OrHigher}
// We don't disable for cases where the users has has set to true in the past.
/>
</View>
<Slider
Expand Down
15 changes: 15 additions & 0 deletions src/store/ModelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class ModelStore {
await this.initializeDownloadStatus();
this.removeInvalidLocalModels();
}

this.initializeUseMetal();
};

mergeModelLists = () => {
Expand Down Expand Up @@ -726,6 +728,7 @@ class ModelStore {
cache_type_k: this.cache_type_k,
cache_type_v: this.cache_type_v,
n_gpu_layers: this.useMetal ? this.n_gpu_layers : 0,
no_gpu_devices: !this.useMetal,
};
const ctx = await initLlama(
{
Expand Down Expand Up @@ -942,6 +945,18 @@ class ModelStore {
}
};

private initializeUseMetal() {
const isIOS18OrHigher =
Platform.OS === 'ios' && parseInt(Platform.Version as string, 10) >= 18;
// If we're not on iOS 18+ or not on iOS at all, force useMetal to false
if (!isIOS18OrHigher) {
runInAction(() => {
this.useMetal = false;
});
}
// If we are on iOS 18+, the persisted value will be used
}

updateUseMetal = (useMetal: boolean) => {
runInAction(() => {
this.useMetal = useMetal;
Expand Down

0 comments on commit 5aa717d

Please sign in to comment.