GithubHelp home page GithubHelp logo

capawesome-team / capacitor-background-task Goto Github PK

View Code? Open in Web Editor NEW
51.0 6.0 7.0 856 KB

⚡️ Capacitor plugin for running background tasks.

Home Page: https://capawesome.io/plugins/background-task/

License: MIT License

Ruby 11.46% Java 27.68% Swift 29.26% Objective-C 8.74% JavaScript 5.62% TypeScript 17.25%
capacitor capacitor-plugin ios capacitor-community capacitor-ios capawesome

capacitor-background-task's People

Contributors

dependabot[bot] avatar robingenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

capacitor-background-task's Issues

iOS Time Execution Longer than 30s?

The UIApplication BG implementation of iOS seems to have a time execution of 30s, max. Does this plugin also adhere to the same limitations?

bug: Called Hundreds of Times Inside useEffect()

Plugin version:
1.0.1

Platform(s):
IOS and Android

Current behavior:
Keep calling the parent function hundreds of times

Expected behavior:
Should run once

Steps to reproduce:

I am placing the const taskId = await BackgroundTask.beforeExit(async () => { inside useEffect().
I am expecting that the http request and updateDB() to be ran background. This is to prevent sudden termination from the user after sending http request and before updating the database. It can cause problem because the data need to be synced. If the user terminate the app after sending http request and not updating the database after that, the next time the user launch the application, the application will try to send the http request to the server, this cause duplicate data being sent.

However this code behaves incredibly weird, the const syncingOut = async () => { is called hundreds of times causing hundreds of http request and updateDB() being called simultaneously. It should be called once.

Related code:

export const useSynchronizer = () => {

  .....
  .....

  useEffect(() => {
    if (syncOut.length > 0) syncingOut()
  }, [syncOut, isSyncingOut]);

  const syncingOut = async () => {
    if (!isSyncingOut) {
      dispatch(setIsSyncingOut(true));
      if (syncOut.length > 0) {
        let job = syncOut[0];
        switch (job.type) {
          case 'POST': {
              const taskId = await BackgroundTask.beforeExit(async () => {
                let r = await Http.post(nav, job.url, job.params, job.model, job.syncToken);
                await updateDB(r, job);
                BackgroundTask.finish({ taskId });
              });
              break;
          }
          case 'PUT': {
              const taskId = await BackgroundTask.beforeExit(async () => {
                let r = await Http.put(nav, job.url, job.params, job.model, job.syncToken);
                await updateDB(r, job);
                BackgroundTask.finish({ taskId });
              });
              break;
          }
          case 'DELETE': {
            if (!isWeb()) {
              const taskId = await BackgroundTask.beforeExit(async () => {
                let r = await Http.delete(nav, job.url, job.params, job.syncToken);
                await updateDB(r, job);
                BackgroundTask.finish({ taskId });
              });
              break;
          }
        }
        dispatch(setIsSyncingOut(false));
      } else {
        dispatch(setIsSyncingOut(false));
      }
    }
  }

Other information:
None

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 3.6.0
  @capacitor/core: 3.6.0
  @capacitor/android: 3.6.0
  @capacitor/ios: 3.6.0

Installed Dependencies:

  @capacitor/cli: 3.4.0
  @capacitor/core: 3.5.1
  @capacitor/android: 3.4.0
  @capacitor/ios: 3.4.0

[success] iOS looking great! 👌
[success] Android looking great! 👌```

feat: Finish function that already started

Is your feature request related to a problem? Please describe:

If i start a progress, let's say an upload function already before the on exit event. How would the logic be to continue this function?

Ask for help

I have an issue with the app and background working. Can anybody help me?

I made an app for the clinic and all works well while they are in-app but when for example pick up the phone or want to reply to a message looks the state of the app lose and they can't navigate through the application (the back button dissipated) and need to kill the app and start it again. Is there any solution to it?

I made a "hack" in the app.component.ts file:

App.addListener('appStateChange', ({isActive}) => {
if (!isActive) {
// App went to background
} else {
// App went to foreground
this.navCtrl.navigateRoot(['./']);
}
});
but when I add that user can't take a picture of the patient or change his avatar, it always backs him on the homepage :( I use a capacitor to build apps. Is there any solution to save the state to not lose on which page the user exists and where he can go back?
I hope that this plugin can help me but I didn't know how to make that part of the code instead of navigating to root :( Please help me.

feat: add Android implementation

Is your feature request related to a problem? Please describe:

There is currently no ready implementation on Android.

Describe the solution you'd like:

Add an implementation for Android.

feat: How can i keep listen to bluetooth data?

Is your feature request related to a problem? Please describe:
I have a scenario where i have bluetooth sensor connected to my application. I am receiving continues data from bluetooth. My issue is when application go to background i want to keep listen to that data on both platforms android / ios.

Describe the solution you'd like:
keep my bluetooth listener active in background mode to receive data.

Describe alternatives you've considered:
as per this Plugin cordova-plugin-background-mode it says "perform infinite background execution"

Additional context:
I am using cordova-pluign-media-capture to record videos. but when i open camera application goes into background so i want to listen to Bluetooth data in background.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.