Add appcast
This commit is contained in:
@@ -5,9 +5,11 @@ import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/core/router/router.dart';
|
||||
import 'package:hiddify/domain/constants.dart';
|
||||
import 'package:hiddify/features/common/app_update_notifier.dart';
|
||||
import 'package:hiddify/features/common/common_controllers.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:upgrader/upgrader.dart';
|
||||
|
||||
class AppView extends HookConsumerWidget with PresLogger {
|
||||
const AppView({super.key});
|
||||
@@ -20,6 +22,8 @@ class AppView extends HookConsumerWidget with PresLogger {
|
||||
|
||||
ref.watch(commonControllersProvider);
|
||||
|
||||
final upgrader = ref.watch(upgraderProvider);
|
||||
|
||||
return MaterialApp.router(
|
||||
// builder: (context, child) {
|
||||
// return AccessibilityTools(
|
||||
@@ -37,13 +41,16 @@ class AppView extends HookConsumerWidget with PresLogger {
|
||||
theme: theme.light(),
|
||||
darkTheme: theme.dark(),
|
||||
title: Constants.appName,
|
||||
|
||||
// https://github.com/ponnamkarthik/FlutterToast/issues/393
|
||||
builder: (context, child) => Overlay(
|
||||
initialEntries: [
|
||||
if (child != null) ...[
|
||||
OverlayEntry(
|
||||
builder: (context) => child,
|
||||
builder: (context) => UpgradeAlert(
|
||||
upgrader: upgrader,
|
||||
navigatorKey: router.routerDelegate.navigatorKey,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -9,6 +9,8 @@ abstract class Constants {
|
||||
"https://api.github.com/repos/hiddify/hiddify-next/releases";
|
||||
static const githubLatestReleaseUrl =
|
||||
"https://github.com/hiddify/hiddify-next/releases/latest";
|
||||
static const appCastUrl =
|
||||
"https://github.com/hiddify/hiddify-next/appcast.xml";
|
||||
static const telegramChannelUrl = "https://t.me/hiddify";
|
||||
static const privacyPolicyUrl = "https://hiddify.com/en/privacy-policy/";
|
||||
static const termsAndConditionsUrl = "https://hiddify.com/terms/";
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/prefs.dart';
|
||||
import 'package:hiddify/core/router/router.dart';
|
||||
import 'package:hiddify/data/data_providers.dart';
|
||||
import 'package:hiddify/domain/app/app.dart';
|
||||
import 'package:hiddify/features/common/new_version_dialog.dart';
|
||||
import 'package:hiddify/services/service_providers.dart';
|
||||
import 'package:hiddify/domain/constants.dart';
|
||||
import 'package:hiddify/utils/pref_notifier.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:upgrader/upgrader.dart';
|
||||
|
||||
part 'app_update_notifier.freezed.dart';
|
||||
part 'app_update_notifier.g.dart';
|
||||
|
||||
const _debugUpgrader = true;
|
||||
|
||||
@riverpod
|
||||
Upgrader upgrader(UpgraderRef ref) => Upgrader(
|
||||
appcastConfig: AppcastConfiguration(url: Constants.appCastUrl),
|
||||
debugLogging: _debugUpgrader && kDebugMode,
|
||||
durationUntilAlertAgain: const Duration(hours: 12),
|
||||
messages: UpgraderMessages(
|
||||
code: ref.watch(localeNotifierProvider).languageCode,
|
||||
),
|
||||
);
|
||||
|
||||
@freezed
|
||||
class AppUpdateState with _$AppUpdateState {
|
||||
const factory AppUpdateState.initial() = AppUpdateStateInitial;
|
||||
@@ -30,7 +42,7 @@ class AppUpdateState with _$AppUpdateState {
|
||||
class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger {
|
||||
@override
|
||||
AppUpdateState build() {
|
||||
_schedule();
|
||||
// _schedule();
|
||||
return const AppUpdateState.initial();
|
||||
}
|
||||
|
||||
@@ -85,25 +97,25 @@ class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger {
|
||||
state = AppUpdateStateIgnored(versionInfo);
|
||||
}
|
||||
|
||||
Future<void> _schedule() async {
|
||||
loggy.debug("scheduling app update checker");
|
||||
return ref.read(cronServiceProvider).schedule(
|
||||
key: 'app_update',
|
||||
duration: const Duration(hours: 8),
|
||||
callback: () async {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
final updateState = await check();
|
||||
final context = rootNavigatorKey.currentContext;
|
||||
if (context != null && context.mounted) {
|
||||
if (updateState
|
||||
case AppUpdateStateAvailable(:final versionInfo)) {
|
||||
await NewVersionDialog(
|
||||
ref.read(appInfoProvider).presentVersion,
|
||||
versionInfo,
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
// Future<void> _schedule() async {
|
||||
// loggy.debug("scheduling app update checker");
|
||||
// return ref.read(cronServiceProvider).schedule(
|
||||
// key: 'app_update',
|
||||
// duration: const Duration(hours: 8),
|
||||
// callback: () async {
|
||||
// await Future.delayed(const Duration(seconds: 5));
|
||||
// final updateState = await check();
|
||||
// final context = rootNavigatorKey.currentContext;
|
||||
// if (context != null && context.mounted) {
|
||||
// if (updateState
|
||||
// case AppUpdateStateAvailable(:final versionInfo)) {
|
||||
// await NewVersionDialog(
|
||||
// ref.read(appInfoProvider).presentVersion,
|
||||
// versionInfo,
|
||||
// ).show(context);
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ void commonControllers(CommonControllersRef ref) {
|
||||
(previous, next) {},
|
||||
fireImmediately: true,
|
||||
);
|
||||
ref.listen(
|
||||
appUpdateNotifierProvider,
|
||||
(previous, next) {},
|
||||
fireImmediately: true,
|
||||
);
|
||||
// ref.listen(
|
||||
// appUpdateNotifierProvider,
|
||||
// (previous, next) {},
|
||||
// fireImmediately: true,
|
||||
// );
|
||||
ref.listen(
|
||||
profilesUpdateNotifierProvider,
|
||||
(previous, next) {},
|
||||
|
||||
Reference in New Issue
Block a user