Skip to content

Commit

Permalink
new: add exit dialog when press close button
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Aug 4, 2024
1 parent f54fe79 commit a392fe1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
5 changes: 5 additions & 0 deletions assets/translations/strings_en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,10 @@
"warpNoiseSize": "Noise Size",
"warpNoiseMode": "Noise Mode",
"warpNoiseDelay": "Noise Delay"
},
"window":{
"hide": "Hide",
"close": "Exit",
"alertMessage":"Hide or Exit the application?"
}
}
2 changes: 1 addition & 1 deletion dependencies.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
core.version=2.1.2
core.version=2.1.4
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SystemTrayNotifier extends _$SystemTrayNotifier with AppLogger {
// SystemTrayNotifier.setIcon(timeout ? Disconnecting() : Connecting());
} else {
setIcon(const Disconnecting());
tooltip = "${tooltip} - ${connection.present(t)}";
tooltip = "$tooltip - ${connection.present(t)}";
}
if (Platform.isMacOS) {
windowManager.setBadgeLabel("${delay}ms");
Expand Down
8 changes: 3 additions & 5 deletions lib/features/window/notifier/window_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand Down Expand Up @@ -45,11 +47,7 @@ class WindowNotifier extends _$WindowNotifier with AppLogger {
}

Future<void> quit() async {
await ref
.read(connectionNotifierProvider.notifier)
.abortConnection()
.timeout(const Duration(seconds: 2))
.catchError(
await ref.read(connectionNotifierProvider.notifier).abortConnection().timeout(const Duration(seconds: 2)).catchError(
(e) {
loggy.warning("error aborting connection on quit", e);
},
Expand Down
34 changes: 31 additions & 3 deletions lib/features/window/widget/window_wrapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:hiddify/core/localization/translations.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/utils/custom_loggers.dart';
import 'package:hiddify/utils/platform_utils.dart';
Expand All @@ -16,8 +19,9 @@ class WindowWrapper extends StatefulHookConsumerWidget {
ConsumerState<ConsumerStatefulWidget> createState() => _WindowWrapperState();
}

class _WindowWrapperState extends ConsumerState<WindowWrapper>
with WindowListener, AppLogger {
class _WindowWrapperState extends ConsumerState<WindowWrapper> with WindowListener, AppLogger {
late AlertDialog closeDialog;

@override
Widget build(BuildContext context) {
ref.watch(windowNotifierProvider);
Expand All @@ -44,7 +48,31 @@ class _WindowWrapperState extends ConsumerState<WindowWrapper>

@override
Future<void> onWindowClose() async {
await ref.read(windowNotifierProvider.notifier).close();
if (RootScaffold.stateKey.currentContext == null) {
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()),
),
],
),
);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion libcore

0 comments on commit a392fe1

Please sign in to comment.