clear data of isolated containers; improved tab handling/state/duplication;
This commit is contained in:
@@ -32,6 +32,8 @@ part 'tab.g.dart';
|
||||
|
||||
@CopyWith()
|
||||
class TabState extends WebPageInfo {
|
||||
static final defaultUrl = Uri.parse('about:blank');
|
||||
|
||||
@CopyWithField(immutable: true)
|
||||
final String id;
|
||||
|
||||
@@ -92,7 +94,7 @@ class TabState extends WebPageInfo {
|
||||
id: tabId,
|
||||
parentId: null,
|
||||
contextId: null,
|
||||
url: Uri.parse('about:blank'),
|
||||
url: defaultUrl,
|
||||
title: "",
|
||||
icon: null,
|
||||
thumbnail: null,
|
||||
|
||||
@@ -46,9 +46,9 @@ part 'tab_state.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class TabStates extends _$TabStates {
|
||||
void _onTabContentStateChange(TabContentState contentState) {
|
||||
final current =
|
||||
state[contentState.id] ?? TabState.$default(contentState.id);
|
||||
Future<void> _onTabContentStateChange(TabContentState contentState) async {
|
||||
final current = await patchedState(contentState.id);
|
||||
|
||||
final url = Uri.parse(contentState.url);
|
||||
|
||||
// Determine title based on priority: new non-empty title > existing title if URL authority unchanged > new title
|
||||
@@ -81,6 +81,27 @@ class TabStates extends _$TabStates {
|
||||
}
|
||||
}
|
||||
|
||||
Future<TabState> patchedState(String id) async {
|
||||
var current = stateOrNull?[id];
|
||||
|
||||
if (current == null || current.url == TabState.defaultUrl) {
|
||||
current ??= TabState.$default(id);
|
||||
|
||||
final tabData = await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.getTabDataById(id);
|
||||
|
||||
if (tabData?.url != null) {
|
||||
current = current.copyWith(
|
||||
title: tabData!.title ?? current.title,
|
||||
url: tabData.url ?? current.url,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
Future<void> _onIconChange(IconChangeEvent event) async {
|
||||
final IconChangeEvent(:tabId, :bytes) = event;
|
||||
|
||||
@@ -174,8 +195,8 @@ class TabStates extends _$TabStates {
|
||||
final eventService = ref.watch(eventServiceProvider);
|
||||
|
||||
final subscriptions = [
|
||||
eventService.tabContentEvents.listen((event) {
|
||||
_onTabContentStateChange(event);
|
||||
eventService.tabContentEvents.listen((event) async {
|
||||
await _onTabContentStateChange(event);
|
||||
}),
|
||||
eventService.iconChangeEvents.listen((event) async {
|
||||
await _onIconChange(event);
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabStatesProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabStatesHash() => r'778242f0b67eb7646014d0df857a3a71de214c40';
|
||||
String _$tabStatesHash() => r'cd73ea6ea479f2708a2c9e5ca86054c9d2464116';
|
||||
|
||||
abstract class _$TabStates extends $Notifier<Map<String, TabState>> {
|
||||
Map<String, TabState> build();
|
||||
|
||||
@@ -75,7 +75,7 @@ class TabRepository extends _$TabRepository {
|
||||
await ref.read(selectedContainerProvider.notifier).fetchData(),
|
||||
);
|
||||
|
||||
final newTabId = await tabDao.upsertContainerTabTransactional(
|
||||
final newTabId = await tabDao.upsertTabTransactional(
|
||||
() {
|
||||
return _tabsService.addTab(
|
||||
url: url,
|
||||
@@ -93,6 +93,7 @@ class TabRepository extends _$TabRepository {
|
||||
parentId: Value(parentId),
|
||||
containerId: Value(assingedContainer.value?.id),
|
||||
isPrivate: Value(private),
|
||||
url: Value(url),
|
||||
);
|
||||
|
||||
if (launchedFromIntent) {
|
||||
@@ -102,10 +103,42 @@ class TabRepository extends _$TabRepository {
|
||||
return newTabId;
|
||||
}
|
||||
|
||||
Future<List<String>> addMultipleTabs({
|
||||
required List<AddTabParams> tabs,
|
||||
String? selectTabId,
|
||||
Value<ContainerData?>? container,
|
||||
}) async {
|
||||
final tabDao = ref.read(tabDatabaseProvider).tabDao;
|
||||
final db = ref.read(tabDatabaseProvider);
|
||||
|
||||
return await db.transaction(() async {
|
||||
final createdTabIds = await _tabsService.addMultipleTabs(
|
||||
tabs: tabs,
|
||||
selectTabId: selectTabId,
|
||||
);
|
||||
|
||||
// Upsert all tabs in the database
|
||||
for (var i = 0; i < createdTabIds.length; i++) {
|
||||
final tabId = createdTabIds[i];
|
||||
final tab = tabs[i];
|
||||
|
||||
await tabDao.insertTab(
|
||||
tabId,
|
||||
parentId: Value(tab.parentId),
|
||||
containerId: Value(container?.value?.id),
|
||||
isPrivate: Value(tab.private),
|
||||
url: Value(Uri.tryParse(tab.url)),
|
||||
);
|
||||
}
|
||||
|
||||
return createdTabIds;
|
||||
});
|
||||
}
|
||||
|
||||
Future<String> duplicateTab({
|
||||
required String selectTabId,
|
||||
String? containerId,
|
||||
bool selectTab = true,
|
||||
required String? containerId,
|
||||
bool selectTab = false,
|
||||
}) async {
|
||||
final tabDao = ref.read(tabDatabaseProvider).tabDao;
|
||||
|
||||
@@ -115,7 +148,7 @@ class TabRepository extends _$TabRepository {
|
||||
.getContainerData(containerId),
|
||||
);
|
||||
|
||||
return await tabDao.upsertContainerTabTransactional(
|
||||
return await tabDao.upsertTabTransactional(
|
||||
() {
|
||||
return _tabsService.duplicateTab(
|
||||
selectTabId: selectTabId,
|
||||
@@ -376,14 +409,16 @@ class TabRepository extends _$TabRepository {
|
||||
final db = ref.watch(tabDatabaseProvider);
|
||||
|
||||
final tabAddedSub = eventSerivce.tabAddedStream.listen((tabId) async {
|
||||
// ignore: only_use_keep_alive_inside_keep_alive
|
||||
final containerId = ref.read(selectedContainerProvider);
|
||||
await db.tabDao.upsertUnassignedTab(
|
||||
tabId,
|
||||
parentId: const Value.absent(),
|
||||
containerId: Value(containerId),
|
||||
isPrivate: const Value.absent(),
|
||||
);
|
||||
if (await db.tabDao.getTabDataById(tabId).getSingleOrNull() == null) {
|
||||
// ignore: only_use_keep_alive_inside_keep_alive
|
||||
final containerId = ref.read(selectedContainerProvider);
|
||||
await db.tabDao.insertTab(
|
||||
tabId,
|
||||
parentId: const Value.absent(),
|
||||
containerId: Value(containerId),
|
||||
isPrivate: const Value.absent(),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
final containerSiteAssignementSub = eventSerivce.siteAssignementEvent.listen((
|
||||
@@ -407,7 +442,7 @@ class TabRepository extends _$TabRepository {
|
||||
|
||||
if (containerData != null) {
|
||||
final tabIsEmpty =
|
||||
tabState.url == TabState.$default(tabState.id).url &&
|
||||
tabState.url == TabState.defaultUrl &&
|
||||
tabState.historyState.items.isEmpty;
|
||||
|
||||
if (event.blocked || tabIsEmpty) {
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabRepositoryHash() => r'0411e8b3fa9c3e344106f8fa8178bd6eb613309a';
|
||||
String _$tabRepositoryHash() => r'de20adb4a38f8cd443be7d2f4ea07eded58803a3';
|
||||
|
||||
abstract class _$TabRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -59,6 +59,10 @@ class BrowserDataService extends _$BrowserDataService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearDataForContext(String contextId) {
|
||||
return _service.clearDataForContext(contextId);
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ final class BrowserDataServiceProvider
|
||||
}
|
||||
|
||||
String _$browserDataServiceHash() =>
|
||||
r'0a00db5b143d3851f2c171f4f939940f959b67bb';
|
||||
r'502dff526bcf7c10c218d2d9fa2cd0f41ad25622';
|
||||
|
||||
abstract class _$BrowserDataService extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -196,13 +196,20 @@ class TabMenu extends HookConsumerWidget {
|
||||
onPressed: () async {
|
||||
final tabState = ref.read(tabStateProvider(selectedTabId))!;
|
||||
|
||||
final tabId = await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: false,
|
||||
selectTab: false,
|
||||
);
|
||||
final tabId = (tabState.isPrivate)
|
||||
? await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: false,
|
||||
selectTab: false,
|
||||
)
|
||||
: await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(
|
||||
selectTabId: selectedTabId,
|
||||
containerId: tabState.contextId,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
//save reference before pop `ref` gets disposed
|
||||
@@ -223,13 +230,20 @@ class TabMenu extends HookConsumerWidget {
|
||||
onPressed: () async {
|
||||
final tabState = ref.read(tabStateProvider(selectedTabId))!;
|
||||
|
||||
final tabId = await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: true,
|
||||
selectTab: false,
|
||||
);
|
||||
final tabId = (!tabState.isPrivate)
|
||||
? await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: true,
|
||||
selectTab: false,
|
||||
)
|
||||
: await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(
|
||||
selectTabId: selectedTabId,
|
||||
containerId: tabState.contextId,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
//save reference before pop `ref` gets disposed
|
||||
|
||||
+5
-24
@@ -24,6 +24,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/states/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/widgets/tab_icon.dart';
|
||||
@@ -95,10 +96,8 @@ class GridTabPreview extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tabState = ref.watch(tabStateProvider(tabId));
|
||||
if (tabState == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final tabState =
|
||||
ref.watch(tabStateProvider(tabId)) ?? TabState.$default(tabId);
|
||||
|
||||
final extendedDeleteMenuController = useMenuController();
|
||||
|
||||
@@ -255,10 +254,8 @@ class ListTabPreview extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
final tabState = ref.watch(tabStateProvider(tabId));
|
||||
if (tabState == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final tabState =
|
||||
ref.watch(tabStateProvider(tabId)) ?? TabState.$default(tabId);
|
||||
|
||||
final extendedDeleteMenuController = useMenuController();
|
||||
|
||||
@@ -388,14 +385,6 @@ class SingleGridTabPreview extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final hasTabState = ref.watch(
|
||||
tabStateProvider(tabId).select((value) => value != null),
|
||||
);
|
||||
|
||||
if (!hasTabState) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final dragStartPosition = useRef(Offset.zero);
|
||||
final draggedDistance = useState(0.0);
|
||||
|
||||
@@ -512,14 +501,6 @@ class SingleListTabPreview extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final hasTabState = ref.watch(
|
||||
tabStateProvider(tabId).select((value) => value != null),
|
||||
);
|
||||
|
||||
if (!hasTabState) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final dragStartPosition = useRef(Offset.zero);
|
||||
final draggedDistance = useState(0.0);
|
||||
|
||||
|
||||
+178
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart' show Value;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
@@ -8,6 +9,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_data.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/presentation/controllers/tab_view_controllers.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
@@ -381,6 +383,182 @@ class TabViewHeader extends HookConsumerWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final selectedContainer = ref.watch(
|
||||
selectedContainerDataProvider.select(
|
||||
(value) => value.value,
|
||||
),
|
||||
);
|
||||
|
||||
// Only show if container has cookie isolation
|
||||
if (selectedContainer
|
||||
?.metadata
|
||||
.contextualIdentity ==
|
||||
null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Divider(),
|
||||
MenuItemButton(
|
||||
closeOnActivate: false,
|
||||
leadingIcon: const Icon(
|
||||
Icons.cleaning_services,
|
||||
),
|
||||
child: const Text('Clear Container Data'),
|
||||
onPressed: () async {
|
||||
final containerId = selectedContainer!.id;
|
||||
final tabs = await ref
|
||||
.read(
|
||||
tabDataRepositoryProvider.notifier,
|
||||
)
|
||||
.getContainerTabsData(containerId);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
final result = await showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(
|
||||
Icons.cleaning_services,
|
||||
),
|
||||
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(
|
||||
'${tabs.length} 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'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
try {
|
||||
await ref
|
||||
.read(
|
||||
tabDataRepositoryProvider
|
||||
.notifier,
|
||||
)
|
||||
.closeContainerTabs(containerId);
|
||||
|
||||
await ref
|
||||
.read(
|
||||
browserDataServiceProvider
|
||||
.notifier,
|
||||
)
|
||||
.clearDataForContext(
|
||||
selectedContainer
|
||||
.metadata
|
||||
.contextualIdentity!,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(
|
||||
tabRepositoryProvider.notifier,
|
||||
)
|
||||
.addMultipleTabs(
|
||||
tabs: tabs
|
||||
.map(
|
||||
(tab) => AddTabParams(
|
||||
url: tab.url.toString(),
|
||||
startLoading: true,
|
||||
parentId: tab.parentId,
|
||||
private:
|
||||
tab.isPrivate ??
|
||||
false,
|
||||
flags: LoadUrlFlags.NONE
|
||||
.toValue(),
|
||||
source: Internal.newTab
|
||||
.toValue(),
|
||||
contextId: selectedContainer
|
||||
.metadata
|
||||
.contextualIdentity,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
container: Value(
|
||||
selectedContainer,
|
||||
),
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Container data cleared successfully',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Error clearing data: $e',
|
||||
),
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
MenuController.maybeOf(context)?.close();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
|
||||
@@ -103,12 +103,14 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> upsertContainerTabTransactional(
|
||||
Future<String> upsertTabTransactional(
|
||||
Future<String> Function() createTab, {
|
||||
required Value<bool?> isPrivate,
|
||||
required Value<String?> parentId,
|
||||
Value<String?> containerId = const Value.absent(),
|
||||
Value<String?> orderKey = const Value.absent(),
|
||||
Value<Uri?> url = const Value.absent(),
|
||||
Value<String?> title = const Value.absent(),
|
||||
}) {
|
||||
return db.transaction(() async {
|
||||
final tabId = await createTab();
|
||||
@@ -122,6 +124,8 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
parentId: parentId,
|
||||
timestamp: DateTime.now(),
|
||||
containerId: containerId,
|
||||
url: url,
|
||||
title: title,
|
||||
isPrivate: isPrivate,
|
||||
orderKey: currentOrderKey,
|
||||
),
|
||||
@@ -130,6 +134,8 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
parentId: parentId,
|
||||
containerId: containerId,
|
||||
orderKey: Value.absentIfNull(orderKey.value),
|
||||
url: url,
|
||||
title: title,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -139,12 +145,14 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
}
|
||||
|
||||
//Upsert an tab only if there is no container assigned yet
|
||||
Future<String> upsertUnassignedTab(
|
||||
Future<String> insertTab(
|
||||
String tabId, {
|
||||
required Value<bool?> isPrivate,
|
||||
required Value<String?> parentId,
|
||||
Value<String?> containerId = const Value.absent(),
|
||||
Value<String?> orderKey = const Value.absent(),
|
||||
Value<Uri?> url = const Value.absent(),
|
||||
Value<String?> title = const Value.absent(),
|
||||
}) {
|
||||
return db.transaction(() async {
|
||||
final currentOrderKey =
|
||||
@@ -159,6 +167,8 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
containerId: containerId,
|
||||
orderKey: currentOrderKey,
|
||||
isPrivate: isPrivate,
|
||||
url: url,
|
||||
title: title,
|
||||
),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
);
|
||||
@@ -218,7 +228,9 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
db.tab,
|
||||
TabCompanion(
|
||||
parentId: (previousState?.parentId != state.parentId)
|
||||
? Value(state.parentId)
|
||||
? Value(
|
||||
next.containsKey(state.parentId) ? state.parentId : null,
|
||||
)
|
||||
: const Value.absent(),
|
||||
url: (previousState?.url != state.url)
|
||||
? Value(state.url)
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/providers/tab_state.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||
@@ -49,21 +51,53 @@ class TabDataRepository extends _$TabDataRepository {
|
||||
.tabDao
|
||||
.assignContainer(tabId, containerId: targetContainer.id);
|
||||
} else {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.duplicateTab(selectTabId: tabId, containerId: targetContainer.id);
|
||||
final tabState = ref.read(tabStateProvider(tabId));
|
||||
if (tabState != null) {
|
||||
if (closeOldTab) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||
}
|
||||
|
||||
if (closeOldTab) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: tabState.isPrivate,
|
||||
container: Value(targetContainer),
|
||||
parentId: tabState.parentId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> unassignContainer(String tabId) {
|
||||
return ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.assignContainer(tabId, containerId: null);
|
||||
Future<void> unassignContainer(String tabId) async {
|
||||
final currentContainerId = await getTabContainerId(tabId);
|
||||
|
||||
final currentContainerData = await currentContainerId.mapNotNull(
|
||||
(containerId) => ref
|
||||
.read(containerRepositoryProvider.notifier)
|
||||
.getContainerData(containerId),
|
||||
);
|
||||
|
||||
if (currentContainerData?.metadata.contextualIdentity == null) {
|
||||
return ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.assignContainer(tabId, containerId: null);
|
||||
} else {
|
||||
final tabState = ref.read(tabStateProvider(tabId));
|
||||
if (tabState != null) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTab(tabId);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: tabState.url,
|
||||
private: tabState.isPrivate,
|
||||
container: const Value(null),
|
||||
parentId: tabState.parentId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignOrderKey(String tabId, String orderKey) {
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabDataRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabDataRepositoryHash() => r'63ab2765ea5be640d6c6a596852fee0df5a958e4';
|
||||
String _$tabDataRepositoryHash() => r'eab2a5040541fec955ffe23947cbb57952d29c6c';
|
||||
|
||||
abstract class _$TabDataRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -121,7 +121,7 @@ class WebEngineSettingsScreen extends HookConsumerWidget {
|
||||
vertical: 8.0,
|
||||
horizontal: 16.0,
|
||||
),
|
||||
leading: const Icon(MdiIcons.delete),
|
||||
leading: const Icon(Icons.cleaning_services),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
await showDialog(
|
||||
|
||||
Reference in New Issue
Block a user