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] Check GitHub for updates #712

Open
wants to merge 16 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
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public static void registerWith(@NonNull FlutterEngine flutterEngine) {
Log.e(TAG, "Error registering plugin local_image_provider, com.csdcorp.local_image_provider.LocalImageProviderPlugin", e);
}
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.packageinfo.PackageInfoPlugin());
flutterEngine.getPlugins().add(new dev.fluttercommunity.plus.packageinfo.PackageInfoPlugin());
} catch(Exception e) {
Log.e(TAG, "Error registering plugin package_info, io.flutter.plugins.packageinfo.PackageInfoPlugin", e);
Log.e(TAG, "Error registering plugin package_info_plus, dev.fluttercommunity.plus.packageinfo.PackageInfoPlugin", e);
}
try {
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
Expand Down
6 changes: 5 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"title-dialog-sync-interval": "Modify Sync Interval",
"title-dialog-chat-with-user": "Chat with {}",
"title-dialog-attempt-chat-with-user": "Try chatting with {}",
"title-dialog-remote-update": "New Syphon Update",
"title-user-verification": "User verification",
"title-confirm-password": "Confirm Password",
"title-confirm-email": "Confirm Email",
Expand Down Expand Up @@ -239,6 +240,8 @@
"list-item-advanced-settings-licenses": "Open Source Licenses",
"list-item-advanced-settings-start-background": "Start Background Service",
"list-item-advanced-settings-stop-background": "Stop All Services",
"list-item-advanced-settings-check-for-updates": "Check GitHub for Syphon updates",
"list-item-advanced-settings-check-for-updates-body": "Periodically check GitHub for new releases",
"list-item-advanced-settings-test-notifications": "Test Notifications",
"list-item-advanced-settings-test-sync-loop": "Test Background Sync Loop",
"list-item-advanced-settings-force-function": "Force Function",
Expand Down Expand Up @@ -273,6 +276,7 @@
"content-intro-section-three": "Both Matrix and {} are developed\nopenly by organizations and people,\nnot corporations",
"content-intro-section-four": "By using {} and other Matrix clients,\nwe can make private messaging \naccessible to everyone",
"content-captcha-warning": "Some Matrix servers require captcha confirmation provided by Google through reCAPTCHA. \n\nIf you'd prefer not to complete this captcha, you may need to go back to server select and choose a different server for account creation.",
"content-dialog-remote-update": "A new Syphon version was released under the version number {}. Do you want to download this update?",
"content-dialog-devices-delete": "You will have to sign in again on these devices if you remove them.",
"content-dialog-devices-key-export": "Are you sure you want to export this device's encryption key? It may make it available to others if you're not careful!",
"content-dialog-device-rename": "Enter the new public display name for this device.",
Expand Down Expand Up @@ -368,4 +372,4 @@
"tooltip-copy-message-content": "Copy Message Content",
"tooltip-quote-and-reply": "Quote and Reply",
"tooltip-share-chats": "Share Chats"
}
}
10 changes: 5 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ PODS:
- OLMKit/olmcpp (= 3.2.12)
- OLMKit/olmc (3.2.12)
- OLMKit/olmcpp (3.2.12)
- package_info (0.0.1):
- package_info_plus (0.4.5):
- Flutter
- path_provider_ios (0.0.1):
- Flutter
Expand Down Expand Up @@ -130,7 +130,7 @@ DEPENDENCIES:
- image_picker (from `.symlinks/plugins/image_picker/ios`)
- local_image_provider (from `.symlinks/plugins/local_image_provider/ios`)
- OLMKit
- package_info (from `.symlinks/plugins/package_info/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
Expand Down Expand Up @@ -181,8 +181,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/image_picker/ios"
local_image_provider:
:path: ".symlinks/plugins/local_image_provider/ios"
package_info:
:path: ".symlinks/plugins/package_info/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
permission_handler:
Expand Down Expand Up @@ -223,7 +223,7 @@ SPEC CHECKSUMS:
local_image_provider: 05b1af32561482c0ca5a440fbc7f489ad818c962
Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
Expand Down
80 changes: 80 additions & 0 deletions lib/global/libs/updater/update-check.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
import 'package:syphon/global/https.dart';

const String CHECK_TIMESTAMP_KEY = 'CHECKED_TIMESTAMP_KEY';
const String MARKED_VERSION_KEY = 'DISMISS_VERSION_KEY';

class UpdateChecker {
static var latestVersion;
static final latestBuildUri = Uri.https('github.com', 'syphon-org/syphon/releases/latest');

static markUpdated(int version) async {
final secureStorage = FlutterSecureStorage();
secureStorage.write(
key: MARKED_VERSION_KEY,
value: version.toString(),
);
}

static markDismissed(int version) async {
final secureStorage = FlutterSecureStorage();
secureStorage.write(
key: MARKED_VERSION_KEY,
value: version.toString(),
);
}

static markChecked() async {
final secureStorage = FlutterSecureStorage();
secureStorage.write(
key: CHECK_TIMESTAMP_KEY,
value: DateTime.now().add(Duration(hours: 24)).millisecondsSinceEpoch.toString(),
);
}

static checkHasUpdate() async {
final secureStorage = FlutterSecureStorage();

// Latest version acknowledge by the user
final markedVersionString = await secureStorage.read(key: MARKED_VERSION_KEY);
final markedVersion = int.parse(markedVersionString ?? '0');

// Last timestamp when we checked for an update
final checkTimestamp = await secureStorage.read(key: CHECK_TIMESTAMP_KEY);
final checkDateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(checkTimestamp ?? '0'));

// Ignore if recently checked for an update and not enough time has passed
if (checkDateTime.isAfter(DateTime.now())) {
return;
}

final packageInfo = await PackageInfo.fromPlatform();
final currentVersion = int.parse(packageInfo.version.replaceAll('.', ''));

// Extract the build tag from the redirect
final request = http.Request('Get', latestBuildUri)..followRedirects = false;
final response = await httpClient.send(request);

if (!response.headers.containsKey('location')) {
return;
}

// Extract the tag
final redirectUri = Uri.parse(response.headers['location']!);
final remoteVersion = int.parse(redirectUri.pathSegments.last.replaceAll('.', ''));

// Mark that we've checked for the latest version
await markChecked();

// Ignore if user has already dismissed this update
if (remoteVersion <= markedVersion) {
return false;
}

latestVersion = remoteVersion;

return remoteVersion > currentVersion;
}
}
Loading