mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve WebDAV: add auto sync option and improve settings UI (#203)
This commit is contained in:
@@ -354,10 +354,10 @@
|
|||||||
"The comic will be marked as no updates as soon as you read it.": "漫画将在您阅读后立即标记为无更新",
|
"The comic will be marked as no updates as soon as you read it.": "漫画将在您阅读后立即标记为无更新",
|
||||||
"Disable": "禁用",
|
"Disable": "禁用",
|
||||||
"Once the operation is successful, app will automatically sync data with the server.": "操作成功后, APP将自动与服务器同步数据",
|
"Once the operation is successful, app will automatically sync data with the server.": "操作成功后, APP将自动与服务器同步数据",
|
||||||
"Webdav is enabled." : "已启用Webdav",
|
|
||||||
"Cache cleared": "缓存已清除",
|
"Cache cleared": "缓存已清除",
|
||||||
"Disabled": "已禁用",
|
"Disabled": "已禁用",
|
||||||
"Last Reading: @epName Page @page": "上次阅读: @epName 第 @page 页"
|
"Last Reading: @epName Page @page": "上次阅读: @epName 第 @page 页",
|
||||||
|
"WebDAV Auto Sync": "WebDAV 自动同步"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -714,9 +714,9 @@
|
|||||||
"The comic will be marked as no updates as soon as you read it.": "漫畫將在您閱讀後立即標記為無更新",
|
"The comic will be marked as no updates as soon as you read it.": "漫畫將在您閱讀後立即標記為無更新",
|
||||||
"Disable": "禁用",
|
"Disable": "禁用",
|
||||||
"Once the operation is successful, app will automatically sync data with the server.": "操作成功後, APP將自動與服務器同步數據",
|
"Once the operation is successful, app will automatically sync data with the server.": "操作成功後, APP將自動與服務器同步數據",
|
||||||
"Webdav is enabled." : "已啟用Webdav",
|
|
||||||
"Cache cleared": "緩存已清除",
|
"Cache cleared": "緩存已清除",
|
||||||
"Disabled": "已禁用",
|
"Disabled": "已禁用",
|
||||||
"Last Reading: @epName Page @page": "上次閱讀: @epName 第 @page 頁"
|
"Last Reading: @epName Page @page": "上次閱讀: @epName 第 @page 頁",
|
||||||
|
"WebDAV Auto Sync": "WebDAV 自動同步"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -330,6 +330,7 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
String url = "";
|
String url = "";
|
||||||
String user = "";
|
String user = "";
|
||||||
String pass = "";
|
String pass = "";
|
||||||
|
bool autoSync = false;
|
||||||
|
|
||||||
bool isTesting = false;
|
bool isTesting = false;
|
||||||
bool upload = true;
|
bool upload = true;
|
||||||
@@ -349,6 +350,7 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
user = configs[1];
|
user = configs[1];
|
||||||
pass = configs[2];
|
pass = configs[2];
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
|
autoSync = appdata.settings['webdavAutoSync'] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -358,6 +360,18 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text("WebDAV Auto Sync".tl),
|
||||||
|
value: autoSync,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
autoSync = value;
|
||||||
|
appdata.settings['webdavAutoSync'] = value;
|
||||||
|
appdata.saveData();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
@@ -428,39 +442,33 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (isEnabled)
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.sync, size: 20),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text("Webdav is enabled.".tl),
|
|
||||||
),
|
|
||||||
Button.text(
|
|
||||||
onPressed: () {
|
|
||||||
appdata.settings['webdav'] = [];
|
|
||||||
appdata.saveData();
|
|
||||||
context.showMessage(message: "Disabled".tl);
|
|
||||||
App.rootPop();
|
|
||||||
},
|
|
||||||
child: Text("Disable".tl),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
).paddingTop(16),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Center(
|
Center(
|
||||||
child: Button.filled(
|
child: Button.filled(
|
||||||
isLoading: isTesting,
|
isLoading: isTesting,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var oldConfig = appdata.settings['webdav'];
|
var oldConfig = appdata.settings['webdav'];
|
||||||
|
var oldAutoSync = appdata.settings['webdavAutoSync'];
|
||||||
|
|
||||||
|
if (url.trim().isEmpty && user.trim().isEmpty && pass.trim().isEmpty) {
|
||||||
|
appdata.settings['webdav'] = [];
|
||||||
|
appdata.settings['webdavAutoSync'] = false;
|
||||||
|
appdata.saveData();
|
||||||
|
context.showMessage(message: "Saved".tl);
|
||||||
|
App.rootPop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
appdata.settings['webdav'] = [url, user, pass];
|
appdata.settings['webdav'] = [url, user, pass];
|
||||||
|
appdata.settings['webdavAutoSync'] = autoSync;
|
||||||
|
|
||||||
|
if (!autoSync) {
|
||||||
|
appdata.saveData();
|
||||||
|
context.showMessage(message: "Saved".tl);
|
||||||
|
App.rootPop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isTesting = true;
|
isTesting = true;
|
||||||
});
|
});
|
||||||
@@ -472,6 +480,7 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
isTesting = false;
|
isTesting = false;
|
||||||
});
|
});
|
||||||
appdata.settings['webdav'] = oldConfig;
|
appdata.settings['webdav'] = oldConfig;
|
||||||
|
appdata.settings['webdavAutoSync'] = oldAutoSync;
|
||||||
context.showMessage(message: testResult.errorMessage!);
|
context.showMessage(message: testResult.errorMessage!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -40,15 +40,19 @@ class DataSync with ChangeNotifier {
|
|||||||
|
|
||||||
bool get isEnabled {
|
bool get isEnabled {
|
||||||
var config = appdata.settings['webdav'];
|
var config = appdata.settings['webdav'];
|
||||||
return config is List && config.isNotEmpty;
|
var autoSync = appdata.settings['webdavAutoSync'] ?? false;
|
||||||
|
return autoSync && config is List && config.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String>? _validateConfig() {
|
List<String>? _validateConfig() {
|
||||||
var config = appdata.settings['webdav'];
|
var config = appdata.settings['webdav'];
|
||||||
if (config is! List || (config.isNotEmpty && config.length != 3)) {
|
if (config is! List) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (config.whereType<String>().length != 3) {
|
if (config.isEmpty) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (config.length != 3 || config.whereType<String>().length != 3) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return List.from(config);
|
return List.from(config);
|
||||||
|
Reference in New Issue
Block a user