Add basic flavors

This commit is contained in:
problematicconsumer
2023-09-12 15:22:58 +03:30
parent ea81be3763
commit f1b0f8ee4b
24 changed files with 271 additions and 293 deletions

View File

@@ -0,0 +1,33 @@
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/app/app.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'app_update_notifier.g.dart';
@Riverpod(keepAlive: true)
class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger {
@override
Future<RemoteVersionInfo?> build() async {
loggy.debug("checking for update");
final currentVersion = ref.watch(appInfoProvider).version;
return ref
.watch(appRepositoryProvider)
.getLatestVersion(includePreReleases: true)
.match(
(l) {
loggy.warning("failed to get latest version, $l");
throw l;
},
(remote) {
if (remote.version.compareTo(currentVersion) > 0) {
loggy.info("new version available: $remote");
return remote;
}
loggy.info("already using latest version[$currentVersion], remote: $remote");
return null;
},
).run();
}
}

View File

@@ -1,5 +1,5 @@
export 'app_update_notifier.dart';
export 'confirmation_dialogs.dart';
export 'custom_app_bar.dart';
export 'profile_tile.dart';
export 'qr_code_scanner_screen.dart';
export 'runtime_details.dart';

View File

@@ -16,7 +16,7 @@ class NewVersionDialog extends HookConsumerWidget {
this.canIgnore = true,
});
final InstalledVersionInfo currentVersion;
final String currentVersion;
final RemoteVersionInfo newVersion;
final bool canIgnore;
@@ -48,7 +48,7 @@ class NewVersionDialog extends HookConsumerWidget {
style: theme.textTheme.bodySmall,
),
TextSpan(
text: currentVersion.fullVersion,
text: currentVersion,
style: theme.textTheme.labelMedium,
),
],

View File

@@ -1,79 +0,0 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/app/app.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'runtime_details.freezed.dart';
part 'runtime_details.g.dart';
// TODO add clash version
@Riverpod(keepAlive: true)
class RuntimeDetailsNotifier extends _$RuntimeDetailsNotifier with AppLogger {
@override
Future<RuntimeDetails> build() async {
loggy.debug("initializing");
final appVersion = await ref
.watch(updateRepositoryProvider)
.getCurrentVersion()
.getOrElse((l) => throw l)
.run();
return RuntimeDetails(appVersion: appVersion);
}
Future<void> checkForUpdates() async {
if (state case AsyncData(:final value)) {
switch (value.latestVersion) {
case AsyncLoading():
return;
default:
loggy.debug("checking for updates");
state =
AsyncData(value.copyWith(latestVersion: const AsyncLoading()));
// TODO use prefs
const includePreReleases = true;
await ref
.read(updateRepositoryProvider)
.getLatestVersion(includePreReleases: includePreReleases)
.match(
(l) {
loggy.warning("failed to get latest version, $l");
state = AsyncData(
value.copyWith(
latestVersion: AsyncError(l, StackTrace.current),
),
);
},
(r) {
state = AsyncData(
value.copyWith(latestVersion: AsyncData(r)),
);
},
).run();
}
}
}
}
@Riverpod(keepAlive: true)
AsyncValue<InstalledVersionInfo> appVersion(AppVersionRef ref) => ref.watch(
runtimeDetailsNotifierProvider
.select((value) => value.whenData((value) => value.appVersion)),
);
@freezed
class RuntimeDetails with _$RuntimeDetails {
const RuntimeDetails._();
const factory RuntimeDetails({
required InstalledVersionInfo appVersion,
@Default(AsyncData(null)) AsyncValue<RemoteVersionInfo?> latestVersion,
}) = _RuntimeDetails;
bool get newVersionAvailable => latestVersion.maybeWhen(
data: (data) =>
data != null &&
data.fullVersion.compareTo(this.appVersion.fullVersion) > 0,
orElse: () => false,
);
}