Skip to content

Commit

Permalink
Added limit for auto connect loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrvel committed Dec 28, 2020
1 parent a56cb7c commit 148005b
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 128 deletions.
4 changes: 4 additions & 0 deletions app/constants/index.js
Expand Up @@ -27,3 +27,7 @@ export const FILE_EXPLORER_TABLE_TRUNCATE_MAX_CHARS = 37;
export const FILE_EXPLORER_GRID_TRUNCATE_MAX_CHARS = 20;

export const DONATE_PAYPAL_URL = `https://paypal.me/ganeshrvel`;

export const USB_HOTPLUG_MAX_ATTEMPTS = 5;

export const USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT = 10000; // in ms
1 change: 1 addition & 0 deletions app/containers/App/components/Titlebar.jsx
Expand Up @@ -13,6 +13,7 @@ class Titlebar extends PureComponent {

const selectedStorage = getSelectedStorage(mtpStoragesList);
const windowHash = getCurrentWindowHash();

return (
<div
onDoubleClick={() => {
Expand Down
46 changes: 44 additions & 2 deletions app/containers/HomePage/components/FileExplorer.jsx
Expand Up @@ -64,7 +64,12 @@ import {
makeMtpMode,
makeShowDirectoriesFirst,
} from '../../Settings/selectors';
import { DEVICES_LABEL, DONATE_PAYPAL_URL } from '../../../constants';
import {
DEVICES_LABEL,
DONATE_PAYPAL_URL,
USB_HOTPLUG_MAX_ATTEMPTS,
USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT,
} from '../../../constants';
import {
arrayAverage,
getPluralText,
Expand Down Expand Up @@ -188,7 +193,10 @@ class FileExplorer extends Component {
shift: false,
};

this.usbHotplugTimerId = null;
this.usbHotplug = {
attempts: 0,
lastAttempted: Date.now(),
};
}

componentDidMount() {
Expand Down Expand Up @@ -389,6 +397,40 @@ class FileExplorer extends Component {
return;
}

// if [this.usbHotplug] is null then set the object
if (!this.usbHotplug) {
this.usbHotplug = {
attempts: 1,
lastAttempted: Date.now(),
};
} else {
// if the last attempt to connect the device was made more than [USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT] milliseconds ago then reset the attempts counter
if (
Date.now() - this.usbHotplug.lastAttempted >=
USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT
) {
this.usbHotplug = {
// update the number of attempts
attempts: 0,
lastAttempted: Date.now(),
};
}

// check for the number of connect attempts
// if the number of connect attempts are greater than [USB_HOTPLUG_MAX_ATTEMPTS]
// and if the [lastAttempted] and was made within [USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT] then don't connect
else if (
this.usbHotplug.attempts > USB_HOTPLUG_MAX_ATTEMPTS &&
Date.now() - this.usbHotplug.lastAttempted <
USB_HOTPLUG_MAX_ATTEMPTS_TIMEOUT
) {
return;
}

// update the number of attempts
this.usbHotplug.attempts += 1;
}

switch (eventName) {
case USB_HOTPLUG_EVENTS.detach:
// if an usb device was detached and mtp device is disconnected then
Expand Down

This file was deleted.

Expand Up @@ -27,7 +27,7 @@ import { styles } from '../styles/FileExplorerTableBodyEmptyRender';
import KeyboadShortcuts from '../../KeyboardShortcutsPage/components/KeyboadShortcuts';
import Features from '../../Onboarding/components/Features';
import { Notification as NotificationDialog } from '../../../components/DialogBox';
import FileExplorerTableBodyEmptyHelpPhoneNotRecognizedRender from './FileExplorerTableBodyEmptyHelpPhoneNotRecognizedRender';
import HelpPhoneNotRecognized from './HelpPhoneNotRecognized';
import { helpPhoneNotConnecting } from '../../../templates/fileExplorer';
import { analyticsService } from '../../../services/analytics';
import { EVENT_TYPE } from '../../../enums/events';
Expand Down Expand Up @@ -288,11 +288,9 @@ class FileExplorerTableBodyEmptyRender extends PureComponent {

<NotificationDialog
fullWidthDialog
maxWidthDialog="sm"
maxWidthDialog="md"
titleText={helpPhoneNotConnecting}
bodyText={
<FileExplorerTableBodyEmptyHelpPhoneNotRecognizedRender />
}
bodyText={<HelpPhoneNotRecognized />}
trigger={showHelpPhoneNotRecognizedDialog}
onClickHandler={this._handleHelpPhoneNotRecognizedDialog}
/>
Expand Down
109 changes: 109 additions & 0 deletions app/containers/HomePage/components/HelpPhoneNotRecognized.jsx
@@ -0,0 +1,109 @@
import React, { PureComponent } from 'react';
import { withStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import ExpansionPanel from '@material-ui/core/ExpansionPanel';
import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary';
import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails';
import Typography from '@material-ui/core/Typography';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import { styles } from '../styles/HelpPhoneNotRecognized';
import { openExternalUrl } from '../../../utils/url';
import { APP_GITHUB_ISSUES_URL } from '../../../constants/meta';
import { analyticsService } from '../../../services/analytics';
import { EVENT_TYPE } from '../../../enums/events';

class HelpPhoneNotRecognized extends PureComponent {
_handleGithubThreadTap = (events) => {
openExternalUrl(`${APP_GITHUB_ISSUES_URL}8`, events);

analyticsService.sendEvent(
EVENT_TYPE.MTP_HELP_PHONE_NOT_CONNECTED_GITHUB_THREAD_TAP,
{}
);
};

render() {
const { classes: styles } = this.props;

return (
<div className={styles.root}>
<Paper elevation={0}>
<ExpansionPanel className={styles.expansionRoot}>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography className={styles.heading}>
Expansion Panel 1
</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse malesuada lacus ex, sit amet blandit leo lobortis
eget.
</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel className={styles.expansionRoot}>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
>
<Typography className={styles.heading}>
Expansion Panel 2
</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse malesuada lacus ex, sit amet blandit leo lobortis
eget.
</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel className={styles.expansionRoot}>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
>
<Typography className={styles.heading}>
Expansion Panel 2
</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse malesuada lacus ex, sit amet blandit leo lobortis
eget.
</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
<ExpansionPanel className={styles.expansionRoot}>
<ExpansionPanelSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
>
<Typography className={styles.heading}>
Expansion Panel 2
</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse malesuada lacus ex, sit amet blandit leo lobortis
eget.
</Typography>
</ExpansionPanelDetails>
</ExpansionPanel>
</Paper>
</div>
);
}
}

export default withStyles(styles)(HelpPhoneNotRecognized);

This file was deleted.

10 changes: 10 additions & 0 deletions app/containers/HomePage/styles/HelpPhoneNotRecognized.js
@@ -0,0 +1,10 @@
export const styles = (_) => ({
root: {
minHeight: 400,
overflowY: 'auto',
maxHeight: 400,
},
expansionRoot: {
background: '#383838',
},
});
Binary file modified build/mac/bin/kalam.dylib
Binary file not shown.
Binary file modified build/mac/bin/kalam_debug_report
Binary file not shown.
10 changes: 0 additions & 10 deletions ffi/kalam/native/kalam.go
Expand Up @@ -90,16 +90,6 @@ func _sendFetchStorages(ptr int64, retry bool) {
if err != nil {
if container.dev != nil && container.deviceInfo != nil {
if strings.Contains(err.Error(), "EOF") {

// for newer samsung devices we might need to access the storage again in case
// the fetch storage function returns an 'EOF' error
if retry {
// make sure the retry param is false else mtp could go into infinite loop
_sendFetchStorages(ptr, false)

return
}

err = fmt.Errorf("error allow storage access. %+v", err.Error())

// this is done to prevent samsung devices from returning usb timeouts
Expand Down

0 comments on commit 148005b

Please sign in to comment.