mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 07:28:26 +00:00
[mob][photos] notify user if model download is paused
This commit is contained in:
parent
51cf793012
commit
eaf136d34f
@ -493,6 +493,13 @@ class MLService {
|
||||
}
|
||||
}
|
||||
|
||||
void triggerModelsDownload() {
|
||||
if (!areModelsDownloaded && !_downloadModelLock.locked) {
|
||||
_logger.info("Models not downloaded, starting download");
|
||||
unawaited(_ensureDownloadedModels());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _ensureDownloadedModels([bool forceRefresh = false]) async {
|
||||
if (_downloadModelLock.locked) {
|
||||
_logger.finest("Download models already in progress");
|
||||
@ -504,7 +511,9 @@ class MLService {
|
||||
}
|
||||
final goodInternet = await canUseHighBandwidth();
|
||||
if (!goodInternet) {
|
||||
_logger.info("Cannot download models because user is not connected to wifi");
|
||||
_logger.info(
|
||||
"Cannot download models because user is not connected to wifi",
|
||||
);
|
||||
return;
|
||||
}
|
||||
_logger.info('Downloading models');
|
||||
|
@ -27,6 +27,7 @@ import "package:photos/ui/components/title_bar_widget.dart";
|
||||
import "package:photos/ui/components/toggle_switch_widget.dart";
|
||||
import "package:photos/ui/settings/ml/enable_ml_consent.dart";
|
||||
import "package:photos/utils/ml_util.dart";
|
||||
import "package:photos/utils/network_util.dart";
|
||||
import "package:photos/utils/wakelock_util.dart";
|
||||
|
||||
class MachineLearningSettingsPage extends StatefulWidget {
|
||||
@ -257,6 +258,8 @@ class ModelLoadingState extends StatefulWidget {
|
||||
class _ModelLoadingStateState extends State<ModelLoadingState> {
|
||||
StreamSubscription<(String, int, int)>? _progressStream;
|
||||
final Map<String, (int, int)> _progressMap = {};
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_progressStream =
|
||||
@ -277,6 +280,9 @@ class _ModelLoadingStateState extends State<ModelLoadingState> {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
_timer = Timer.periodic(const Duration(seconds: 10), (timer) {
|
||||
setState(() {});
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@ -284,6 +290,7 @@ class _ModelLoadingStateState extends State<ModelLoadingState> {
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_progressStream?.cancel();
|
||||
_timer?.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -292,8 +299,25 @@ class _ModelLoadingStateState extends State<ModelLoadingState> {
|
||||
children: [
|
||||
MenuSectionTitle(title: S.of(context).status),
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: _getTitle(context),
|
||||
captionedTextWidget: FutureBuilder(
|
||||
future: canUseHighBandwidth(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
if (snapshot.data!) {
|
||||
MLService.instance.triggerModelsDownload();
|
||||
return CaptionedTextWidget(
|
||||
title: S.of(context).loadingModel,
|
||||
key: const ValueKey("loading_model"),
|
||||
);
|
||||
} else {
|
||||
return CaptionedTextWidget(
|
||||
title: S.of(context).waitingForWifi,
|
||||
key: const ValueKey("waiting_for_wifi"),
|
||||
);
|
||||
}
|
||||
}
|
||||
return const CaptionedTextWidget(title: "");
|
||||
},
|
||||
),
|
||||
trailingWidget: EnteLoadingWidget(
|
||||
size: 12,
|
||||
@ -322,15 +346,6 @@ class _ModelLoadingStateState extends State<ModelLoadingState> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _getTitle(BuildContext context) {
|
||||
// TODO: uncomment code below to actually check for high bandwidth
|
||||
// final usableConnection = await canUseHighBandwidth();
|
||||
// if (!usableConnection) {
|
||||
// return S.of(context).waitingForWifi;
|
||||
// }
|
||||
return S.of(context).loadingModel;
|
||||
}
|
||||
}
|
||||
|
||||
class MLStatusWidget extends StatefulWidget {
|
||||
|
Loading…
x
Reference in New Issue
Block a user