-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1382 from TheLastFlame/main
Remembering window closing action
- Loading branch information
Showing
9 changed files
with
222 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,6 @@ app.*.map.json | |
/android/app/debug | ||
/android/app/profile | ||
/android/app/release | ||
|
||
|
||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.