mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: webdav classification (#794)
* 优化设置备份[#739](https://github.com/bggRGjQaUbCoE/PiliPlus/issues/739)
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:PiliPlus/common/widgets/pair.dart';
|
import 'package:PiliPlus/common/widgets/pair.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:webdav_client/webdav_client.dart' as webdav;
|
import 'package:webdav_client/webdav_client.dart' as webdav;
|
||||||
|
|
||||||
class WebDav {
|
class WebDav {
|
||||||
@@ -44,6 +46,34 @@ class WebDav {
|
|||||||
return Pair(first: false, second: e.toString());
|
return Pair(first: false, second: e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _isPhone() async {
|
||||||
|
final deviceInfoPlugin = DeviceInfoPlugin();
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
|
||||||
|
return androidInfo.systemFeatures.contains("android.hardware.telephony");
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
|
||||||
|
return _isIosPhone(iosInfo.utsname.machine);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool _isIosPhone(String machine) {
|
||||||
|
if (machine.startsWith("iPhone")) {
|
||||||
|
return true;
|
||||||
|
} else if (machine.startsWith("iPad")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> _getFileName() async {
|
||||||
|
final isPhoneDevice = await _isPhone();
|
||||||
|
return isPhoneDevice
|
||||||
|
? 'piliplus_settings_phone.json'
|
||||||
|
: 'piliplus_settings_pad.json';
|
||||||
|
}
|
||||||
|
|
||||||
Future backup() async {
|
Future backup() async {
|
||||||
if (_client == null) {
|
if (_client == null) {
|
||||||
@@ -55,7 +85,9 @@ class WebDav {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String data = await GStorage.exportAllSettings();
|
String data = await GStorage.exportAllSettings();
|
||||||
final path = '$_webdavDirectory/piliplus_settings.json';
|
final isPhoneDevice = await _isPhone();
|
||||||
|
final fileName = await _getFileName();
|
||||||
|
final path = '$_webdavDirectory/$fileName';
|
||||||
try {
|
try {
|
||||||
await _client!.remove(path);
|
await _client!.remove(path);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
@@ -75,7 +107,9 @@ class WebDav {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final path = '$_webdavDirectory/piliplus_settings.json';
|
final isPhoneDevice = await _isPhone();
|
||||||
|
final fileName = await _getFileName();
|
||||||
|
final path = '$_webdavDirectory/$fileName';
|
||||||
final data = await _client!.read(path);
|
final data = await _client!.read(path);
|
||||||
await GStorage.importAllSettings(utf8.decode(data));
|
await GStorage.importAllSettings(utf8.decode(data));
|
||||||
SmartDialog.showToast('恢复成功');
|
SmartDialog.showToast('恢复成功');
|
||||||
|
|||||||
Reference in New Issue
Block a user