mirror of
https://github.com/venera-app/venera.git
synced 2025-12-16 23:11:15 +00:00
Compare commits
4 Commits
b08f11f6ac
...
feat/login
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ccf0eea43 | |||
| 09a1d2821c | |||
|
|
7842b5a1ac | ||
|
|
079f574e2f |
@@ -181,7 +181,15 @@ abstract class ImageDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configs['onResponse'] is JSInvokable) {
|
if (configs['onResponse'] is JSInvokable) {
|
||||||
buffer = (configs['onResponse'] as JSInvokable)([Uint8List.fromList(buffer)]);
|
dynamic result = (configs['onResponse'] as JSInvokable)([Uint8List.fromList(buffer)]);
|
||||||
|
if (result is Future) {
|
||||||
|
result = await result;
|
||||||
|
}
|
||||||
|
if (result is List<int>) {
|
||||||
|
buffer = result;
|
||||||
|
} else {
|
||||||
|
throw "Error: Invalid onResponse result.";
|
||||||
|
}
|
||||||
(configs['onResponse'] as JSInvokable).free();
|
(configs['onResponse'] as JSInvokable).free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,11 +197,12 @@ class _NetworkSectionState extends State<_NetworkSection> {
|
|||||||
if (res.subData is List) {
|
if (res.subData is List) {
|
||||||
final list = List<String>.from(res.subData);
|
final list = List<String>.from(res.subData);
|
||||||
if (list.isNotEmpty) {
|
if (list.isNotEmpty) {
|
||||||
addedFolders = {list.first};
|
addedFolders = list.toSet();
|
||||||
|
localIsFavorite = true;
|
||||||
} else {
|
} else {
|
||||||
addedFolders.clear();
|
addedFolders.clear();
|
||||||
|
localIsFavorite = false;
|
||||||
}
|
}
|
||||||
localIsFavorite = addedFolders.isNotEmpty;
|
|
||||||
} else {
|
} else {
|
||||||
addedFolders.clear();
|
addedFolders.clear();
|
||||||
localIsFavorite = false;
|
localIsFavorite = false;
|
||||||
@@ -352,62 +353,6 @@ class _NetworkSectionState extends State<_NetworkSection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMultiFolder() {
|
Widget _buildMultiFolder() {
|
||||||
if (localIsFavorite == true &&
|
|
||||||
widget.comicSource.favoriteData!.singleFolderForSingleComic) {
|
|
||||||
return ListTile(
|
|
||||||
title: Row(
|
|
||||||
children: [
|
|
||||||
Text("Network Favorites".tl),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: context.colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Text("Added".tl, style: ts.s12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
trailing: isLoading
|
|
||||||
? const SizedBox(
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
|
||||||
)
|
|
||||||
: _HoverButton(
|
|
||||||
isFavorite: true,
|
|
||||||
onTap: () async {
|
|
||||||
setState(() {
|
|
||||||
isLoading = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
var res = await widget
|
|
||||||
.comicSource
|
|
||||||
.favoriteData!
|
|
||||||
.addOrDelFavorite!(widget.cid, '', false, null);
|
|
||||||
if (res.success) {
|
|
||||||
// Invalidate network cache so subsequent loads see latest
|
|
||||||
NetworkCacheManager().clear();
|
|
||||||
setState(() {
|
|
||||||
localIsFavorite = false;
|
|
||||||
});
|
|
||||||
widget.onFavorite(false);
|
|
||||||
App.rootContext.showMessage(message: "Removed".tl);
|
|
||||||
if (appdata.settings['autoCloseFavoritePanel'] ?? false) {
|
|
||||||
context.pop();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
context.showMessage(message: res.errorMessage!);
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -425,8 +370,10 @@ class _NetworkSectionState extends State<_NetworkSection> {
|
|||||||
var name = entry.value;
|
var name = entry.value;
|
||||||
var id = entry.key;
|
var id = entry.key;
|
||||||
var isAdded = addedFolders.contains(id);
|
var isAdded = addedFolders.contains(id);
|
||||||
var hasSelection = addedFolders.isNotEmpty;
|
// When `singleFolderForSingleComic` is `false`, all add and remove buttons are clickable.
|
||||||
var enabled = !hasSelection || isAdded;
|
// When `singleFolderForSingleComic` is `true`, the remove button is always clickable,
|
||||||
|
// while the add button is only clickable if the comic has not been added to any list.
|
||||||
|
var enabled = !(widget.comicSource.favoriteData!.singleFolderForSingleComic && addedFolders.isNotEmpty && !isAdded);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
@@ -469,11 +416,9 @@ class _NetworkSectionState extends State<_NetworkSection> {
|
|||||||
NetworkCacheManager().clear();
|
NetworkCacheManager().clear();
|
||||||
setState(() {
|
setState(() {
|
||||||
if (isAdded) {
|
if (isAdded) {
|
||||||
addedFolders.clear();
|
addedFolders.remove(id);
|
||||||
} else {
|
} else {
|
||||||
addedFolders
|
addedFolders.add(id);
|
||||||
..clear()
|
|
||||||
..add(id);
|
|
||||||
}
|
}
|
||||||
// sync local flag for single-folder-per-comic logic and parent
|
// sync local flag for single-folder-per-comic logic and parent
|
||||||
localIsFavorite = addedFolders.isNotEmpty;
|
localIsFavorite = addedFolders.isNotEmpty;
|
||||||
|
|||||||
@@ -1245,6 +1245,15 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
if (widget.config.checkLoginStatus != null &&
|
if (widget.config.checkLoginStatus != null &&
|
||||||
widget.config.checkLoginStatus!(url, title)) {
|
widget.config.checkLoginStatus!(url, title)) {
|
||||||
var cookies = (await c.getCookies(url)) ?? [];
|
var cookies = (await c.getCookies(url)) ?? [];
|
||||||
|
var localStorageItems = await c.webStorage.localStorage.getItems();
|
||||||
|
var mappedLocalStorage = <String, dynamic>{};
|
||||||
|
for (var item in localStorageItems) {
|
||||||
|
if (item.key != null) {
|
||||||
|
mappedLocalStorage[item.key!] = item.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
widget.source.data['_localStorage'] = mappedLocalStorage;
|
||||||
|
await widget.source.saveData();
|
||||||
SingleInstanceCookieJar.instance?.saveFromResponse(
|
SingleInstanceCookieJar.instance?.saveFromResponse(
|
||||||
Uri.parse(url),
|
Uri.parse(url),
|
||||||
cookies,
|
cookies,
|
||||||
@@ -1306,6 +1315,20 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
Uri.parse(url),
|
Uri.parse(url),
|
||||||
cookies,
|
cookies,
|
||||||
);
|
);
|
||||||
|
var localStorageJson = await webview.evaluateJavascript(
|
||||||
|
"JSON.stringify(window.localStorage);",
|
||||||
|
);
|
||||||
|
var localStorage = <String, dynamic>{};
|
||||||
|
try {
|
||||||
|
var decoded = jsonDecode(localStorageJson ?? '');
|
||||||
|
if (decoded is Map<String, dynamic>) {
|
||||||
|
localStorage = decoded;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("ComicSourcePage", "Failed to parse localStorage JSON\n$e");
|
||||||
|
}
|
||||||
|
widget.source.data['_localStorage'] = localStorage;
|
||||||
|
await widget.source.saveData();
|
||||||
success = true;
|
success = true;
|
||||||
widget.config.onLoginWithWebviewSuccess?.call();
|
widget.config.onLoginWithWebviewSuccess?.call();
|
||||||
webview.close();
|
webview.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user