Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: integrate version checker for Linux (#7346)
Lucas8f646a2843fb
diff --git a/frontend/appflowy_flutter/lib/shared/version_checker/version_checker.dart b/frontend/appflowy_flutter/lib/shared/version_checker/version_checker.dartnew file mode 100644index 0000000000..b9fecb2b94--- /dev/null+++ b/frontend/appflowy_flutter/lib/shared/version_checker/version_checker.dart@@ -0,0 +1,89 @@+import 'package:appflowy/core/helpers/url_launcher.dart';+import 'package:appflowy/startup/tasks/device_info_task.dart';+import 'package:auto_updater/auto_updater.dart';+import 'package:collection/collection.dart';+import 'package:http/http.dart' as http;+import 'package:universal_platform/universal_platform.dart';+import 'package:xml/xml.dart' as xml;++final versionChecker = VersionChecker();++/// Version checker class to handle update checks using appcast XML feeds+class VersionChecker {+ factory VersionChecker() => _instance;++ VersionChecker._internal();+ String? _feedUrl;++ static final VersionChecker _instance = VersionChecker._internal();++ /// Sets the appcast XML feed URL+ void setFeedUrl(String url) {+ _feedUrl = url;++ if (UniversalPlatform.isWindows || UniversalPlatform.isMacOS) {+ autoUpdater.setFeedURL(url);+ }+ }++ /// Checks for updates by fetching and parsing the appcast XML+ /// Returns a list of [AppcastItem] or throws an exception if the feed URL is not set+ Future<AppcastItem?> checkForUpdateInformation() async {+ if (_feedUrl == null) {+ throw Exception('Feed URL not set. Call setFeedUrl() first.');+ }++ try {+ final response = await http.get(Uri.parse(_feedUrl!));+ if (response.statusCode != 200) {+ throw Exception('Failed to fetch appcast feed');+ }++ // Parse XML content+ final document = xml.XmlDocument.parse(response.body);+ final items = document.findAllElements('item');++ // Convert XML items to AppcastItem objects+ return items+ .map(_parseAppcastItem)+ .nonNulls+ .firstWhereOrNull((e) => e.os == ApplicationInfo.os);+ } catch (e) {+ throw Exception('Error checking for updates: $e');+ }+ }++ /// For Windows and macOS, calling this API will trigger the auto updater to check for updates+ /// For Linux, it will open the official website in the browser if there is a new version++ Future<void> checkForUpdate() async {+ if (UniversalPlatform.isLinux) {+ // open the official website in the browser+ await afLaunchUrlString('https://appflowy.com/download');+ } else {+ await autoUpdater.checkForUpdates();+ }+ }++ AppcastItem? _parseAppcastItem(xml.XmlElement item) {+ final enclosure = item.findElements('enclosure').firstOrNull;+ return AppcastItem.fromJson({+ 'title': item.findElements('title').firstOrNull?.innerText,+ 'versionString': item+ .findElements('sparkle:shortVersionString')+ .firstOrNull+ ?.innerText,+ 'displayVersionString': item+ .findElements('sparkle:shortVersionString')+ .firstOrNull+ ?.innerText,+ 'releaseNotesUrl':+ item.findElements('releaseNotesLink').firstOrNull?.innerText,+ 'pubDate': item.findElements('pubDate').firstOrNull?.innerText,+ 'fileURL': enclosure?.getAttribute('url') ?? '',+ 'os': enclosure?.getAttribute('sparkle:os') ?? '',+ 'criticalUpdate':+ enclosure?.getAttribute('sparkle:criticalUpdate') ?? false,+ });+ }+}diff --git a/frontend/appflowy_flutter/lib/startup/tasks/auto_update_task.dart b/frontend/appflowy_flutter/lib/startup/tasks/auto_update_task.dartindex 3371abf224..5846b31bef 100644--- a/frontend/appflowy_flutter/lib/startup/tasks/auto_update_task.dart+++ b/frontend/appflowy_flutter/lib/startup/tasks/auto_update_task.dart@@ -1,4 +1,5 @@import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/shared/version_checker/version_checker.dart';import 'package:appflowy/startup/tasks/app_widget.dart';import 'package:appflowy/startup/tasks/device_info_task.dart';import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';@@ -14,37 +15,22 @@ import '../startup.dart';class AutoUpdateTask extends LaunchTask {AutoUpdateTask();- // static const _feedUrl =- // 'https://github.com/LucasXu0/AppFlowy/releases/latest/download/appcast-{os}-{arch}.xml';+ static const _feedUrl =+ 'https://github.com/LucasXu0/AppFlowy/releases/latest/download/appcast-{os}-{arch}.xml';final _listener = _AppFlowyAutoUpdaterListener();@overrideFuture<void> initialize(LaunchContext context) async {- // Enable auto update when the integration of Windows and Linux is completed.- return;- // // the auto updater is not supported on mobile and linux- // if (UniversalPlatform.isMobile || UniversalPlatform.isLinux) {- // return;- // }-- // Log.info(- // '[AutoUpdate] current version: ${ApplicationInfo.applicationVersion}, current cpu architecture: ${ApplicationInfo.architecture}',- // );-- // autoUpdater.addListener(_listener);-- // // Since the appcast.xml is not supported the arch, we separate the feed url by os and arch.- // final feedUrl = _feedUrl- // .replaceAll('{os}', ApplicationInfo.os)- // .replaceAll('{arch}', ApplicationInfo.architecture);- // Log.info('[AutoUpdate] feed url: $feedUrl');-- // await autoUpdater.setFeedURL(feedUrl);- // await autoUpdater.checkForUpdateInformation();-- // ApplicationInfo.isCriticalUpdateNotifier.addListener(- // _showCriticalUpdateDialog,- // );+ // the auto updater is not supported on mobile+ if (UniversalPlatform.isMobile) {+ return;+ }++ await _setupAutoUpdater();++ ApplicationInfo.isCriticalUpdateNotifier.addListener(+ _showCriticalUpdateDialog,+ );}@override@@ -56,6 +42,34 @@ class AutoUpdateTask extends LaunchTask {);}+ // On macOS and windows, we use auto_updater to check for updates.+ // On linux, we use the version checker to check for updates because the auto_updater is not supported.+ Future<void> _setupAutoUpdater() async {+ Log.info(+ '[AutoUpdate] current version: ${ApplicationInfo.applicationVersion}, current cpu architecture: ${ApplicationInfo.architecture}',+ );++ // Since the appcast.xml is not supported the arch, we separate the feed url by os and arch.+ final feedUrl = _feedUrl+ .replaceAll('{os}', ApplicationInfo.os)+ .replaceAll('{arch}', ApplicationInfo.architecture);++ // the auto updater is only supported on macOS and windows, so we don't need to check the platform+ if (UniversalPlatform.isMacOS || UniversalPlatform.isWindows) {+ autoUpdater.addListener(_listener);+ }++ Log.info('[AutoUpdate] feed url: $feedUrl');++ versionChecker.setFeedUrl(feedUrl);+ final item = await versionChecker.checkForUpdateInformation();+ if (item != null) {+ ApplicationInfo.latestAppcastItem = item;+ ApplicationInfo.latestVersionNotifier.value =+ item.displayVersionString ?? '';+ }+ }+void _showCriticalUpdateDialog() {showCustomConfirmDialog(context: AppGlobals.rootNavKey.currentContext!,@@ -74,7 +88,7 @@ class AutoUpdateTask extends LaunchTask {closeOnConfirm: false,confirmLabel: LocaleKeys.autoUpdate_criticalUpdateButton.tr(),onConfirm: () async {- await autoUpdater.checkForUpdates();+ await versionChecker.checkForUpdate();},);}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dartindex d98c24287e..ea55c72f16 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart@@ -7,6 +7,7 @@ import 'package:appflowy/plugins/blank/blank.dart';import 'package:appflowy/plugins/document/presentation/editor_notification.dart';import 'package:appflowy/shared/feature_flags.dart';import 'package:appflowy/shared/loading.dart';+import 'package:appflowy/shared/version_checker/version_checker.dart';import 'package:appflowy/startup/startup.dart';import 'package:appflowy/startup/tasks/device_info_task.dart';import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';@@ -36,7 +37,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'show UserProfilePB;import 'package:appflowy_editor/appflowy_editor.dart';-import 'package:auto_updater/auto_updater.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flutter/material.dart';@@ -462,7 +462,7 @@ class _SidebarState extends State<_Sidebar> {),child: SidebarUpgradeApplicationButton(onUpdateButtonTap: () {- autoUpdater.checkForUpdates();+ versionChecker.checkForUpdate();},onCloseButtonTap: () {_muteUpdateButton.value = true;diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/about/app_version.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/about/app_version.dartindex 85e3c897f6..71dfdde7a9 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/about/app_version.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/about/app_version.dart@@ -1,8 +1,8 @@import 'package:appflowy/core/helpers/url_launcher.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/shared/version_checker/version_checker.dart';import 'package:appflowy/startup/tasks/device_info_task.dart';import 'package:appflowy_backend/log.dart';-import 'package:auto_updater/auto_updater.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flutter/material.dart';@@ -23,15 +23,19 @@ class SettingsAppVersion extends StatelessWidget {return Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- const FlowyText.regular(- 'AppFlowy is up to date!',+ FlowyText.regular(+ LocaleKeys.settings_accountPage_isUpToDate.tr(),figmaLineHeight: 17,),const VSpace(4),Opacity(opacity: 0.7,child: FlowyText.regular(- 'Version ${ApplicationInfo.applicationVersion} (Official build)',+ LocaleKeys.settings_accountPage_officialVersion.tr(+ namedArgs: {+ 'version': ApplicationInfo.applicationVersion,+ },+ ),fontSize: 12,figmaLineHeight: 13,),@@ -62,7 +66,7 @@ class _UpdateAppSection extends StatelessWidget {radius: 8.0,onTap: () {Log.info('[AutoUpdater] Checking for updates');- autoUpdater.checkForUpdates();+ versionChecker.checkForUpdate();},);}diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lockindex 13771d85db..3c5ca468af 100644--- a/frontend/appflowy_flutter/pubspec.lock+++ b/frontend/appflowy_flutter/pubspec.lock@@ -2540,7 +2540,7 @@ packages:source: hostedversion: "1.1.0"xml:- dependency: transitive+ dependency: "direct main"description:name: xmlsha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yamlindex 21d0b942c7..5643e3b09b 100644--- a/frontend/appflowy_flutter/pubspec.yaml+++ b/frontend/appflowy_flutter/pubspec.yaml@@ -144,6 +144,7 @@ dependencies:# Window Manager for MacOS and Linuxversion: ^3.0.2+ xml: ^6.5.0window_manager: ^0.4.3dev_dependencies:diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex 9b4d235d47..98c0167327 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -571,7 +571,9 @@"title": "Account login","loginLabel": "Log in","logoutLabel": "Log out"- }+ },+ "isUpToDate": "@:appName is up to date!",+ "officialVersion": "Version {version} (Official build)"},"workspacePage": {"menuLabel": "Workspace",