# auto_updater **Repository Path**: leanflutter/auto_updater ## Basic Information - **Project Name**: auto_updater - **Description**: 这个插件允许 Flutter 桌面 应用自动更新自己 (基于 sparkle 和 winsparkle)。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2022-01-11 - **Last Updated**: 2024-10-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # auto_updater [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] [pub-image]: https://img.shields.io/pub/v/auto_updater.svg [pub-url]: https://pub.dev/packages/auto_updater [discord-image]: https://img.shields.io/discord/884679008049037342.svg [discord-url]: https://discord.gg/zPa6EZ2jqb This plugin allows Flutter **desktop** apps to automatically update themselves (based on [sparkle](https://sparkle-project.org/) and [winsparkle](https://winsparkle.org)). --- English | [简体中文](./README-ZH.md) --- - [auto\_updater](#auto_updater) - [Platform Support](#platform-support) - [Quick Start](#quick-start) - [Installation](#installation) - [⚠️ Windows requirements](#️-windows-requirements) - [Usage](#usage) - [Publish your app](#publish-your-app) - [Generate private key](#generate-private-key) - [macOS](#macos) - [Windows](#windows) - [Packaging](#packaging) - [macOS](#macos-1) - [Windows](#windows-1) - [Get signature](#get-signature) - [macOS](#macos-2) - [Windows](#windows-2) - [Distributing](#distributing) - [Troubleshooting](#troubleshooting) - [macOS](#macos-3) - [Who's using it?](#whos-using-it) - [API](#api) - [AutoUpdater](#autoupdater) - [Methods](#methods) - [setFeedURL](#setfeedurl) - [checkForUpdates](#checkforupdates) - [setScheduledCheckInterval](#setscheduledcheckinterval) - [Related Links](#related-links) - [License](#license) ## Platform Support | Linux | macOS | Windows | | :---: | :---: | :-----: | | ➖ | ✔️ | ✔️ | ## Quick Start ### Installation Add this to your package's pubspec.yaml file: ```yaml dependencies: auto_updater: ^0.2.0 ``` Or ```yaml dependencies: auto_updater: git: path: packages/auto_updater url: https://github.com/leanflutter/auto_updater.git ref: main ``` #### ⚠️ Windows requirements - `openssl` Run the following command: > Use [Chocolatey](https://chocolatey.org/install) ``` choco install openssl ``` ### Usage ```dart import 'package:auto_updater/auto_updater.dart'; void main() async { // Must add this line. WidgetsFlutterBinding.ensureInitialized(); String feedURL = 'http://localhost:5002/appcast.xml'; await autoUpdater.setFeedURL(feedURL); await autoUpdater.checkForUpdates(); await autoUpdater.setScheduledCheckInterval(3600); runApp(MyApp()); } ``` > Please see the example app of this plugin for a full example. ### Publish your app #### Generate private key Run the following command: ```bash dart run auto_updater:generate_keys ``` > You need to run this command on `macOS` and `Windows` systems separately. ##### macOS Prepare signing with `EdDSA` signatures: Output: ``` A key has been generated and saved in your keychain. Add the `SUPublicEDKey` key to the Info.plist of each app for which you intend to use Sparkle for distributing updates. It should appear like this: SUPublicEDKey pfIShU4dEXqPd5ObYNfDBiQWcXozk7estwzTnF9BamQ= ``` Change the file `macos/Runner/Info.plist` as follows: ```diff ... + SUPublicEDKey + bHaXClrRGMmKoKP/3HJnr/jn2ODTRPAM3VZhhkI9ZvY= ``` ##### Windows Prepare signing with `DSA` signatures: Output: ``` Generated two files: dsa_priv.pem: your private key. Keep it secret and don't share it! dsa_pub.pem: public counterpart to include in youe app. BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE! If you lose it, your users will be unable to upgrade! ``` > command will generate the private key (`dsa_priv.pem`) and the public key (`dsa_pub.pem`) for you. Please Back up your private key and keep it safe, Add your public key to your project either as Windows resource. Change the file `windows/runner/Runner.rc` as follows: ```diff ... +///////////////////////////////////////////////////////////////////////////// +// +// WinSparkle +// +// And verify signature using DSA public key: +DSAPub DSAPEM "../../dsa_pub.pem" ``` #### Packaging > To simplify the packaging process, [Flutter Distributor](https://github.com/leanflutter/flutter_distributor) is used here, A complete tool dedicated to packaging and publishing Flutter apps. Add `distribute_options.yaml` to your project root directory. ```yaml output: dist/ releases: - name: prod jobs: - name: macos-zip package: platform: macos target: zip build_args: dart-define: APP_ENV: dev # See full documentation: https://distributor.leanflutter.org/configuration/makers/exe - name: windows-exe package: platform: windows target: exe build_args: dart-define: APP_ENV: dev ``` ##### macOS Run the following command: ``` flutter_distributor release --name prod --jobs macos-zip ``` ##### Windows Run the following command: ``` flutter_distributor release --name prod --jobs windows-exe ``` #### Get signature ##### macOS Run the following command: ``` dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-macos.zip ``` Output: ``` sparkle:edSignature="pbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAA==" length="13400992" ``` Update the obtained new signature to the value of the `sparkle:edSignature` attribute of the `enclosure` node of the `appcast.xml` file. ##### Windows Run the following command: ``` dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-windows-setup.exe ``` Output: ``` sparkle:dsaSignature="MEUCIQCVbVzVID7H3aUzAY5znpi+ySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rk=" length="13400992" ``` Update the obtained new signature to the value of the `sparkle:dsaSignature` attribute of the `enclosure` node of the `appcast.xml` file. #### Distributing Add `appcast.xml` to your project `dist/` directory. ```xml auto_updater_example Most recent updates to auto_updater_example en Version 1.1.0 2 1.1.0 https://your_domain/your_path/release_notes.html Sun, 16 Feb 2022 12:00:00 +0800 Version 1.1.0 https://your_domain/your_path/release_notes.html Sun, 16 Feb 2022 12:00:00 +0800 ``` > This example uses the same `appcast.xml` file for `macOS` and `Windows`, and you need to configure the value of the `sparkle:os` property accordingly. Start the test update server: ``` cd dist/ serve -l 5002 ``` ## Troubleshooting ### macOS - Make sure you have the sparkle pod added as described in [Sparkle Documentation](https://sparkle-project.org/documentation/) - Make sure you have added and enabled network capabilties of your app and disabled the sandbox for release by adding the following to your entitlement files for debug and release ``` com.apple.security.network.client com.apple.security.network.server com.apple.security.app-sandbox ``` ## Who's using it? - [Biyi](https://biyidev.com/) - A convenient translation and dictionary app. ## API ### AutoUpdater #### Methods ##### setFeedURL Sets the url and initialize the auto updater. ##### checkForUpdates Asks the server whether there is an update. You must call setFeedURL before using this API. ##### setScheduledCheckInterval Sets the auto update check interval, default 86400, minimum 3600, 0 to disable update ## Related Links - https://sparkle-project.org/ - https://winsparkle.org/ ## License [MIT](./LICENSE)