feat: add action options for closing the application
This commit is contained in:
@@ -199,7 +199,13 @@
|
|||||||
"ignoreBatteryOptimizationsMsg": "Remove Restrictions For Optimal VPN Performance",
|
"ignoreBatteryOptimizationsMsg": "Remove Restrictions For Optimal VPN Performance",
|
||||||
"dynamicNotification": "Display Speed in Notification",
|
"dynamicNotification": "Display Speed in Notification",
|
||||||
"hapticFeedback": "Haptic Feedback",
|
"hapticFeedback": "Haptic Feedback",
|
||||||
"autoIpCheck": "Automatically Check Connection IP"
|
"autoIpCheck": "Automatically Check Connection IP",
|
||||||
|
"actionAtClosing": "Action at closing",
|
||||||
|
"actionsAtClosing": {
|
||||||
|
"askEachTime": "Ask each time",
|
||||||
|
"hide": "Hide",
|
||||||
|
"exit": "Exit"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "Advanced",
|
"sectionTitle": "Advanced",
|
||||||
@@ -425,6 +431,7 @@
|
|||||||
"window": {
|
"window": {
|
||||||
"hide": "Hide",
|
"hide": "Hide",
|
||||||
"close": "Exit",
|
"close": "Exit",
|
||||||
"alertMessage": "Hide or Exit the application?"
|
"alertMessage": "Hide or Exit the application?",
|
||||||
|
"remember": "Remember my choice"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,13 @@
|
|||||||
"ignoreBatteryOptimizationsMsg": "Отключение ограничений для оптимальной производительности VPN",
|
"ignoreBatteryOptimizationsMsg": "Отключение ограничений для оптимальной производительности VPN",
|
||||||
"dynamicNotification": "Отображение скорости в уведомлении",
|
"dynamicNotification": "Отображение скорости в уведомлении",
|
||||||
"hapticFeedback": "Тактильная обратная связь",
|
"hapticFeedback": "Тактильная обратная связь",
|
||||||
"autoIpCheck": "Автоматически проверять IP-адрес соединения"
|
"autoIpCheck": "Автоматически проверять IP-адрес соединения",
|
||||||
|
"actionAtClosing": "Действие при закрытии",
|
||||||
|
"actionsAtClosing": {
|
||||||
|
"askEachTime": "Каждый раз спрашивать",
|
||||||
|
"hide": "Скрыть",
|
||||||
|
"exit": "Выйти"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"advanced": {
|
"advanced": {
|
||||||
"sectionTitle": "Расширенные",
|
"sectionTitle": "Расширенные",
|
||||||
@@ -425,6 +431,7 @@
|
|||||||
"window": {
|
"window": {
|
||||||
"hide": "Скрыть",
|
"hide": "Скрыть",
|
||||||
"close": "Закрыть",
|
"close": "Закрыть",
|
||||||
"alertMessage": "Скрыть или выйти из приложения?"
|
"alertMessage": "Скрыть приложение или выйти?",
|
||||||
|
"remember": "Запомнить выбор"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
lib/core/preferences/actions_at_closing.dart
Normal file
13
lib/core/preferences/actions_at_closing.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import 'package:hiddify/gen/translations.g.dart';
|
||||||
|
|
||||||
|
enum ActionsAtClosing {
|
||||||
|
ask,
|
||||||
|
hide,
|
||||||
|
exit;
|
||||||
|
|
||||||
|
String present(TranslationsEn t) => switch (this) {
|
||||||
|
ask => t.settings.general.actionsAtClosing.askEachTime,
|
||||||
|
hide => t.settings.general.actionsAtClosing.hide,
|
||||||
|
exit => t.settings.general.actionsAtClosing.exit,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hiddify/core/app_info/app_info_provider.dart';
|
import 'package:hiddify/core/app_info/app_info_provider.dart';
|
||||||
import 'package:hiddify/core/model/environment.dart';
|
import 'package:hiddify/core/model/environment.dart';
|
||||||
|
import 'package:hiddify/core/preferences/actions_at_closing.dart';
|
||||||
// import 'package:hiddify/core/model/region.dart';
|
// import 'package:hiddify/core/model/region.dart';
|
||||||
import 'package:hiddify/core/preferences/preferences_provider.dart';
|
import 'package:hiddify/core/preferences/preferences_provider.dart';
|
||||||
import 'package:hiddify/core/utils/preferences_utils.dart';
|
import 'package:hiddify/core/utils/preferences_utils.dart';
|
||||||
@@ -61,6 +62,13 @@ abstract class Preferences {
|
|||||||
"store_reviewed_by_user",
|
"store_reviewed_by_user",
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static final actionAtClose = PreferencesNotifier.create<ActionsAtClosing, String>(
|
||||||
|
"action_at_close",
|
||||||
|
ActionsAtClosing.ask,
|
||||||
|
mapFrom: ActionsAtClosing.values.byName,
|
||||||
|
mapTo: (value) => value.name,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Riverpod(keepAlive: true)
|
@Riverpod(keepAlive: true)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import 'package:hiddify/core/localization/locale_extensions.dart';
|
|||||||
import 'package:hiddify/core/localization/locale_preferences.dart';
|
import 'package:hiddify/core/localization/locale_preferences.dart';
|
||||||
import 'package:hiddify/core/localization/translations.dart';
|
import 'package:hiddify/core/localization/translations.dart';
|
||||||
import 'package:hiddify/core/model/region.dart';
|
import 'package:hiddify/core/model/region.dart';
|
||||||
|
import 'package:hiddify/core/preferences/actions_at_closing.dart';
|
||||||
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||||
import 'package:hiddify/core/theme/app_theme_mode.dart';
|
import 'package:hiddify/core/theme/app_theme_mode.dart';
|
||||||
import 'package:hiddify/core/theme/theme_preferences.dart';
|
import 'package:hiddify/core/theme/theme_preferences.dart';
|
||||||
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
|
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
|
||||||
@@ -177,3 +179,43 @@ class ThemeModePrefTile extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClosingPrefTile extends ConsumerWidget {
|
||||||
|
const ClosingPrefTile({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final t = ref.watch(translationsProvider);
|
||||||
|
|
||||||
|
final action = ref.watch(Preferences.actionAtClose);
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Text(t.settings.general.actionAtClosing),
|
||||||
|
subtitle: Text(action.present(t)),
|
||||||
|
leading: const Icon(FluentIcons.arrow_exit_20_regular),
|
||||||
|
onTap: () async {
|
||||||
|
final selectedAction = await showDialog<ActionsAtClosing>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text(t.settings.general.actionAtClosing),
|
||||||
|
children: ActionsAtClosing.values
|
||||||
|
.map(
|
||||||
|
(e) => RadioListTile(
|
||||||
|
title: Text(e.present(t)),
|
||||||
|
value: e,
|
||||||
|
groupValue: action,
|
||||||
|
onChanged: Navigator.of(context).maybePop,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (selectedAction != null) {
|
||||||
|
await ref.read(Preferences.actionAtClose.notifier).update(selectedAction);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:hiddify/core/haptic/haptic_service.dart';
|
import 'package:hiddify/core/haptic/haptic_service.dart';
|
||||||
import 'package:hiddify/core/localization/translations.dart';
|
import 'package:hiddify/core/localization/translations.dart';
|
||||||
import 'package:hiddify/core/preferences/general_preferences.dart';
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||||
import 'package:hiddify/core/theme/app_theme_mode.dart';
|
|
||||||
import 'package:hiddify/core/theme/theme_preferences.dart';
|
|
||||||
import 'package:hiddify/features/auto_start/notifier/auto_start_notifier.dart';
|
import 'package:hiddify/features/auto_start/notifier/auto_start_notifier.dart';
|
||||||
import 'package:hiddify/features/common/general_pref_tiles.dart';
|
import 'package:hiddify/features/common/general_pref_tiles.dart';
|
||||||
import 'package:hiddify/utils/utils.dart';
|
import 'package:hiddify/utils/utils.dart';
|
||||||
@@ -47,6 +45,7 @@ class GeneralSettingTiles extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (PlatformUtils.isDesktop) ...[
|
if (PlatformUtils.isDesktop) ...[
|
||||||
|
const ClosingPrefTile(),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(t.settings.general.autoStart),
|
title: Text(t.settings.general.autoStart),
|
||||||
value: ref.watch(autoStartNotifierProvider).asData!.value,
|
value: ref.watch(autoStartNotifierProvider).asData!.value,
|
||||||
|
|||||||
69
lib/features/window/widget/window_closing_dialog.dart
Normal file
69
lib/features/window/widget/window_closing_dialog.dart
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hiddify/core/localization/translations.dart';
|
||||||
|
import 'package:hiddify/core/preferences/actions_at_closing.dart';
|
||||||
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||||
|
import 'package:hiddify/features/window/notifier/window_notifier.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
|
class WindowClosingDialog extends ConsumerStatefulWidget {
|
||||||
|
const WindowClosingDialog({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<WindowClosingDialog> createState() => _WindowClosingDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _WindowClosingDialogState extends ConsumerState<WindowClosingDialog> {
|
||||||
|
bool remember = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final t = ref.watch(translationsProvider);
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(t.window.alertMessage),
|
||||||
|
content: GestureDetector(
|
||||||
|
onTap: () => setState(() {
|
||||||
|
remember = !remember;
|
||||||
|
}),
|
||||||
|
behavior: HitTestBehavior.translucent,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Checkbox(
|
||||||
|
value: remember,
|
||||||
|
onChanged: (v) {
|
||||||
|
remember = v ?? remember;
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
t.window.remember,
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (remember) {
|
||||||
|
ref.read(Preferences.actionAtClose.notifier).update(ActionsAtClosing.exit);
|
||||||
|
}
|
||||||
|
ref.read(windowNotifierProvider.notifier).quit();
|
||||||
|
},
|
||||||
|
child: Text(t.window.close),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if (remember) {
|
||||||
|
ref.read(Preferences.actionAtClose.notifier).update(ActionsAtClosing.hide);
|
||||||
|
}
|
||||||
|
Navigator.of(context).maybePop(false);
|
||||||
|
await ref.read(windowNotifierProvider.notifier).close();
|
||||||
|
},
|
||||||
|
child: Text(t.window.hide),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hiddify/core/localization/translations.dart';
|
import 'package:hiddify/core/preferences/actions_at_closing.dart';
|
||||||
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
||||||
import 'package:hiddify/features/common/adaptive_root_scaffold.dart';
|
import 'package:hiddify/features/common/adaptive_root_scaffold.dart';
|
||||||
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
|
|
||||||
import 'package:hiddify/features/window/notifier/window_notifier.dart';
|
import 'package:hiddify/features/window/notifier/window_notifier.dart';
|
||||||
|
import 'package:hiddify/features/window/widget/window_closing_dialog.dart';
|
||||||
import 'package:hiddify/utils/custom_loggers.dart';
|
import 'package:hiddify/utils/custom_loggers.dart';
|
||||||
import 'package:hiddify/utils/platform_utils.dart';
|
import 'package:hiddify/utils/platform_utils.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
@@ -22,6 +23,8 @@ class WindowWrapper extends StatefulHookConsumerWidget {
|
|||||||
class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListener, AppLogger {
|
class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListener, AppLogger {
|
||||||
late AlertDialog closeDialog;
|
late AlertDialog closeDialog;
|
||||||
|
|
||||||
|
bool isWindowClosingDialogOpened = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
ref.watch(windowNotifierProvider);
|
ref.watch(windowNotifierProvider);
|
||||||
@@ -52,27 +55,23 @@ class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListen
|
|||||||
await ref.read(windowNotifierProvider.notifier).close();
|
await ref.read(windowNotifierProvider.notifier).close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final t = ref.watch(translationsProvider);
|
|
||||||
|
|
||||||
await showDialog(
|
switch (ref.read(Preferences.actionAtClose)) {
|
||||||
context: RootScaffold.stateKey.currentContext!,
|
case ActionsAtClosing.ask:
|
||||||
builder: (BuildContext context) => AlertDialog(
|
if (isWindowClosingDialogOpened) return;
|
||||||
title: Text(t.window.alertMessage),
|
isWindowClosingDialogOpened = true;
|
||||||
actions: [
|
await showDialog(
|
||||||
TextButton(
|
context: RootScaffold.stateKey.currentContext!,
|
||||||
onPressed: () async => await ref.read(windowNotifierProvider.notifier).quit(),
|
builder: (BuildContext context) => const WindowClosingDialog(),
|
||||||
child: Text(t.window.close.toUpperCase()),
|
);
|
||||||
),
|
isWindowClosingDialogOpened = false;
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
case ActionsAtClosing.hide:
|
||||||
Navigator.of(context).maybePop(false);
|
await ref.read(windowNotifierProvider.notifier).close();
|
||||||
await ref.read(windowNotifierProvider.notifier).close();
|
|
||||||
},
|
case ActionsAtClosing.exit:
|
||||||
child: Text(t.window.hide.toUpperCase()),
|
await ref.read(windowNotifierProvider.notifier).quit();
|
||||||
),
|
}
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user