Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Option to require Wi-Fi for auto-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mortein committed Feb 27, 2021
1 parent 41108a7 commit 63ee1e4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"show_upload_queue": "Show upload queue",
"show_uploaded_photos_list": "Show uploaded photos list",
"show_failed_uploads_list": "Show failed uploads list",
"select_albums_for_auto_upload": "Select albums for auto-upload"
}
"select_albums_for_auto_upload": "Select albums for auto-upload",
"auto_upload_wifi_only": "Only automatically upload on Wi-Fi"
}
18 changes: 18 additions & 0 deletions lib/common/photoprism_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:background_fetch/background_fetch.dart';
import 'package:photoprism/api/api.dart';
import 'package:photoprism/model/photoprism_model.dart';
import 'package:photo_manager/photo_manager.dart' as photolib;
import 'package:connectivity/connectivity.dart';

class PhotoprismUploader {
PhotoprismUploader(this.photoprismModel) {
Expand Down Expand Up @@ -87,6 +88,13 @@ class PhotoprismUploader {
getPhotosToUpload(photoprismModel);
}

Future<void> setAutoUploadWifiOnly(bool autoUploadWifiOnlyNew) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool('autoUploadWifiOnly', autoUploadWifiOnlyNew);
photoprismModel.autoUploadWifiOnly = autoUploadWifiOnlyNew;
photoprismModel.notify();
}

Future<void> setAutoUploadLastTimeActive() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
// get current date and time
Expand Down Expand Up @@ -243,6 +251,16 @@ class PhotoprismUploader {
return;
}

if (photoprismModel.autoUploadWifiOnly) {
final ConnectivityResult connectivityResult =
await Connectivity().checkConnectivity();
if (connectivityResult != ConnectivityResult.wifi) {
model.addLogEntry('AutoUploader',
'Auto upload requires Wi-Fi. Stopping autoupload routine.');
return;
}
}

if (photoprismModel.photoprismUrl == 'https://demo.photoprism.org') {
model.addLogEntry('AutoUploader',
'Auto upload disabled for demo page. Stopping autoupload routine.');
Expand Down
1 change: 1 addition & 0 deletions lib/model/photoprism_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PhotoprismModel extends ChangeNotifier {

// photoprism uploader
bool autoUploadEnabled = false;
bool autoUploadWifiOnly = true;
String autoUploadLastTimeCheckedForPhotos = 'Never';
Set<String> _albumsToUpload = <String>{};
Set<String> _photosToUpload = <String>{};
Expand Down
9 changes: 9 additions & 0 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ class SettingsPage extends StatelessWidget {
configureAlbumsToUpload(context);
},
),
if (model.autoUploadEnabled)
SwitchListTile(
title: Text('auto_upload_wifi_only'.tr()),
secondary: const Icon(Icons.wifi),
value: model.autoUploadWifiOnly,
onChanged: (bool newState) async {
model.photoprismUploader.setAutoUploadWifiOnly(newState);
},
),
if (model.autoUploadEnabled)
ListTile(
title: const Text('last_time_checked_for_photos_to_be_uploaded')
Expand Down
28 changes: 28 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
connectivity:
dependency: "direct main"
description:
name: connectivity
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
connectivity_for_web:
dependency: transitive
description:
name: connectivity_for_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.1+4"
connectivity_macos:
dependency: transitive
description:
name: connectivity_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0+7"
connectivity_platform_interface:
dependency: transitive
description:
name: connectivity_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.6"
convert:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
draggable_scrollbar:
git:
url: git://github.com/thielepaul/flutter-draggable-scrollbar.git
connectivity: ^2.0.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 63ee1e4

Please sign in to comment.