2021-09-22 18:07:13 +02:00
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
2021-07-18 18:34:03 +02:00
|
|
|
import { Platform } from 'react-native';
|
2023-02-25 17:20:46 +01:00
|
|
|
import { isTablet, getDeviceType } from 'react-native-device-info';
|
2020-12-18 22:15:38 +01:00
|
|
|
|
2023-03-30 03:04:18 +02:00
|
|
|
const isDesktop: boolean = getDeviceType() === 'Desktop';
|
|
|
|
|
|
|
|
const getIsTorCapable = (): boolean => {
|
2021-07-18 18:34:03 +02:00
|
|
|
let capable = true;
|
|
|
|
if (Platform.OS === 'android' && Platform.Version < 26) {
|
|
|
|
capable = false;
|
|
|
|
} else if (isDesktop) {
|
|
|
|
capable = false;
|
|
|
|
}
|
|
|
|
return capable;
|
|
|
|
};
|
2020-12-18 22:15:38 +01:00
|
|
|
|
2023-03-30 03:04:18 +02:00
|
|
|
const IS_TOR_DAEMON_DISABLED: string = 'is_tor_daemon_disabled';
|
|
|
|
|
|
|
|
export async function setIsTorDaemonDisabled(disabled: boolean = true): Promise<void> {
|
2021-09-22 18:07:13 +02:00
|
|
|
return AsyncStorage.setItem(IS_TOR_DAEMON_DISABLED, disabled ? '1' : '');
|
|
|
|
}
|
|
|
|
|
2023-03-30 03:04:18 +02:00
|
|
|
export async function isTorDaemonDisabled(): Promise<boolean> {
|
2023-07-25 15:50:04 +02:00
|
|
|
let result: boolean;
|
2021-09-22 18:07:13 +02:00
|
|
|
try {
|
|
|
|
const savedValue = await AsyncStorage.getItem(IS_TOR_DAEMON_DISABLED);
|
|
|
|
if (savedValue === null) {
|
2023-07-25 15:50:04 +02:00
|
|
|
result = false;
|
2021-09-22 18:07:13 +02:00
|
|
|
} else {
|
2023-07-25 15:50:04 +02:00
|
|
|
result = savedValue === '1';
|
2021-09-22 18:07:13 +02:00
|
|
|
}
|
|
|
|
} catch {
|
2023-07-25 15:50:04 +02:00
|
|
|
result = true;
|
2021-09-22 18:07:13 +02:00
|
|
|
}
|
|
|
|
|
2023-07-25 15:50:04 +02:00
|
|
|
return result;
|
2021-09-22 18:07:13 +02:00
|
|
|
}
|
|
|
|
|
2023-03-30 03:04:18 +02:00
|
|
|
export const isHandset: boolean = getDeviceType() === 'Handset';
|
|
|
|
export const isTorCapable: boolean = getIsTorCapable();
|
2023-02-25 17:20:46 +01:00
|
|
|
export { isDesktop, isTablet };
|