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

[upload] Downloading doesn't report the correct progress #1266

Closed
pxdl opened this issue May 1, 2024 · 7 comments
Closed

[upload] Downloading doesn't report the correct progress #1266

pxdl opened this issue May 1, 2024 · 7 comments

Comments

@pxdl
Copy link

pxdl commented May 1, 2024

When trying to download zip files using the @tauri-apps/plugin-upload plugin, the progress callback isn't reporting the correct length of the chunks being downloaded.

Here's an example (using console.log) of the total chunks reported not matching the entire size of the file:

Saving
Downloaded 1371 of 820420 bytes
Downloaded 2742 of 820420 bytes
Downloaded 4113 of 820420 bytes
Downloaded 5484 of 820420 bytes
Downloaded 6855 of 820420 bytes
Asset downloaded

Here's an example of the total chunks reported properly matching the actual size of the file:

Saving
Downloaded 1371 of 5210 bytes
Downloaded 2742 of 5210 bytes
Downloaded 4113 of 5210 bytes
Downloaded 5210 of 5210 bytes
Asset downloaded

Some bigger files also work and other don't, so I don't think it has to do with the size of the file.

Here's my JavaScript code calling the @tauri-apps/plugin-upload plugin:

let receivedLength = 0;

// Download asset
await download(assetUrl, downloadPathTest, ({ progress, total }) => {
  receivedLength += progress;
  console.log(`Downloaded ${receivedLength} of ${total} bytes`);
});

Is there some kind of compression going on during the download? How to report the actual progress?

@Legend-Master
Copy link
Contributor

This will probably get fixed in #1237, we need to update tauri api version to apply the fix made in tauri-apps/tauri#9463

@FabianLars
Copy link
Member

New packages were released, can you make sure to update all tauri related packages (both rust and js) and then try again?

@pxdl
Copy link
Author

pxdl commented May 1, 2024

After updating all packages to the latest version, this bug seems to have been fixed, thank you!

@pxdl pxdl closed this as completed May 1, 2024
@pxdl
Copy link
Author

pxdl commented May 2, 2024

After some testing, I noticed that the plugin worked fine at first, even when downloading large files. But now it doesn't seem to be working properly, it seems to choke when sending updates to the channel and only properly updates when the download finishes, especially with large files. After this happens, lots of errors pop up on the console after reloading the page, which can be further detailed in the Network tab:

image

These errors keep popping up until I restart the program completely, reloading the page isn't enough.

This is how I'm updating the download progress state (I'm passing down the handleDownloadProgress function to where I call the plugin):

function reducer(state, action) {
  switch (action.type) {
    case 'reset':
      return { total: 0, downloaded: 0 };
    case 'downloaded_chunk':
      return {
        downloaded:
          action.total !== state.total
            ? action.chunk
            : state.downloaded + action.chunk,
        total: action.total,
      };
    default:
      throw Error('Unknown action.');
  }
}

function Updater() {
const [downloadState, dispatchDownloadState] = useReducer(reducer, {
    total: 0,
    downloaded: 0,
  });

const handleDownloadProgress = ({
    progress,
    total,
  }: {
    progress: number;
    total: number;
  }) => {
    dispatchDownloadState({ type: 'downloaded_chunk', chunk: progress, total });
  };
  
  return (
    <Text>{`${downloadState.downloaded} bytes / ${downloadState.total} bytes`}</Text>
  );
}

Here's a small gif showing what happens. This was working fine a while ago, updating in real time:
msedgewebview2_CKELyv4L2l

@pxdl pxdl reopened this May 2, 2024
@FabianLars
Copy link
Member

Fairly sure this is not the plugin's fault but an issue with the Channel api. I could swear i talked about this somewhere before but i can't find the issue or discord discussion 🤔

@pxdl
Copy link
Author

pxdl commented May 3, 2024

It seems related to this issue on the tauri repository: tauri-apps/tauri#8177

Given that the issue doesn't seem to be related to the plugin, but to the channel API, I'm closing it again.

@FabianLars I noticed that you implemented some sort of workaround on dd8bc4a, are there any plans to implement event emission throttling on the main branch?

@FabianLars
Copy link
Member

I'm not sure if it's really 8177. This emit issue makes the whole app crash while we're just talking about lost events. Considering that we're talking about v1 vs v2 it may be the same issue just without the crash due to refactoring, not sure.

As long as we're in beta (hoping that we figure out the issue) i won't add the throttle. Once we're running out of time and don't have a fix, i'll add it though.

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

3 participants