feat: add action options for closing the application
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
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/connection/notifier/connection_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/platform_utils.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -22,6 +23,8 @@ class WindowWrapper extends StatefulHookConsumerWidget {
|
||||
class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListener, AppLogger {
|
||||
late AlertDialog closeDialog;
|
||||
|
||||
bool isWindowClosingDialogOpened = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.watch(windowNotifierProvider);
|
||||
@@ -52,27 +55,23 @@ class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListen
|
||||
await ref.read(windowNotifierProvider.notifier).close();
|
||||
return;
|
||||
}
|
||||
final t = ref.watch(translationsProvider);
|
||||
|
||||
await showDialog(
|
||||
context: RootScaffold.stateKey.currentContext!,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text(t.window.alertMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async => await ref.read(windowNotifierProvider.notifier).quit(),
|
||||
child: Text(t.window.close.toUpperCase()),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).maybePop(false);
|
||||
await ref.read(windowNotifierProvider.notifier).close();
|
||||
},
|
||||
child: Text(t.window.hide.toUpperCase()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
switch (ref.read(Preferences.actionAtClose)) {
|
||||
case ActionsAtClosing.ask:
|
||||
if (isWindowClosingDialogOpened) return;
|
||||
isWindowClosingDialogOpened = true;
|
||||
await showDialog(
|
||||
context: RootScaffold.stateKey.currentContext!,
|
||||
builder: (BuildContext context) => const WindowClosingDialog(),
|
||||
);
|
||||
isWindowClosingDialogOpened = false;
|
||||
|
||||
case ActionsAtClosing.hide:
|
||||
await ref.read(windowNotifierProvider.notifier).close();
|
||||
|
||||
case ActionsAtClosing.exit:
|
||||
await ref.read(windowNotifierProvider.notifier).quit();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user