Skip to content

Commit

Permalink
Added reboot dialog after installation and logs
Browse files Browse the repository at this point in the history
ehsan6sha committed Oct 8, 2024
1 parent db497fc commit cae55f7
Showing 2 changed files with 71 additions and 2 deletions.
45 changes: 44 additions & 1 deletion apps/box/src/screens/Plugin.screen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useState, useEffect } from 'react';
import { ScrollView, StyleSheet, TextInput, Linking } from 'react-native';
import {
ScrollView,
StyleSheet,
TextInput,
Linking,
Alert,
} from 'react-native';
import {
FxBox,
FxCard,
@@ -66,6 +72,42 @@ export const PluginScreen = () => {
const isInstalled = activePlugins.includes(name);
const { queueToast } = useToast();

const handleReboot = async () => {
try {
// Call the reboot method here
// For example: await fxblox.reboot();
queueToast({
type: 'success',
title: 'Reboot Initiated',
message: 'Your Blox is rebooting. Please wait...',
});
} catch (error) {
queueToast({
type: 'error',
title: 'Reboot Failed',
message: error.message || 'Failed to reboot Blox.',
});
}
};

const showRebootDialog = () => {
Alert.alert(
'Reboot Required',
'To complete the installation, your Blox needs to be rebooted. Would you like to reboot now?',
[
{
text: 'Reboot Now',
onPress: handleReboot,
style: 'destructive',
},
{
text: 'Reboot Later',
style: 'cancel',
},
]
);
};

useEffect(() => {
const fetchPluginInfo = async () => {
if (!name) {
@@ -143,6 +185,7 @@ export const PluginScreen = () => {
title: 'Success',
message: 'Plugin installed successfully',
});
showRebootDialog();
} else {
queueToast({
type: 'error',
28 changes: 27 additions & 1 deletion apps/box/src/screens/Settings/BloxLogs.screen.tsx
Original file line number Diff line number Diff line change
@@ -18,17 +18,37 @@ import { fxblox } from '@functionland/react-native-fula';
import { useLogger } from '../../hooks';
import { ActivityIndicator } from 'react-native';
import { copyToClipboard } from '../../utils/clipboard';
import { usePluginsStore } from '../../stores/usePluginsStore';

export const BloxLogsScreen = () => {
const logger = useLogger();
const [selectedValue, setSelectedValue] = React.useState<string>('');
const [log, setLog] = React.useState<string>('');
const [tailCount, setTailCount] = React.useState<string>('30');
const [tailCount, setTailCount] = React.useState<string>('50');
const [loadingLogs, setLoadingLogs] = React.useState<boolean>(false);
const [fulaIsReady] = useUserProfileStore((state) => [state.fulaIsReady]);
const [showOtherInput, setShowOtherInput] = React.useState<boolean>(false);
const { queueToast } = useToast();
const { colors } = useFxTheme();
const [activePlugins, setActivePlugins] = React.useState<string[]>([]);
const { listActivePlugins } = usePluginsStore();
const fetchActivePlugins = React.useCallback(async () => {
try {
const result = await listActivePlugins();
if (result.success) {
setActivePlugins(result.msg);
} else {
console.error('Failed to fetch active plugins:', result.message);
}
} catch (error) {
console.error('Error fetching active plugins:', error);
}
}, [listActivePlugins]);

React.useEffect(() => {
fetchActivePlugins();
}, [fetchActivePlugins]);

const sanitizeLogData = (logString: string) => {
// Regular expression to match non-printable characters except newlines
// This regex matches characters in the control characters range (0x00-0x1F and 0x7F-0x9F) except for newline (0x0A)
@@ -114,8 +134,14 @@ export const BloxLogsScreen = () => {
{ label: 'Select container name', value: '' },
{ label: 'Go-Fula', value: 'fula_go' },
{ label: 'Node', value: 'fula_node' },
{ label: 'IPFS', value: 'ipfs_host' },
{ label: 'IPFS Cluster', value: 'ipfs_cluster' },
{ label: 'Fx', value: 'fula_fxsupport' },
{ label: 'Service Logs', value: 'MainService' },
...activePlugins.map((plugin) => ({
label: plugin,
value: plugin,
})),
{ label: 'Other', value: 'Other' },
]}
title="Container Name"

0 comments on commit cae55f7

Please sign in to comment.