npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

capacitor-plugin-downloader

v2.1.7

Published

Capacitor plugin for downloader in native apps (Android/iOS). Clone from https://github.com/triniwiz/capacitor-downloader because of without maintainance.

Downloads

4

Readme

Capacitor Downloader

🔥 IMPORTANT: This plugin based on Capacitor Downloader.

The author made a awesome plugin but the reason is he doesn't maintain this great plugin. I decide to clone this for personal purposes.

  • [x] Upgrade iOS dependencies
  • [x] Upgrade Android dependencies
  • [x] Integrate Android notification progress when downloading
  • [ ] Android resume, cancel, pause

npm npm Build Status

Installation

  • npm i capacitor-plugin-downloader

Android

Add import co.fitcom.capacitor.Downloader.DownloaderPlugin; and add(DownloaderPlugin.class); in the app's MainActivity.java like this:

import co.fitcom.capacitor.Downloader.DownloaderPlugin;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      add(DownloaderPlugin.class);
    }});
  }
}

API

| Method | Default | Android | iOS | Type | Description | | ---------------------------------------- | ------- | -------- | -------- | -------- | ----------------------------------------------------- | | initialize() | | X | X | Promise<void> | Initialize plugin in native. | | createDownload(options: DownloadOptions) | | X | X | Promise<IdResponse> | Creates a download task it returns the id of the task | | start(options:Options, progress?: Function) | | X | X | Promise<IdResponse> | Starts a download task. | | | resume(options:Options) | | X | | Promise<IdResponse> | Resumes a download task. | | cancel(options:Options) | | X | | Promise<IdResponse> | Cancels a download task. | | pause(options:Options) | | X | | Promise<IdResponse> | Pauses a download task. |

Usage

import { Downloader, DownloadEventData, ProgressEventData } from 'capacitor-downloader';
const downloader = new Downloader();
const { id } = await downloader.createDownload({
  url:
    'https://wallpaperscraft.com/image/hulk_wolverine_x_men_marvel_comics_art_99032_3840x2400.jpg'
});
downloader.start({ id });
downloader.addListener('progressUpdate', (progressData: ProgressEventData) => {
    console.log(`Progress ID : ${progressData.id}%`);
    console.log(`Current Size : ${progressData.currentSize}%`);
    console.log(`Total Size : ${progressData.totalSize}%`);
    console.log(`Download Speed in bytes : ${progressData.speed}%`);
})

downloader.addListener('downloadedSucceed', (data: DownloadedSucceedEvent) => {
    console.log(`Progress ID : ${progressData.id}%`);
    console.log(`Absolute Path : ${progressData.path}%`);
})

downloader.addListener('downloadedFailed', (data: DownloadedFailedEvent) => {
    console.log(`Progress ID : ${progressData.id}%`);
    console.log(`Error Code : ${progressData.code}%`);
    console.log(`Error Message : ${progressData.message}%`);
})

API Interface


export interface IDownloader {
  addListener<T extends Listeners>(
    event: T,
    callback: ListenerCallbacks[T]
  ): PluginListenerHandle;
  initialize(): Promise<void>;
  createDownload(options: DownloadOptions): Promise<IdResponse>;
  start(id: string): Promise<IdResponse>;
  pause(id: string): Promise<IdResponse>; // only with iOS
  resume(id: string): Promise<IdResponse>; // only with iOS
  cancel(id: string): Promise<IdResponse>; // only with iOS
}

export type Listeners =
  | 'progressUpdate'
  | 'downloadedSucceed'
  | 'downloadedFailed';
export type ListenerCallbacks = {
  progressUpdate: (event: ProgressEvent) => void;
  downloadedSucceed: (event: DownloadedSucceedEvent) => void;
  downloadedFailed: (event: DownloadedFailedEvent) => void;
};

export interface DownloadedFailedEvent {
  id: string;
  code: DownloadErrorCodes;
  message: DownloadErrorMessages;
}

export interface DownloadedSucceedEvent {
  id: string;
  path: string;
}
export interface ProgressEvent {
  id: string;
  currentSize: number;
  totalSize: number;
  speed?: number; // only with iOS
}

export interface IdResponse {
  id: string;
}

export enum StatusCode {
  PENDING = 'pending',
  PAUSED = 'paused',
  DOWNLOADING = 'downloading',
  COMPLETED = 'completed',
  ERROR = 'error',
}
export type DownloadErrorCodes = 1;
export type DownloadErrorMessages = {
  1: 'File not found';
};

export interface DownloadOptions {
  url: string;
  fileName: string;
}