Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature auto update windows #59

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class AppConfig {
static String get webBaseUrl => _webBaseUrl;
static const String sourceCodeUrl = 'https://github.com/Tawkie/tawkie-app';
static const String supportUrl = 'https://www.tawkie.fr/faq/';
static const String githubReleasesUrl = 'https://api.github.com/repos/Tawkie/tawkie-app/releases/latest';
static final Uri newIssueUrl = Uri(
scheme: 'https',
host: 'github.com',
Expand Down
40 changes: 40 additions & 0 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import 'package:tawkie/config/setting_keys.dart';
import 'package:tawkie/pages/add_bridge/model/social_network.dart';
import 'package:tawkie/pages/bootstrap/bootstrap_dialog.dart';
import 'package:tawkie/pages/chat/send_file_dialog.dart';
import 'package:tawkie/services/update_service.dart';
import 'package:tawkie/utils/account_bundles.dart';
import 'package:tawkie/utils/app_info.dart';
import 'package:tawkie/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:tawkie/utils/show_update_snackbar.dart';
import 'package:tawkie/utils/url_launcher.dart';
Expand All @@ -36,6 +38,7 @@ import 'package:tawkie/utils/platform_infos.dart';

import 'package:tawkie/utils/tor_stub.dart'
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';
import 'package:updat/updat.dart';

enum SelectMode {
normal,
Expand Down Expand Up @@ -623,6 +626,43 @@ class ChatListController extends State<ChatList>
void initState() {
super.initState();

// Call UpdatWidget in initState to run when page is opened
if (PlatformInfos.isWindows) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
final String currentVersion = await getAppVersion();
final latestVersion = await getLatestVersionFromGitHub();
final binaryUrl = await getWindowsExeDownloadUrl();

// If the version or URL of the exe file is unavailable, do not display anything.
if (latestVersion == null || binaryUrl == null) {
if (kDebugMode) {
print("Update information unavailable. No update displayed.");
}
return;
}

// If all goes well, the update widget is displayed
showDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return AlertDialog(
content:
UpdatWidget(
currentVersion: currentVersion,
getLatestVersion: () => Future.value(latestVersion),
getBinaryUrl: (latestVersion) async {
return binaryUrl;
},
appName: AppConfig.applicationName,
openOnDownload: true,
),
);
},
);
});
}

_initReceiveSharingIntent();
scrollController.addListener(_onScroll);
_waitForFirstSync();
Expand Down
58 changes: 58 additions & 0 deletions lib/services/update_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

Future<String?> getLatestVersionFromGitHub() async {
final String url = "https://api.github.com/repos/Tawkie/tawkie-app/releases/latest";
final response = await http.get(Uri.parse(url));

if (response.statusCode == 200) {
final data = jsonDecode(response.body);
String latestVersion = data['tag_name']; // Retrieves the tag for the latest version

// Remove the first character 'v'
if (latestVersion.startsWith('v')) {
latestVersion = latestVersion.substring(1);
}
return latestVersion;
} else {
if (kDebugMode) {
print('Error retrieving version information: ${response.statusCode}');
}
return null;
}
}

Future<String?> getWindowsExeDownloadUrl() async {
try {
final String url = "https://api.github.com/repos/Tawkie/tawkie-app/releases/latest";
final response = await http.get(Uri.parse(url));

if (response.statusCode == 200) {
final data = jsonDecode(response.body);
final List<dynamic> assets = data['assets'];

// Browse asset list to find URL of Windows file (.exe)
for (var asset in assets) {
if (asset['name'].endsWith('.exe')) {
print("URL du fichier .exe : ${asset['browser_download_url']}");
return asset['browser_download_url'];
}
}
if (kDebugMode) {
print('No .exe files found in release assets.');
}
return null;
} else {
if (kDebugMode) {
print('Error retrieving release information: ${response.statusCode}');
}
return null;
}
} catch (e) {
if (kDebugMode) {
print("Error retrieving URL:$e");
}
return null;
}
}
6 changes: 6 additions & 0 deletions lib/utils/app_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:package_info_plus/package_info_plus.dart';

Future<String> getAppVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version;
}
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.2.1"
flutter_markdown:
dependency: transitive
description:
name: flutter_markdown
sha256: "04c4722cc36ec5af38acc38ece70d22d3c2123c61305d555750a091517bbe504"
url: "https://pub.dev"
source: hosted
version: "0.6.23"
flutter_math_fork:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1872,6 +1880,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.2"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90"
url: "https://pub.dev"
source: hosted
version: "0.1.9"
scroll_to_index:
dependency: "direct main"
description:
Expand Down Expand Up @@ -2301,6 +2317,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.2.0"
updat:
dependency: "direct main"
description:
name: updat
sha256: c0715dc22502355c9915a8eb318255b3587f71a29d3e9c34113c6aded3907bd9
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: "direct main"
description:
Expand Down Expand Up @@ -2557,6 +2581,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.3"
window_manager:
dependency: transitive
description:
name: window_manager
sha256: "8699323b30da4cdbe2aa2e7c9de567a6abd8a97d9a5c850a3c86dcd0b34bbfbf"
url: "https://pub.dev"
source: hosted
version: "0.3.9"
window_to_front:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependencies:
built_collection: ^5.1.1
built_value: ^8.9.2
back_button_interceptor: ^7.0.3
updat: ^1.3.2

dev_dependencies:
flutter_lints: ^3.0.0
Expand Down
Loading