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

@el3um4s/ipc-for-electron-auto-updater

v1.0.2

Published

Allow the renderer to update electron apps

Downloads

10

Readme

IPC for Electron: Auto Updater

Allow the renderer to update electron apps via electron-updater

NPM link: @el3um4s/ipc-for-electron-auto-updater

Use @el3um4s/ipc-for-electron and @el3um4s/renderer-for-electron-auto-updater to allow communication between Electron and a web page

Install and use the package

To use the package in a project:

npm i @el3um4s/ipc-for-electron @el3um4s/ipc-for-electron-auto-updater @el3um4s/renderer-for-electron-auto-updater

Then the preload.ts file:

import { generateContextBridge } from "@el3um4s/ipc-for-electron";
import autoUpdater from "@el3um4s/ipc-for-electron-auto-updater";

const listAPI = [autoUpdater];

generateContextBridge(listAPI);

In main electron file (index.ts):

import autoUpdater from "@el3um4s/ipc-for-electron-auto-updater";

autoUpdater.initAutoUpdater(mainWindow);
autoUpdater.checkForUpdates();

// to start donwloading the update
autoUpdater.startDownloadUpdate();

// to restart the electron app and install the new version
autoUpdater.quitAndInstall();

In the renderer file:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

let version: string;

autoUpdater.requestVersionNumber({
  apiKey: "my-api-key",
  callback: (data) => {
    version = data.version;
  },
});

autoUpdater.checkForUpdates({
  apiKey: "my-api-key",
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update available", version, releaseName, releaseDate);
    autoUpdater.startDownloadUpdate({ apiKey: "my-api-key" });
  },
});

autoUpdater.on.downloadProgress({
  callback: (data) => {
    const { total, delta, transferred, percent, bytesPerSecond } = data;
    console.log(
      "Download progress",
      total,
      delta,
      transferred,
      percent,
      bytesPerSecond
    );
  },
});

autoUpdater.on.updateDownloaded({
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update downloaded", version, releaseName, releaseDate);
    autoUpdater.quitAndInstall();
  },
});

In the renderer you can use:

let version: string;

globalThis.api.autoUpdater.send("requestVersionNumber", null);
globalThis.api.autoUpdater.receive("getVersionNumber", (data) => {
  version = data.version;
});

API: Electron Side

  • requestVersionNumber - Request the version number. The response is sent to the getVersionNumber channel
  • checkForUpdates - Check if an update is available. The response is sent to the updateAvailable channel (or via the updateNotAvailable channel if no update is available)
  • startDownloadUpdate - Request to start downloading the update. The response is sent to the downloadProgress channel
  • quitAndInstall - Request to quit and install the update. The response is sent to the updateDownloaded channel

If an error occurs, the response is sent to the errorOnAutoUpdate channel.

API: Renderer Side - Request

requestVersionNumber = async (options: { callback?: (arg0: VersionNumber) => void; apiKey?: string; }): Promise<VersionNumber>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

let version: string;

autoUpdater.requestVersionNumber({
  apiKey: "my-api-key",
  callback: (data) => {
    version = data.version;
  },
});

checkForUpdates = async (options: { callback?: (arg0: UpdateInfo) => void; apiKey?: string; }): Promise<UpdateInfo>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates({
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update available", version, releaseName, releaseDate);
    autoUpdater.startDownloadUpdate({ apiKey: "my-api-key" });
  },
});

startDownloadUpdate = async (options: { apiKey?: string; }): Promise<void>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.startDownloadUpdate();

quitAndInstall = async (options: { apiKey?: string }): Promise<void>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.on.updateDownloaded({
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update downloaded", version, releaseName, releaseDate);
    autoUpdater.quitAndInstall();
  },
});

API: Renderer Side - Response

on.getVersionNumber = async (options: { callback?: (arg0: VersionNumber) => void; apiKey?: string; }): Promise<VersionNumber>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

let version: string;

autoUpdater.requestVersionNumber();

autoUpdater.on.getVersionNumber({
  callback: (data) => {
    version = data.version;
    console.log("Version number", version);
  },
});

on.errorOnAutoUpdate = async (options: { callback?: (arg0: Error) => void; apiKey?: string; }): Promise<Error>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.errorOnAutoUpdate({
  callback: (data) => {
    console.log("Error on auto update");
    console.log(data);
  },
});

on.checkingForUpdate = async (options: { callback?: () => void; apiKey?: string; }): Promise<void>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.checkingForUpdate({
  callback: () => {
    console.log("Checking for update...");
  },
});

on.updateAvailable = async (options: { callback?: (arg0: UpdateInfo) => void; apiKey?: string; }): Promise<UpdateInfo>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.updateAvailable({
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update available", version, releaseName, releaseDate);
    autoUpdater.startDownloadUpdate();
  },
});

on.updateNotAvailable = async (options: { callback?: (arg0: UpdateInfo) => void; apiKey?: string; }): Promise<UpdateInfo>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.updateNotAvailable({
  callback: (data) => {
    console.log("Update not available", data);
  },
});

on.downloadProgress = async (options: { callback?: (arg0: ProgressInfo) => void; apiKey?: string; }): Promise<ProgressInfo>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.downloadProgress({
  callback: (data) => {
    const { total, delta, transferred, percent, bytesPerSecond } = data;
    console.log(
      "Download progress",
      total,
      delta,
      transferred,
      percent,
      bytesPerSecond
    );
  },
});

on.updateDownloaded = async (options: { callback?: (arg0: UpdateDownloadedEvent) => void; apiKey?: string; }): Promise<UpdateDownloadedEvent>

example:

import autoUpdater from "@el3um4s/renderer-for-electron-auto-updater";

autoUpdater.checkForUpdates();

autoUpdater.on.updateDownloaded({
  callback: (data) => {
    const { version, releaseName, releaseDate } = data;
    console.log("Update downloaded", version, releaseName, releaseDate);
    autoUpdater.quitAndInstall();
  },
});

Types

VersionNumber

interface VersionNumber {
  version: string;
}

UpdateInfo

interface UpdateInfo {
  version: string;
  releaseName: string | undefined;
  releaseDate: string;
}

UpdateDownloadedEvent

interface UpdateDownloadedEvent extends UpdateInfo {
  downloadedFile: string;
}

ProgressInfo

interface ProgressInfo {
  total: number;
  delta: number;
  transferred: number;
  percent: number;
  bytesPerSecond: number;
}

DefaultApiKey

type DefaultApiKey = "ipc";