mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Add error status to data sync component.
This commit is contained in:
@@ -125,11 +125,11 @@ class OverlayWidgetState extends State<OverlayWidget> {
|
|||||||
void showDialogMessage(BuildContext context, String title, String message) {
|
void showDialogMessage(BuildContext context, String title, String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => ContentDialog(
|
||||||
title: Text(title),
|
title: title,
|
||||||
content: Text(message),
|
content: Text(message).paddingHorizontal(16),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
FilledButton(
|
||||||
onPressed: context.pop,
|
onPressed: context.pop,
|
||||||
child: Text("OK".tl),
|
child: Text("OK".tl),
|
||||||
)
|
)
|
||||||
|
@@ -162,16 +162,50 @@ class _SyncDataWidgetState extends State<_SyncDataWidget>
|
|||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
if (DataSync().lastError != null)
|
||||||
|
InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
onTap: () {
|
||||||
|
showDialogMessage(
|
||||||
|
App.rootContext,
|
||||||
|
"Error".tl,
|
||||||
|
DataSync().lastError!,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.errorContainer,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.error_outline,
|
||||||
|
color: Colors.red,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text('Error'.tl, style: ts.s12),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).paddingRight(4),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.cloud_upload_outlined),
|
icon: const Icon(Icons.cloud_upload_outlined),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
DataSync().uploadData();
|
DataSync().uploadData();
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.cloud_download_outlined),
|
icon: const Icon(Icons.cloud_download_outlined),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
DataSync().downloadData();
|
DataSync().downloadData();
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -538,7 +572,8 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
launchUrlString("https://github.com/venera-app/venera/blob/master/doc/import_comic.md");
|
launchUrlString(
|
||||||
|
"https://github.com/venera-app/venera/blob/master/doc/import_comic.md");
|
||||||
},
|
},
|
||||||
).fixWidth(90).paddingRight(8),
|
).fixWidth(90).paddingRight(8),
|
||||||
Button.filled(
|
Button.filled(
|
||||||
@@ -697,14 +732,24 @@ class _ComicSourceWidgetState extends State<_ComicSourceWidget> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.update, color: context.colorScheme.primary, size: 20,),
|
Icon(
|
||||||
|
Icons.update,
|
||||||
|
color: context.colorScheme.primary,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text("@c updates".tlParams({
|
Text(
|
||||||
'c': _availableUpdates,
|
"@c updates".tlParams({
|
||||||
}), style: ts.withColor(context.colorScheme.primary),),
|
'c': _availableUpdates,
|
||||||
|
}),
|
||||||
|
style: ts.withColor(context.colorScheme.primary),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
).toAlign(Alignment.centerLeft).paddingHorizontal(16).paddingBottom(8),
|
)
|
||||||
|
.toAlign(Alignment.centerLeft)
|
||||||
|
.paddingHorizontal(16)
|
||||||
|
.paddingBottom(8),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -844,7 +889,8 @@ class _ImageFavoritesState extends State<ImageFavorites> {
|
|||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 8, vertical: 2),
|
horizontal: 8, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
color:
|
||||||
|
Theme.of(context).colorScheme.secondaryContainer,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
@@ -40,7 +40,11 @@ class DataSync with ChangeNotifier {
|
|||||||
|
|
||||||
bool get isUploading => _isUploading;
|
bool get isUploading => _isUploading;
|
||||||
|
|
||||||
bool haveWaitingTask = false;
|
bool _haveWaitingTask = false;
|
||||||
|
|
||||||
|
String? _lastError;
|
||||||
|
|
||||||
|
String? get lastError => _lastError;
|
||||||
|
|
||||||
bool get isEnabled {
|
bool get isEnabled {
|
||||||
var config = appdata.settings['webdav'];
|
var config = appdata.settings['webdav'];
|
||||||
@@ -64,17 +68,19 @@ class DataSync with ChangeNotifier {
|
|||||||
|
|
||||||
Future<Res<bool>> uploadData() async {
|
Future<Res<bool>> uploadData() async {
|
||||||
if (isDownloading) return const Res(true);
|
if (isDownloading) return const Res(true);
|
||||||
if (haveWaitingTask) return const Res(true);
|
if (_haveWaitingTask) return const Res(true);
|
||||||
while (isUploading) {
|
while (isUploading) {
|
||||||
haveWaitingTask = true;
|
_haveWaitingTask = true;
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
}
|
}
|
||||||
haveWaitingTask = false;
|
_haveWaitingTask = false;
|
||||||
_isUploading = true;
|
_isUploading = true;
|
||||||
|
_lastError = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
var config = _validateConfig();
|
var config = _validateConfig();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
|
_lastError = 'Invalid WebDAV configuration';
|
||||||
return const Res.error('Invalid WebDAV configuration');
|
return const Res.error('Invalid WebDAV configuration');
|
||||||
}
|
}
|
||||||
if (config.isEmpty) {
|
if (config.isEmpty) {
|
||||||
@@ -98,13 +104,6 @@ class DataSync with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
|
||||||
await client.ping();
|
|
||||||
} catch (e) {
|
|
||||||
Log.error("Upload Data", 'Failed to connect to WebDAV server');
|
|
||||||
return const Res.error('Failed to connect to WebDAV server');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
appdata.settings['dataVersion']++;
|
appdata.settings['dataVersion']++;
|
||||||
await appdata.saveData(false);
|
await appdata.saveData(false);
|
||||||
@@ -131,6 +130,7 @@ class DataSync with ChangeNotifier {
|
|||||||
return const Res(true);
|
return const Res(true);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Upload Data", e, s);
|
Log.error("Upload Data", e, s);
|
||||||
|
_lastError = e.toString();
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -140,17 +140,19 @@ class DataSync with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Res<bool>> downloadData() async {
|
Future<Res<bool>> downloadData() async {
|
||||||
if (haveWaitingTask) return const Res(true);
|
if (_haveWaitingTask) return const Res(true);
|
||||||
while (isDownloading || isUploading) {
|
while (isDownloading || isUploading) {
|
||||||
haveWaitingTask = true;
|
_haveWaitingTask = true;
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
}
|
}
|
||||||
haveWaitingTask = false;
|
_haveWaitingTask = false;
|
||||||
_isDownloading = true;
|
_isDownloading = true;
|
||||||
|
_lastError = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
var config = _validateConfig();
|
var config = _validateConfig();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
|
_lastError = 'Invalid WebDAV configuration';
|
||||||
return const Res.error('Invalid WebDAV configuration');
|
return const Res.error('Invalid WebDAV configuration');
|
||||||
}
|
}
|
||||||
if (config.isEmpty) {
|
if (config.isEmpty) {
|
||||||
@@ -174,13 +176,6 @@ class DataSync with ChangeNotifier {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
|
||||||
await client.ping();
|
|
||||||
} catch (e) {
|
|
||||||
Log.error("Data Sync", 'Failed to connect to WebDAV server');
|
|
||||||
return const Res.error('Failed to connect to WebDAV server');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var files = await client.readDir('/');
|
var files = await client.readDir('/');
|
||||||
files.sort((a, b) => b.name!.compareTo(a.name!));
|
files.sort((a, b) => b.name!.compareTo(a.name!));
|
||||||
@@ -206,6 +201,7 @@ class DataSync with ChangeNotifier {
|
|||||||
return const Res(true);
|
return const Res(true);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Data Sync", e, s);
|
Log.error("Data Sync", e, s);
|
||||||
|
_lastError = e.toString();
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
Reference in New Issue
Block a user