added setting to disable double back to close tab
This commit is contained in:
@@ -569,6 +569,10 @@ class _Browser extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final doubleBackCloseTab = ref.watch(
|
||||
generalSettingsWithDefaultsProvider.select((s) => s.doubleBackCloseTab),
|
||||
);
|
||||
|
||||
final lastBackButtonPress = useRef<DateTime?>(null);
|
||||
|
||||
final overlayBuilder = ref.watch(overlayControllerProvider);
|
||||
@@ -682,39 +686,44 @@ class _Browser extends HookConsumerWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lastBackButtonPress.value != null &&
|
||||
DateTime.now().difference(lastBackButtonPress.value!) <
|
||||
_backButtonPressTimeout) {
|
||||
lastBackButtonPress.value = null;
|
||||
// Handle double back to close (if enabled)
|
||||
if (doubleBackCloseTab) {
|
||||
if (lastBackButtonPress.value != null &&
|
||||
DateTime.now().difference(lastBackButtonPress.value!) <
|
||||
_backButtonPressTimeout) {
|
||||
lastBackButtonPress.value = null;
|
||||
|
||||
if (tabState != null && tabCount > 1) {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(tabState.id);
|
||||
if (tabState != null && tabCount > 1) {
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.closeTab(tabState.id);
|
||||
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
);
|
||||
if (context.mounted) {
|
||||
ui_helper.showTabUndoClose(
|
||||
context,
|
||||
ref.read(tabRepositoryProvider.notifier).undoClose,
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//Mark back as unhandled and navigator will pop
|
||||
await SystemNavigator.pop();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
lastBackButtonPress.value = DateTime.now();
|
||||
ui_helper.showTabBackButtonMessage(
|
||||
context,
|
||||
tabCount,
|
||||
_backButtonPressTimeout,
|
||||
);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//Mark back as unhandled and navigator will pop
|
||||
await SystemNavigator.pop();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
lastBackButtonPress.value = DateTime.now();
|
||||
ui_helper.showTabBackButtonMessage(
|
||||
context,
|
||||
tabCount,
|
||||
_backButtonPressTimeout,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
child: _BrowserView(
|
||||
isFullscreen: tabInFullScreen,
|
||||
|
||||
@@ -67,6 +67,7 @@ class GeneralSettingsScreen extends StatelessWidget {
|
||||
_BottomSheetTabViewTile(),
|
||||
_TabBarSwipeBehaviorSection(),
|
||||
_PullToRefreshTile(),
|
||||
_DoubleBackCloseTabTile(),
|
||||
_IconCacheTile(),
|
||||
],
|
||||
);
|
||||
@@ -867,6 +868,34 @@ class _PullToRefreshTile extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _DoubleBackCloseTabTile extends HookConsumerWidget {
|
||||
const _DoubleBackCloseTabTile();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final doubleBackCloseTab = ref.watch(
|
||||
generalSettingsWithDefaultsProvider.select((s) => s.doubleBackCloseTab),
|
||||
);
|
||||
|
||||
return SwitchListTile.adaptive(
|
||||
title: const Text('Double Back to Close Tab'),
|
||||
subtitle: const Text(
|
||||
'When enabled, press back twice to close the tab. When disabled, back button only navigates page history.',
|
||||
),
|
||||
secondary: const Icon(MdiIcons.gestureDoubleTap),
|
||||
value: doubleBackCloseTab,
|
||||
onChanged: (value) async {
|
||||
await ref
|
||||
.read(saveGeneralSettingsControllerProvider.notifier)
|
||||
.save(
|
||||
(currentSettings) =>
|
||||
currentSettings.copyWith.doubleBackCloseTab(value),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _IconCacheTile extends HookConsumerWidget {
|
||||
const _IconCacheTile();
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ class GeneralSettings with FastEquatable {
|
||||
final TabBarPosition tabBarPosition;
|
||||
final QuickTabSwitcherMode quickTabSwitcherMode;
|
||||
final bool pullToRefreshEnabled;
|
||||
final bool doubleBackCloseTab;
|
||||
|
||||
GeneralSettings({
|
||||
required this.themeMode,
|
||||
@@ -104,6 +105,7 @@ class GeneralSettings with FastEquatable {
|
||||
required this.tabBarPosition,
|
||||
required this.quickTabSwitcherMode,
|
||||
required this.pullToRefreshEnabled,
|
||||
required this.doubleBackCloseTab,
|
||||
});
|
||||
|
||||
GeneralSettings.withDefaults({
|
||||
@@ -128,6 +130,7 @@ class GeneralSettings with FastEquatable {
|
||||
TabBarPosition? tabBarPosition,
|
||||
QuickTabSwitcherMode? quickTabSwitcherMode,
|
||||
bool? pullToRefreshEnabled,
|
||||
bool? doubleBackCloseTab,
|
||||
}) : themeMode = themeMode ?? ThemeMode.dark,
|
||||
enableReadability = enableReadability ?? true,
|
||||
enforceReadability = enforceReadability ?? false,
|
||||
@@ -151,7 +154,8 @@ class GeneralSettings with FastEquatable {
|
||||
tabBarPosition = tabBarPosition ?? TabBarPosition.bottom,
|
||||
quickTabSwitcherMode =
|
||||
quickTabSwitcherMode ?? QuickTabSwitcherMode.lastUsedTabs,
|
||||
pullToRefreshEnabled = pullToRefreshEnabled ?? true;
|
||||
pullToRefreshEnabled = pullToRefreshEnabled ?? true,
|
||||
doubleBackCloseTab = doubleBackCloseTab ?? true;
|
||||
|
||||
factory GeneralSettings.fromJson(Map<String, dynamic> json) =>
|
||||
_$GeneralSettingsFromJson(json);
|
||||
@@ -181,5 +185,6 @@ class GeneralSettings with FastEquatable {
|
||||
tabBarPosition,
|
||||
quickTabSwitcherMode,
|
||||
pullToRefreshEnabled,
|
||||
doubleBackCloseTab,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ abstract class _$GeneralSettingsCWProxy {
|
||||
|
||||
GeneralSettings pullToRefreshEnabled(bool pullToRefreshEnabled);
|
||||
|
||||
GeneralSettings doubleBackCloseTab(bool doubleBackCloseTab);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `GeneralSettings(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
@@ -88,6 +90,7 @@ abstract class _$GeneralSettingsCWProxy {
|
||||
TabBarPosition tabBarPosition,
|
||||
QuickTabSwitcherMode quickTabSwitcherMode,
|
||||
bool pullToRefreshEnabled,
|
||||
bool doubleBackCloseTab,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -186,6 +189,10 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
GeneralSettings pullToRefreshEnabled(bool pullToRefreshEnabled) =>
|
||||
call(pullToRefreshEnabled: pullToRefreshEnabled);
|
||||
|
||||
@override
|
||||
GeneralSettings doubleBackCloseTab(bool doubleBackCloseTab) =>
|
||||
call(doubleBackCloseTab: doubleBackCloseTab);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `GeneralSettings(...).copyWith.fieldName(value)`.
|
||||
@@ -216,6 +223,7 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
Object? tabBarPosition = const $CopyWithPlaceholder(),
|
||||
Object? quickTabSwitcherMode = const $CopyWithPlaceholder(),
|
||||
Object? pullToRefreshEnabled = const $CopyWithPlaceholder(),
|
||||
Object? doubleBackCloseTab = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return GeneralSettings(
|
||||
themeMode: themeMode == const $CopyWithPlaceholder() || themeMode == null
|
||||
@@ -340,6 +348,12 @@ class _$GeneralSettingsCWProxyImpl implements _$GeneralSettingsCWProxy {
|
||||
? _value.pullToRefreshEnabled
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: pullToRefreshEnabled as bool,
|
||||
doubleBackCloseTab:
|
||||
doubleBackCloseTab == const $CopyWithPlaceholder() ||
|
||||
doubleBackCloseTab == null
|
||||
? _value.doubleBackCloseTab
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: doubleBackCloseTab as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -405,6 +419,7 @@ GeneralSettings _$GeneralSettingsFromJson(
|
||||
json['quickTabSwitcherMode'],
|
||||
),
|
||||
pullToRefreshEnabled: json['pullToRefreshEnabled'] as bool?,
|
||||
doubleBackCloseTab: json['doubleBackCloseTab'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GeneralSettingsToJson(
|
||||
@@ -439,6 +454,7 @@ Map<String, dynamic> _$GeneralSettingsToJson(
|
||||
'quickTabSwitcherMode':
|
||||
_$QuickTabSwitcherModeEnumMap[instance.quickTabSwitcherMode]!,
|
||||
'pullToRefreshEnabled': instance.pullToRefreshEnabled,
|
||||
'doubleBackCloseTab': instance.doubleBackCloseTab,
|
||||
};
|
||||
|
||||
const _$ThemeModeEnumMap = {
|
||||
|
||||
@@ -126,6 +126,10 @@ class GeneralSettingsRepository extends _$GeneralSettingsRepository {
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
'doubleBackCloseTab': settings['doubleBackCloseTab']?.readAs(
|
||||
DriftSqlType.bool,
|
||||
db.typeMapping,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ final class GeneralSettingsRepositoryProvider
|
||||
}
|
||||
|
||||
String _$generalSettingsRepositoryHash() =>
|
||||
r'dceccac3a93e96907c7bd2b4c58f5021912553ac';
|
||||
r'ada58479ceea436f08e22780be200c99e3abedb7';
|
||||
|
||||
abstract class _$GeneralSettingsRepository
|
||||
extends $StreamNotifier<GeneralSettings> {
|
||||
|
||||
Reference in New Issue
Block a user