Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
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
Binary file added assets/blank-profile-picture-973460_1280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/svg/app_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:lb_planner/features/themes/themes.dart';
import 'package:lb_planner/shared/shared.dart';
import 'package:auto_route/auto_route.dart';
import 'package:lb_planner/features/auth/auth.dart';
import 'package:lb_planner/features/update/update.dart';

part 'app_router.gr.dart';

Expand Down Expand Up @@ -111,13 +112,19 @@ class AppRouter extends _$AppRouter {
DefaultRoute(
page: LoginRoute.page,
path: '/login',
)
initial: true,
),
DefaultRoute(
page: UpdateRoute.page,
path: '/update',
title: (context, data) => context.t.update_btn),
];
}

/// Implements [CustomRoute] with some default settings.
class DefaultRoute extends CustomRoute {
/// Implements [CustomRoute] with some default settings.
DefaultRoute({required super.page, required super.path, super.initial})
DefaultRoute(
{required super.page, required super.path, super.initial, super.title})
: super(transitionsBuilder: TransitionsBuilders.noTransition);
}
20 changes: 20 additions & 0 deletions lib/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions lib/features/update/domain/models/patching_progress.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lb_planner/shared/shared.dart';
import 'package:lb_planner/features/update/update.dart';

part 'patching_progress.freezed.dart';

Expand All @@ -8,10 +8,16 @@ part 'patching_progress.freezed.dart';
class PatchingProgress with _$PatchingProgress {
/// Represents the progress of patching the current app.
factory PatchingProgress({
/// The version that is being patched.
required Version version,
/// The release that is currently being patched.
required Release release,

/// The progress of the patching process.
required double progress,

/// The error that occurred during patching, if any.
Object? error,

/// The stack trace of the error that occurred during patching, if any.
StackTrace? stackTrace,
}) = _PatchingProgress;
}
114 changes: 84 additions & 30 deletions lib/features/update/domain/models/patching_progress.freezed.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,35 @@ class IsUpdateAvailableProviderState extends AsyncNotifier<bool> {
/// The [ReleaseRepository] instance to use.
late final ReleaseRepository releaseRepository;

late Release _latestRelease;

/// The latest release published.
///
/// Updates when [checkForUpdates] is called.
Release get latestRelease => _latestRelease;

@override
FutureOr<bool> build() {
FutureOr<bool> build() async {
releaseRepository = ref.watch(releaseRepositoryProvider);

return releaseRepository.isUpdateAvailable();
return _checkForUpdates();
}

/// Checks whether an update is available.
/// Checks if a new release has been published.
Future<void> checkForUpdates() async {
state = AsyncLoading();

state = await AsyncValue.guard(releaseRepository.isUpdateAvailable);
state = await AsyncValue.guard(_checkForUpdates);
}

/// INTERNAL USE ONLY!
///
/// Checks whether an update is available.
///
/// Called by [build] and [checkForUpdates].
Future<bool> _checkForUpdates() async {
_latestRelease = await releaseRepository.getLatestRelease();

return releaseRepository.isUpdateAvailable();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import 'package:lb_planner/features/update/update.dart';
import 'package:riverpod/riverpod.dart';

/// Provides the current [PatchingProgress].
/// Provides the progress of the current patching process.
///
/// The progess is represented as double between `0.0` and `1.0`.
///
/// NOTE: Resolves to `null` if no patching is in progress.
///
/// To start patching, use [patchingProgressController].
/// If you want start a patching process, use [patchingProgressController].
final patchingProgressProvider =
StateNotifierProvider<PatchingProgressProviderState, PatchingProgress?>(
(ref) {
final patcherService = ref.watch(patcherServiceProvider);
final releaseRepository = ref.watch(releaseRepositoryProvider);

return PatchingProgressProviderState(
patcherService,
releaseRepository,
);
},
AsyncNotifierProvider<PatchingProgressProviderState, double?>(
() => PatchingProgressProviderState(),
);

/// Expososes the controller for [patchingProgressProvider].
/// Exposes methods for patching the app.
///
/// If [patchingProgressProvider] resolves to [AsyncLoading], the patcher is currently being initialized and it unsafe to use any properties or methods.
///
/// If [patchingProgressProvider] resolves to [AsyncError], there was an error while patching or an error during setup, which also makes it unsafe to call any methods or use any properties.
///
/// To receive updates on the patching progress, use [patchingProgressProvider].
/// If you want to read the current patching progress, use [patchingProgressProvider].
final patchingProgressController = patchingProgressProvider.notifier;
Loading