Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'start' of undefined #203

Open
sitannsu opened this issue Dec 18, 2023 · 3 comments
Open

Cannot read property 'start' of undefined #203

sitannsu opened this issue Dec 18, 2023 · 3 comments

Comments

@sitannsu
Copy link

await BackgroundService.start(veryIntensiveTask, options);  it throws  Cannot read property 'start' of undefined 
@Omare123
Copy link

Omare123 commented Jan 10, 2024

I've been fighting this all day too.

`import { StatusBar } from 'expo-status-bar';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { Header } from './src/Components/Header';
import { useEffect, useState, useRef} from 'react';
import React from 'react';
import { PomodoroContainer } from './src/Components/PomodoroContainer';
import { PomodoroButton } from './src/Components/PomodoroButton';
import { Timer } from './src/Components/Timer';
import * as Notifications from 'expo-notifications';
import * as Device from 'expo-device';
import BackgroundService from 'react-native-background-actions';

const FOCUS_TIME_MINUTES = 0.1 * 60 * 1000;
const BREAK_TIME_MINUTES = 0.05 * 60 * 1000;
const LONG_BREAK_TIME_MINUTES = 0.1 * 60 * 1000;
const BREAK_TIMES = 3;
const FOCUS = "Focus";
const BREAK = "Break"

const sleep = (time) => new Promise((resolve) => setTimeout(() => resolve(null), time));

const veryIntensiveTask = async (taskDataArguments) => {
// Example of an infinite loop task
const { delay } = taskDataArguments;
await new Promise(async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log(i);
await BackgroundService.updateNotification({taskDesc: Running...${i}});
await sleep(delay);
}
});
};

const options = {
taskName: 'Example',
taskTitle: 'ExampleTask title',
taskDesc: 'ExampleTask description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
linkingURI: 'pomodoro://chat/jane', // See Deep Linking for more info
parameters: {
delay: 1000,
},
};
export default function App() {
const [timerCount, setTimerCount] = useState(FOCUS_TIME_MINUTES);
const [timerIntervalId, setTimerIntervalId] = useState<NodeJS.Timeout | null>(null);
const [breakTimerCount, setBreakTimerCount] = useState(BREAK_TIMES);
const [timerMode, setTimerMode] = useState<"Focus" | "Break">(FOCUS);
const timerDate = new Date(timerCount);

const startBackgroundService = async () => {
await BackgroundService.start(veryIntensiveTask, options);
await BackgroundService.updateNotification({taskDesc: 'Running...'});
}
const stopBackgroundService = async () => {
await BackgroundService.stop();
}
const startTimer = async () =>{
let id = setInterval(() => setTimerCount(prev => prev - 1000), 1000);
setTimerIntervalId(id);
}

function stopTimer(){
if(timerIntervalId !== null){
clearInterval(timerIntervalId);
setTimerIntervalId(null);
}
}

function resetTimer(){
if(timerIntervalId !== null){
stopTimer();
}
setTimerCount(FOCUS_TIME_MINUTES);
setTimerMode(FOCUS);
}

return (


{timerMode === FOCUS ? "Time to focus!" : "Time for a break!"}
<PomodoroButton action={!timerIntervalId ? startBackgroundService : stopBackgroundService} color={'#b4a12d'} text={!timerIntervalId ? 'Start' : 'Stop'}/>
<PomodoroButton action={resetTimer} color={'#4c5a23'} text={'Reset'}/>

);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
flexDirection: 'column',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'center',
minHeight: '10%',
width: '100%'
}
});
`

@mr2726
Copy link

mr2726 commented Feb 20, 2024

Did you find a solution?

@MarkNaArea
Copy link

PR #208 worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants