feat(update): add toast notifications for update failures

- Add toast error messages when version check fails
- Show user-friendly error notifications for download failures
- Display specific installation error messages with troubleshooting hints
- Improve logging from console.error to console.info for better categorization
This commit is contained in:
zimplexing
2025-08-13 18:58:32 +08:00
parent df8fae96ac
commit fc81de1728
4 changed files with 21 additions and 12 deletions

View File

@@ -53,11 +53,11 @@ export function UpdateSection() {
</StyledButton> </StyledButton>
</View> </View>
{UPDATE_CONFIG.AUTO_CHECK && ( {/* {UPDATE_CONFIG.AUTO_CHECK && (
<ThemedText style={styles.hint}> <ThemedText style={styles.hint}>
自动检查更新已开启,每{UPDATE_CONFIG.CHECK_INTERVAL / (60 * 60 * 1000)}小时检查一次 自动检查更新已开启,每{UPDATE_CONFIG.CHECK_INTERVAL / (60 * 60 * 1000)}小时检查一次
</ThemedText> </ThemedText>
)} )} */}
</View> </View>
); );
} }

View File

@@ -1,5 +1,6 @@
import ReactNativeBlobUtil from "react-native-blob-util"; import ReactNativeBlobUtil from "react-native-blob-util";
import FileViewer from "react-native-file-viewer"; import FileViewer from "react-native-file-viewer";
import Toast from "react-native-toast-message";
import { version as currentVersion } from "../package.json"; import { version as currentVersion } from "../package.json";
import { UPDATE_CONFIG } from "../constants/UpdateConfig"; import { UPDATE_CONFIG } from "../constants/UpdateConfig";
@@ -46,9 +47,10 @@ class UpdateService {
}; };
} catch (error) { } catch (error) {
retries++; retries++;
console.error(`Error checking version (attempt ${retries}/${maxRetries}):`, error); console.info(`Error checking version (attempt ${retries}/${maxRetries}):`, error);
if (retries === maxRetries) { if (retries === maxRetries) {
Toast.show({ type: "error", text1: "检查更新失败", text2: "无法获取版本信息,请检查网络连接" });
throw error; throw error;
} }
@@ -140,9 +142,10 @@ class UpdateService {
return res.path(); return res.path();
} catch (error) { } catch (error) {
retries++; retries++;
console.error(`Error downloading APK (attempt ${retries}/${maxRetries}):`, error); console.info(`Error downloading APK (attempt ${retries}/${maxRetries}):`, error);
if (retries === maxRetries) { if (retries === maxRetries) {
Toast.show({ type: "error", text1: "下载失败", text2: "APK下载失败请检查网络连接" });
throw new Error(`Download failed after ${maxRetries} attempts: ${error}`); throw new Error(`Download failed after ${maxRetries} attempts: ${error}`);
} }
@@ -170,15 +173,21 @@ class UpdateService {
displayName: "OrionTV Update", displayName: "OrionTV Update",
}); });
} catch (error) { } catch (error) {
console.error("Error installing APK:", error); console.info("Error installing APK:", error);
// 提供更详细的错误信息 // 提供更详细的错误信息
if (error instanceof Error) { if (error instanceof Error) {
if (error.message.includes('No app found')) { if (error.message.includes('No app found')) {
Toast.show({ type: "error", text1: "安装失败", text2: "未找到可安装APK的应用请确保允许安装未知来源的应用" });
throw new Error('未找到可安装APK的应用请确保允许安装未知来源的应用'); throw new Error('未找到可安装APK的应用请确保允许安装未知来源的应用');
} else if (error.message.includes('permission')) { } else if (error.message.includes('permission')) {
Toast.show({ type: "error", text1: "安装失败", text2: "没有安装权限,请在设置中允许此应用安装未知来源的应用" });
throw new Error('没有安装权限,请在设置中允许此应用安装未知来源的应用'); throw new Error('没有安装权限,请在设置中允许此应用安装未知来源的应用');
} else {
Toast.show({ type: "error", text1: "安装失败", text2: "APK安装过程中出现错误" });
} }
} else {
Toast.show({ type: "error", text1: "安装失败", text2: "APK安装过程中出现未知错误" });
} }
throw error; throw error;

View File

@@ -124,7 +124,7 @@ const usePlayerStore = create<PlayerState>((set, get) => ({
try { try {
await videoRef?.current?.replayAsync(); await videoRef?.current?.replayAsync();
} catch (error) { } catch (error) {
console.error("Failed to replay video:", error); console.info("Failed to replay video:", error);
Toast.show({ type: "error", text1: "播放失败" }); Toast.show({ type: "error", text1: "播放失败" });
} }
} }
@@ -140,7 +140,7 @@ const usePlayerStore = create<PlayerState>((set, get) => ({
await videoRef?.current?.playAsync(); await videoRef?.current?.playAsync();
} }
} catch (error) { } catch (error) {
console.error("Failed to toggle play/pause:", error); console.info("Failed to toggle play/pause:", error);
Toast.show({ type: "error", text1: "操作失败" }); Toast.show({ type: "error", text1: "操作失败" });
} }
} }
@@ -154,7 +154,7 @@ const usePlayerStore = create<PlayerState>((set, get) => ({
try { try {
await videoRef?.current?.setPositionAsync(newPosition); await videoRef?.current?.setPositionAsync(newPosition);
} catch (error) { } catch (error) {
console.error("Failed to seek video:", error); console.info("Failed to seek video:", error);
Toast.show({ type: "error", text1: "快进/快退失败" }); Toast.show({ type: "error", text1: "快进/快退失败" });
} }

View File

@@ -73,7 +73,7 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
Date.now().toString() Date.now().toString()
); );
} catch (error) { } catch (error) {
console.error('检查更新失败:', error); // console.info('检查更新失败:', error);
set({ set({
error: error instanceof Error ? error.message : '检查更新失败', error: error instanceof Error ? error.message : '检查更新失败',
updateAvailable: false updateAvailable: false
@@ -110,7 +110,7 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
downloadProgress: 100, downloadProgress: 100,
}); });
} catch (error) { } catch (error) {
console.error('下载失败:', error); // console.info('下载失败:', error);
set({ set({
downloading: false, downloading: false,
downloadProgress: 0, downloadProgress: 0,
@@ -133,7 +133,7 @@ export const useUpdateStore = create<UpdateState>((set, get) => ({
// 安装开始后,关闭弹窗 // 安装开始后,关闭弹窗
set({ showUpdateModal: false }); set({ showUpdateModal: false });
} catch (error) { } catch (error) {
console.error('安装失败:', error); console.info('安装失败:', error);
set({ set({
error: error instanceof Error ? error.message : '安装失败', error: error instanceof Error ? error.message : '安装失败',
}); });
@@ -181,6 +181,6 @@ export const initUpdateStore = async () => {
skipVersion: skipVersion || null, skipVersion: skipVersion || null,
}); });
} catch (error) { } catch (error) {
console.error('初始化更新存储失败:', error); console.info('初始化更新存储失败:', error);
} }
}; };