make tab restoration optional
This commit is contained in:
+90
-40
@@ -18,50 +18,100 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||||
|
|
||||||
Future<bool?> showClearContainerDataDialog(BuildContext context, int tabCount) {
|
class ClearContainerDataResult {
|
||||||
return showDialog<bool?>(
|
final bool confirmed;
|
||||||
|
final bool reopenTabs;
|
||||||
|
|
||||||
|
const ClearContainerDataResult({
|
||||||
|
required this.confirmed,
|
||||||
|
required this.reopenTabs,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ClearContainerDataResult?> showClearContainerDataDialog(
|
||||||
|
BuildContext context,
|
||||||
|
int tabCount,
|
||||||
|
) {
|
||||||
|
return showDialog<ClearContainerDataResult?>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return _ClearContainerDataDialog(tabCount: tabCount);
|
||||||
icon: const Icon(MdiIcons.databaseRemove),
|
|
||||||
title: const Text('Clear Container Data?'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Text('This will clear all data for this container:'),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
const Text('• Cookies'),
|
|
||||||
const Text('• Site data'),
|
|
||||||
const Text('• Cache'),
|
|
||||||
const Text('• Permissions'),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'$tabCount tab(s) will be closed and reopened fresh.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context).colorScheme.tertiary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, false);
|
|
||||||
},
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context, true);
|
|
||||||
},
|
|
||||||
child: const Text('Clear Data'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ClearContainerDataDialog extends HookWidget {
|
||||||
|
final int tabCount;
|
||||||
|
|
||||||
|
const _ClearContainerDataDialog({required this.tabCount});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final reopenTabs = useState(false);
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
icon: const Icon(MdiIcons.databaseRemove),
|
||||||
|
title: const Text('Clear Container Data'),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Text('This will clear all data for this container:'),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
const Text('• Cookies'),
|
||||||
|
const Text('• Site data'),
|
||||||
|
const Text('• Cache'),
|
||||||
|
const Text('• Permissions'),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'$tabCount tab(s) will be closed.',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Theme.of(context).colorScheme.tertiary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
CheckboxListTile(
|
||||||
|
value: reopenTabs.value,
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value != null) {
|
||||||
|
reopenTabs.value = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title: const Text('Recreate tabs after clearing'),
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
controlAffinity: ListTileControlAffinity.trailing,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(
|
||||||
|
context,
|
||||||
|
const ClearContainerDataResult(
|
||||||
|
confirmed: false,
|
||||||
|
reopenTabs: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(
|
||||||
|
context,
|
||||||
|
ClearContainerDataResult(
|
||||||
|
confirmed: true,
|
||||||
|
reopenTabs: reopenTabs.value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Clear Data'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+46
-40
@@ -378,7 +378,9 @@ class TabViewHeader extends HookConsumerWidget {
|
|||||||
tabs.length,
|
tabs.length,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result == true) {
|
if (result?.confirmed == true) {
|
||||||
|
final shouldReopenTabs = result!.reopenTabs;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final closedTabIds = await ref
|
final closedTabIds = await ref
|
||||||
.read(
|
.read(
|
||||||
@@ -398,52 +400,56 @@ class TabViewHeader extends HookConsumerWidget {
|
|||||||
.contextualIdentity!,
|
.contextualIdentity!,
|
||||||
);
|
);
|
||||||
|
|
||||||
await ref
|
if (shouldReopenTabs) {
|
||||||
.read(
|
await ref
|
||||||
tabRepositoryProvider.notifier,
|
.read(
|
||||||
)
|
tabRepositoryProvider.notifier,
|
||||||
.addMultipleTabs(
|
)
|
||||||
tabs: tabs.map((tab) {
|
.addMultipleTabs(
|
||||||
var parentId = tab.parentId;
|
tabs: tabs.map((tab) {
|
||||||
while (parentId != null &&
|
var parentId = tab.parentId;
|
||||||
closedTabIds.contains(
|
while (parentId != null &&
|
||||||
parentId,
|
closedTabIds.contains(
|
||||||
)) {
|
parentId,
|
||||||
parentId = tabs
|
)) {
|
||||||
.firstWhereOrNull(
|
parentId = tabs
|
||||||
(old) =>
|
.firstWhereOrNull(
|
||||||
old.id == parentId,
|
(old) =>
|
||||||
)
|
old.id == parentId,
|
||||||
?.parentId;
|
)
|
||||||
}
|
?.parentId;
|
||||||
|
}
|
||||||
|
|
||||||
return AddTabParams(
|
return AddTabParams(
|
||||||
url: tab.url.toString(),
|
url: tab.url.toString(),
|
||||||
startLoading: true,
|
startLoading: true,
|
||||||
parentId: parentId,
|
parentId: parentId,
|
||||||
private:
|
private:
|
||||||
tab.isPrivate ?? false,
|
tab.isPrivate ?? false,
|
||||||
flags: LoadUrlFlags.NONE
|
flags: LoadUrlFlags.NONE
|
||||||
.toValue(),
|
.toValue(),
|
||||||
source: Internal.newTab
|
source: Internal.newTab
|
||||||
.toValue(),
|
.toValue(),
|
||||||
contextId: selectedContainer
|
contextId: selectedContainer
|
||||||
.metadata
|
.metadata
|
||||||
.contextualIdentity,
|
.contextualIdentity,
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
container: Value(
|
container: Value(
|
||||||
selectedContainer,
|
selectedContainer,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(
|
ScaffoldMessenger.of(
|
||||||
context,
|
context,
|
||||||
).showSnackBar(
|
).showSnackBar(
|
||||||
const SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'Container data cleared successfully',
|
shouldReopenTabs
|
||||||
|
? 'Container data cleared successfully'
|
||||||
|
: 'Container data cleared. ${tabs.length} tab(s) closed.',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user