2016-11-18 51 views
0

我试图在电子应用程序中实现Windows自动更新功能(这可能会导致我过早死亡),并且出现此错误。autoUpdater.setFeedURL不是函数

enter image description here

这是我通过为测试目的URL

编辑:我的电子应用程序是使用两个的package.json结构,这个代码是在我的应用程序> main.js文件

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

编辑2:感谢@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(); 
}) 

回答

1

您是否正确包含autoUpdater模块?

const {autoUpdater} = require('electron') 

如果是这样,尝试在应用程序“就绪”事件后执行代码。

app.on('ready',() => { 
    const feedURL = 'C:\\Users\\p00009970\\Desktop\\update_test'; 
    autoUpdater.setFeedURL(feedURL); 
    autoUpdater.checkForUpdates(); 
}) 
+0

包括应用“准备好”一切摆脱了错误,但现在如果它执行更新与否我也说不上来,我推了更新,但什么也没有发生 – Skedge

+0

更新:应用程序准备绝对固定的我问题,我剩下的问题是与公司代理废话。我将用最终代码更新我的问题。 – Skedge

+0

很高兴我能帮忙! – JuanMa