Files
OrionTV/components/settings/UpdateSection.tsx
zimplexing f0c797434d fix(update): resolve APK download path issue and enhance update components
- Fix UpdateService to use DocumentDir instead of DownloadDir for APK storage
- Add retry mechanism for network failures in version checking and downloading
- Implement automatic cleanup of old APK files to manage storage
- Replace TouchableOpacity with StyledButton in UpdateModal for consistency
- Add TV focus control to UpdateSection component
- Reduce category button spacing on TV for better navigation
- Update download URL template to match release naming convention
2025-08-13 17:19:48 +08:00

126 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from "react";
import { View, StyleSheet, Platform, ActivityIndicator } from "react-native";
import { ThemedText } from "../ThemedText";
import { StyledButton } from "../StyledButton";
import { useUpdateStore } from "@/stores/updateStore";
import { UPDATE_CONFIG } from "@/constants/UpdateConfig";
export function UpdateSection() {
const { currentVersion, remoteVersion, updateAvailable, downloading, downloadProgress, checkForUpdate } =
useUpdateStore();
const [checking, setChecking] = React.useState(false);
const handleCheckUpdate = async () => {
setChecking(true);
try {
await checkForUpdate(false);
} finally {
setChecking(false);
}
};
return (
<View style={styles.sectionContainer}>
<ThemedText style={styles.sectionTitle}></ThemedText>
<View style={styles.row}>
<ThemedText style={styles.label}></ThemedText>
<ThemedText style={styles.value}>v{currentVersion}</ThemedText>
</View>
{updateAvailable && (
<View style={styles.row}>
<ThemedText style={styles.label}></ThemedText>
<ThemedText style={[styles.value, styles.newVersion]}>v{remoteVersion}</ThemedText>
</View>
)}
{downloading && (
<View style={styles.row}>
<ThemedText style={styles.label}></ThemedText>
<ThemedText style={styles.value}>{downloadProgress}%</ThemedText>
</View>
)}
<View style={styles.buttonContainer}>
<StyledButton onPress={handleCheckUpdate} disabled={checking || downloading} style={styles.button}>
{checking ? (
<ActivityIndicator color="#fff" size="small" />
) : (
<ThemedText style={styles.buttonText}></ThemedText>
)}
</StyledButton>
</View>
{UPDATE_CONFIG.AUTO_CHECK && (
<ThemedText style={styles.hint}>
{UPDATE_CONFIG.CHECK_INTERVAL / (60 * 60 * 1000)}
</ThemedText>
)}
</View>
);
}
const styles = StyleSheet.create({
sectionContainer: {
marginBottom: 24,
padding: 16,
backgroundColor: Platform.select({
ios: "rgba(255, 255, 255, 0.05)",
android: "rgba(255, 255, 255, 0.05)",
default: "transparent",
}),
borderRadius: 8,
},
sectionTitle: {
fontSize: Platform.isTV ? 24 : 20,
fontWeight: "bold",
marginBottom: 16,
paddingTop: 8,
},
row: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
marginBottom: 12,
},
label: {
fontSize: Platform.isTV ? 18 : 16,
color: "#999",
},
value: {
fontSize: Platform.isTV ? 18 : 16,
},
newVersion: {
color: "#00bb5e",
fontWeight: "bold",
},
buttonContainer: {
flexDirection: "row",
gap: 12,
marginTop: 16,
justifyContent: "center", // 居中对齐
alignItems: "center",
},
button: {
width: "90%",
...(Platform.isTV && {
// TV平台焦点样式
borderWidth: 2,
borderColor: "transparent",
}),
},
buttonText: {
color: "#ffffff",
fontSize: Platform.isTV ? 16 : 14,
fontWeight: "500",
},
hint: {
fontSize: Platform.isTV ? 14 : 12,
color: "#666",
marginTop: 12,
textAlign: "center",
},
});