electron - autoUpdater.setFeedURL 不是函数

标签 electron auto-update squirrel.windows

我正在尝试在 Electron 应用程序中实现 Windows 自动更新功能(这可能导致我早逝)并且我收到了这个错误。

enter image description here

这是我为测试目的而传递的 URL

编辑:我的 Electron 应用程序使用两个 package.json 结构,此代码在我的 app>main.js 文件中

const feedURL = 'C:\\Users\\p00009970\\Desktop\\update_test';
autoUpdater.setFeedURL(feedURL); 
autoUpdater.checkForUpdates(); 

EDIT2:感谢@JuanMa,我能够让它工作。这是代码。
// auto update functionality

const {autoUpdater} = require('electron')

// local file system example: const feedURL = 'C:\\Users\\john\\Desktop\\updates_folder';
// network file system example: const feedURL = '\\\\serverName\\updates_folder';

const feedURL = '\\\\serverName\\updates_folder';

app.on('ready', () => {
    autoUpdater.setFeedURL(feedURL);

    // auto update event listeners, these are fired as a result of  autoUpdater.checkForUpdates();

    autoUpdater.addListener("update-available", function(event) {

    });
    autoUpdater.addListener("update-downloaded", function(event,   releaseNotes, releaseName, releaseDate, updateURL) {

      //TODO: finess this a tad, as is after a few seconds of launching the app it will close without warning
      // and reopen with the update which could confuse the user and possibly cause loss of work

        autoUpdater.quitAndInstall();
    });
    autoUpdater.addListener("error", function(error) {

    });
    autoUpdater.addListener("checking-for-update", function(event) {

    });
    autoUpdater.addListener("update-not-available", function(event) {

    });

    // tell squirrel to check for updates
    autoUpdater.checkForUpdates();
})

最佳答案

您是否正确包含了 autoUpdater 模块?

const {autoUpdater} = require('electron')

如果是这样,请尝试在应用程序“就绪”事件之后执行代码。
app.on('ready', () => {
  const feedURL = 'C:\\Users\\p00009970\\Desktop\\update_test';
  autoUpdater.setFeedURL(feedURL); 
  autoUpdater.checkForUpdates(); 
})

关于electron - autoUpdater.setFeedURL 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40681227/

相关文章:

javascript - 单击 Electron web View 中的元素

postgresql - postgresql 服务器启动时,postgresql 中是否有任何系统表自动更新?

Delphi自动更新服务器到客户端

c# - WPF 应用程序的部署和更新程序

electron - 每次使用Squirrel.Windows更新应用程序时,如何避免添加新的Windows防火墙豁免?

macos - 如何在 Mac 上退出 Electron 应用程序?

javascript - DOM 准备好后立即开始抓取 Nightmarejs

screenshot - node-webkit 或 atom-shell 可以截取整个桌面屏幕吗?

sql-server - 当以另一种形式保存数据时,Vb.Net 以主形式更新 Datagridview

c# - Squirrel.windows 在桌面上创建多个快捷方式