autoUpdater

    进程:主进程

    请参阅:在应用程序中如何实现更新的详细指南。

    autoUpdater是一个.

    Currently, only macOS and Windows are supported. There is no built-in support for auto-updater on Linux, so it is recommended to use the distribution’s package manager to update your app.

    此外,每个平台都有一些细微的差别:

    在macOS上, autoUpdater模块建立在 Squirrel.Mac上,这意味着你不需要任何特殊的设置来使它工作。 对于服务器端要求, 你可以阅读 . 注意App Transport Security (ATS) 适用于所有请求作为更新过程的一部分。 如需禁用ATS的应用程序可以在其应用程序的plist中添加 NSAllowsArbitraryLoads属性。

    Note: Your application must be signed for automatic updates on macOS. This is a requirement of Squirrel.Mac.

    Windows

    在 Windows 上, 你必须使用安装程序将你的应用装到用户的计算机上才能使用autoUpdater, 所以比较推荐的方法是用 electron-winstaller, 或 grunt-electron-installer 模块来生成Windows安装程序。

    当使用 或 electron-forge 时,确保不要在时更新你的应用程序 (详情参阅 这个问题的更多信息). 还建议使用 来创建应用程序的桌面快捷方式。

    与 Squirrel.Mac 不同,Windows 版可以将更新文件放在 S3 或者其他静态主机上。 你可以阅读 Squirrel.Windows的文档来获得更多详细信息。

    对象会触发以下的事件:

    Event: ‘error’

    返回:

    当更新发生错误的时候触发。

    Event: ‘checking-for-update’

    当开始检查更新的时候触发。

    Emitted when there is an available update. The update is downloaded automatically.

    Event: ‘update-not-available’

    当没有可用更新的时候触发。

    Event: ‘update-downloaded’

    返回:

    • event Event
    • releaseNotes String
    • releaseName String
    • releaseDate Date
    • updateURL String

    在更新下载完成的时候触发。

    Note: It is not strictly necessary to handle this event. A successfully downloaded update will still be applied the next time the application starts.

    Event: ‘before-quit-for-update’

    此事件是在用户调用quitAndInstall()之后发出的。

    当此API被调用时,会在所有窗口关闭之前发出 before-quit 事件。 因此,如果您希望在关闭窗口进程退出之前执行操作,则应该侦听此事件,以及侦听 before-quit

    autoUpdater 对象具有以下方法:

    • Object
      • url String
      • serverType String (可选) macOS - json 或者 default, 有关更多信息,请参考 Squirrel.Mac 的自述文件(README)。

    设置检查更新的 url,并且初始化自动更新。

    autoUpdater.getFeedURL()

    返回 String - 获取当前更新的 Feed 链接.

    autoUpdater.checkForUpdates()

    Asks the server whether there is an update. You must call setFeedURL before using this API.

    autoUpdater.quitAndInstall()

    Restarts the app and installs the update after it has been downloaded. It should only be called after update-downloaded has been emitted.

    在此机制下,调用 将首先关闭所有应用程序窗口,并且在所有窗口都关闭之后自动调用 app.quit()