schoolx-ota-manager
Version:
React Native library for managing OTA updates with GitLab integration
61 lines • 2.82 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { View, Text, Button, StyleSheet } from 'react-native';
import { withOTAUpdate } from './OTAUpdate';
// Component with OTA props injected by HOC
const ExampleComponent = ({ title, otaCheckUpdate, otaInstallUpdate, otaCheckAndInstallUpdate, otaUpdateInfo, otaIsChecking, otaIsInstalling, }) => {
const handleCheckUpdate = async () => {
const updateInfo = await otaCheckUpdate();
console.log('Update info:', updateInfo);
};
const handleInstallUpdate = async () => {
const success = await otaInstallUpdate();
console.log('Install success:', success);
};
const handleCheckAndInstall = async () => {
const success = await otaCheckAndInstallUpdate();
console.log('Check and install success:', success);
};
return (_jsxs(View, { style: styles.container, children: [_jsx(Text, { style: styles.title, children: title }), _jsxs(View, { style: styles.statusContainer, children: [_jsxs(Text, { style: styles.statusText, children: ["Status: ", otaIsChecking ? 'Checking...' : otaIsInstalling ? 'Installing...' : 'Idle'] }), otaUpdateInfo && (_jsxs(Text, { style: styles.updateText, children: ["Update available: ", otaUpdateInfo.hasUpdate ? 'Yes' : 'No'] }))] }), _jsxs(View, { style: styles.buttonContainer, children: [_jsx(Button, { title: "Check Update", onPress: handleCheckUpdate, disabled: otaIsChecking || otaIsInstalling }), _jsx(Button, { title: "Install Update", onPress: handleInstallUpdate, disabled: !(otaUpdateInfo === null || otaUpdateInfo === void 0 ? void 0 : otaUpdateInfo.hasUpdate) || otaIsInstalling }), _jsx(Button, { title: "Check & Install", onPress: handleCheckAndInstall, disabled: otaIsChecking || otaIsInstalling })] })] }));
};
// OTA configuration
const otaConfig = {
gitlabToken: 'your-gitlab-token',
gitlabBaseUrl: 'https://gitlab.com/api/v4',
gitlabProjectId: 'your-project-id',
repoFolder: 'ota-bundles',
platform: 'ios', // Will be overridden by HOC
autoUpdate: false,
};
// Wrap the component with OTA functionality
export const ExampleWithOTA = withOTAUpdate(ExampleComponent, otaConfig);
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#f5f5f5',
},
title: {
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
marginBottom: 20,
},
statusContainer: {
backgroundColor: 'white',
padding: 15,
borderRadius: 8,
marginBottom: 20,
},
statusText: {
fontSize: 16,
marginBottom: 10,
},
updateText: {
fontSize: 14,
color: '#666',
},
buttonContainer: {
gap: 10,
},
});
//# sourceMappingURL=OTAUpdateExample.js.map