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

@dimensional-innovations/electron-asset-loader

v2.1.2

Published

electron-asset-loader allows you download assets to the local file system and then access them through a custom scheme. This can help improve the performance of applications that have multiple or large files that need to be downloaded since they can be do

Downloads

5

Readme

@dimensional-innovations/electron-asset-loader

electron-asset-loader allows you download assets to the local file system and then access them through a custom scheme. This can help improve the performance of applications that have multiple or large files that need to be downloaded since they can be downloaded on startup and then be served from the local filesystem.

Getting Started

Install

Make sure you have @dimensional-innovations private package repository access, more info here: https://gitlab.com/dimensional-innovations/di-handbook/-/blob/master/gitlab-packages/gitlab-packages-setup.md Add the package using yarn or npm:

yarn add @dimensional-innovations/electron-asset-loader

or

npm install --save @dimensional-innovations/electron-asset-loader

Setup & Usage

In background.js or whichever file is used for main, call initAssetLoader to setup the custom scheme and handlers.

import { initAssetLoader } from '@dimensional-innovations/electron-asset-loader/dist/main';
import { app } from 'electron';

app.whenReady()
  .then(() => {
    initAssetLoader();
  });

Then in the render process call preloadAssets to download the asset and get the new url to use.

<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { preloadAssets } from '@dimensional-innovations/electron-asset-loader';

export default defineComponent({
  setup() {
    const videoUrl = ref<string>();

    onMounted(async () => {
      videoUrl.value = await preloadAssets('http://localhost:3000/static/video.mp4');
    });

    return {
      videoUrl
    };
  }
})
</script>

<template>
  <video v-if="videoUrl" :src="videoUrl" autoplay loop />
</template>

You can also call preloadAssets with with multiple urls.

<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { preloadAssets } from '@dimensional-innovations/electron-asset-loader';

export default defineComponent({
  setup() {
    const videos = ref<Array<string>>([]);

    onMounted(async () => {
      videos.value = await preloadAssets([
        'http://localhost:3000/static/video1.mp4',
        'http://localhost:3000/static/video2.mp4',
      ]);
    });

    return {
      videos
    };
  }
})
</script>

<template>
  <template v-for="url in videos">
    <video :src="url" autoplay loop />
  </template>
</template>

@dimensional-innovations/electron-background

If you are using the init script from @dimensional-innovations/electron-background, you can add the following in your main file to setup this package:

import { initAssetLoader } from '@dimensional-innovations/electron-asset-loader/dist/main';
import { init } from '@dimensional-innovations/electron-background';

init({
  ...
  plugins: [
    ...
    { afterReady: async (context) => initAssetLoader({ log: context.log }) },
    ...
  ]
})

Api Reference

initAssetLoader

The following options can be passed to initAssetLoader

scheme

The custom scheme to use to serve the assets. This defaults to "assets". Note that if this provided, the new scheme needs to passed to preloadAssets as well. For example:

initAssetLoader({ scheme: 'videos' });
preloadAsset({ key: 'testVideo', url: 'http://localhost:3000/static/video.mp4' }, 'videos');

assetDir

The path to the directory to save the downloaded assets in. This defaults to an "assets" folder in the userData directory.

preloadAsset

The following options can be passed to preloadAssets, either as a single object or as an array to load multiple files. When a string is passed to preloadAssets, the string is treated as the url and a unique key is generated automatically.

key

The unique key used to identify the asset.

url

The url to download the file from.

overwrite

Indicates if the local file should be replaced. If true this will cause the file to be downloaded again, even if it already exists. Defaults to false.

scheme

The scheme used to serve the asset. This is only required if a custom scheme was used when initializing the asset loader.

onProgress

As an asset is downloaded, a progress event is raised to share how much of the asset of the has been downloaded. onProgress can be called to register a callback for this event.

clearAssets

Removes all assets that are not currently loaded through preloadAsset.

scheme

The scheme used to serve the assets. This is only required if a custom scheme was used when initializing the asset loader.