angularelectronelectron-builderelectron-updater

How to call electron-updater outside the main rendering process


Im creating a desktop app using angular-electron
I'm using electron-builder for packaging that supports auto updates with electron-updater

Everything is working by calling the functions from the entry point main.ts

import {autoUpdater} from 'electron-updater';
autoUpdater.checkForUpdatesAndNotify();

I would like to call checkForUpdatesAndNotify from angular so the user can check for update manually by clicking on a button.
First, I tried with the same way i've done it in main.ts but the method couldn't be found. So I'm trying to get it by the remote, but I'm still getting an error.

import { remote } from 'electron';

@Injectable()
export class UpdaterService {
  console.log('try update');
  remote.require('electron-updater').checkForUpdatesAndNotify();
  console.log('success');
}

uncaught TypeError: remote.require(...).checkForUpdatesAndNotify is not a function
    at SafeSubscriber._next (updater.service.ts:17)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:192)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:130)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:76)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber.notifyNext (mergeMap.js:84)
    at InnerSubscriber.push../node_modules/rxjs/_esm5/internal/InnerSubscriber.js.InnerSubscriber._next (InnerSubscriber.js:15)
    at InnerSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)
    at ThrowIfEmptySubscriber.push../node_modules/rxjs/_esm5/internal/operators/throwIfEmpty.js.ThrowIfEmptySubscriber._next (throwIfEmpty.js:32)
    at ThrowIfEmptySubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)

What's wrong ?


Solution

  • It was remote.require('electron-updater').autoUpdater.checkForUpdates()