add setting to auto clear unassigned tabs after duration
This commit is contained in:
+11
@@ -47,6 +47,7 @@ import 'package:weblibre/features/geckoview/features/browser/domain/services/pro
|
||||
import 'package:weblibre/features/geckoview/features/history/domain/repositories/history.dart';
|
||||
import 'package:weblibre/features/geckoview/features/preferences/data/repositories/preference_observer.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/container.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/share_intent/domain/entities/shared_content.dart';
|
||||
import 'package:weblibre/features/user/data/models/general_settings.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/cache.dart';
|
||||
@@ -117,6 +118,16 @@ class _BrowserViewState extends ConsumerState<BrowserView>
|
||||
DateTime.now().subtract(settings.historyAutoCleanInterval),
|
||||
);
|
||||
}
|
||||
|
||||
if (settings.unassignedTabsAutoCleanInterval > Duration.zero) {
|
||||
await ref
|
||||
.read(tabDataRepositoryProvider.notifier)
|
||||
.deleteUnassignedTabsOlderThan(
|
||||
DateTime.now().subtract(
|
||||
settings.unassignedTabsAutoCleanInterval,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Clear data for containers with clearDataOnExit enabled
|
||||
|
||||
-1
@@ -33,7 +33,6 @@ import 'package:weblibre/features/geckoview/features/find_in_page/domain/entitie
|
||||
import 'package:weblibre/features/geckoview/features/find_in_page/presentation/controllers/find_in_page.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
||||
import 'package:weblibre/presentation/widgets/non_focusable.dart';
|
||||
import 'package:weblibre/presentation/widgets/uri_breadcrumb.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
||||
|
||||
|
||||
@@ -387,4 +387,15 @@ class TabDao extends DatabaseAccessor<TabDatabase> with $TabDaoMixin {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> getUnassignedTabsOlderThan(DateTime threshold) {
|
||||
final query = selectOnly(db.tab)
|
||||
..addColumns([db.tab.id])
|
||||
..where(
|
||||
db.tab.containerId.isNull() &
|
||||
db.tab.timestamp.isSmallerThanValue(threshold),
|
||||
);
|
||||
|
||||
return query.map((row) => row.read(db.tab.id)!).get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +210,19 @@ class TabDataRepository extends _$TabDataRepository {
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> deleteUnassignedTabsOlderThan(DateTime threshold) async {
|
||||
final tabIds = await ref
|
||||
.read(tabDatabaseProvider)
|
||||
.tabDao
|
||||
.getUnassignedTabsOlderThan(threshold);
|
||||
|
||||
if (tabIds.isNotEmpty) {
|
||||
await ref.read(tabRepositoryProvider.notifier).closeTabs(tabIds);
|
||||
}
|
||||
|
||||
return tabIds.length;
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ final class TabDataRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$tabDataRepositoryHash() => r'a01c38e94aad2145bd26aa0b8ff0bb1bcceb22f5';
|
||||
String _$tabDataRepositoryHash() => r'c3632e0a2d91811103b329659cb0c6d778b14cea';
|
||||
|
||||
abstract class _$TabDataRepository extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
Reference in New Issue
Block a user