maximegris / angular-electron

Ultra-fast bootstrapping with Angular and Electron :speedboat:
https://www.maximegris.fr/angular-electron/
MIT License
5.67k stars 1.37k forks source link

electron-updater not working (require('electron').app is undefined) #476

Closed agnoam closed 4 years ago

agnoam commented 4 years ago

I'm trying to use electron-updater package, by its documentation. I write this angular service: import { Injectable } from '@angular/core'; import { autoUpdater } from 'electron-updater';

@Injectable({ providedIn: 'root' })
export class AppUpdateService {
    constructor() { }

    checkForUpdates() {
        const res = autoUpdater.checkForUpdates()
        console.log(res);
    }
}

But when I run checkForUpdates() it's throwing me this exception:

core.js:3866 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'getVersion' of undefined
TypeError: Cannot read property 'getVersion' of undefined
    at ElectronAppAdapter.get version [as version] (ElectronAppAdapter.js:34)
    at new AppUpdater (AppUpdater.js:232)
    at new BaseUpdater (BaseUpdater.js:20)
    at new NsisUpdater (NsisUpdater.js:126)
    at doLoadAutoUpdater (main.js:129)
    at Object.get [as autoUpdater] (main.js:142)
    at AppUpdateService.push../src/app/services/app-update.service.ts.AppUpdateService.checkForUpdates (app-update.service.ts:10)
    at new NetworkingService (networking.service.ts:40)
    at Object.NetworkingService_Factory [as factory] (ɵfac.js? [sm]:1)
    at R3Injector.push../node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js.R3Injector.hydrate (core.js:11425)
    at resolvePromise (zone.js:836)
    at resolvePromise (zone.js:795)
    at zone.js:897
    at ZoneDelegate.invokeTask (zone.js:431)
    at Object.onInvokeTask (core.js:27453)
    at ZoneDelegate.invokeTask (zone.js:430)
    at Zone.runTask (zone.js:198)
    at drainMicroTaskQueue (zone.js:611)

Possible solution:

More thing, I have tried to fix this problem myself, and I found if you change ElectronAppAdapter constructor from: constructor(app = require("electron").app), to this: constructor(app = require("electron").remote.app). everything fixes.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

davayd commented 4 years ago

Same issue

NisStrom commented 4 years ago

+1

kiriri commented 2 months ago

For posterity: 1) electron-updater needs to be called from the main thread. Not the renderer. Put the code in main.ts . Expose it through whatever IPC method you want to use. 2) modules used in the main thread need to be installed in ./app/packages.json not ./packages.json . Yes, that file with no other dependencies inside.