feat: exit alert
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:winui_n2n/edge_state.dart';
|
import 'package:winui_n2n/edge_state.dart';
|
||||||
import 'package:winui_n2n/home_page.dart';
|
import 'package:winui_n2n/home_page.dart';
|
||||||
|
import 'package:winui_n2n/shared_pref_singleton.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
class ApplicationExitControl extends StatefulWidget {
|
class ApplicationExitControl extends StatefulWidget {
|
||||||
const ApplicationExitControl({super.key});
|
const ApplicationExitControl({super.key});
|
||||||
@@ -29,6 +32,68 @@ class _ApplicationExitControlState extends State<ApplicationExitControl> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<AppExitResponse> _handleExitRequest() async {
|
Future<AppExitResponse> _handleExitRequest() async {
|
||||||
|
if (SharedPrefSingleton().minimizeOnQuit == null) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
bool minimize = false;
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.exitAlert),
|
||||||
|
actions: <Widget>[
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
StatefulBuilder(builder:
|
||||||
|
(BuildContext context, StateSetter setState) {
|
||||||
|
return Checkbox(
|
||||||
|
value: minimize,
|
||||||
|
onChanged: (bool? value) {
|
||||||
|
SharedPrefSingleton()
|
||||||
|
.setMinimizeOrNot(value ?? false)
|
||||||
|
.then(
|
||||||
|
(_) {
|
||||||
|
setState(
|
||||||
|
() {
|
||||||
|
minimize = value ?? false;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
Text(AppLocalizations.of(context)!.alwaysMinimize),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
windowManager.hide();
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.minimize),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.exit),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return AppExitResponse.cancel;
|
||||||
|
}
|
||||||
|
|
||||||
if (EdgeState.instance.isRunning && EdgeState.instance.process != null) {
|
if (EdgeState.instance.isRunning && EdgeState.instance.process != null) {
|
||||||
if (EdgeState.instance.process!.kill()) {
|
if (EdgeState.instance.process!.kill()) {
|
||||||
EdgeState.instance.isRunning = false;
|
EdgeState.instance.isRunning = false;
|
||||||
|
@@ -24,5 +24,9 @@
|
|||||||
"successfullyConnected": "Connected",
|
"successfullyConnected": "Connected",
|
||||||
"macOrIpAlreadyInUse": "MAC or IP address already in use or not released yet by supernode",
|
"macOrIpAlreadyInUse": "MAC or IP address already in use or not released yet by supernode",
|
||||||
"otherReasonFail": "Connect fail",
|
"otherReasonFail": "Connect fail",
|
||||||
"clearLog": "Clear log"
|
"clearLog": "Clear log",
|
||||||
|
"exitAlert": "Do you want to exit or minimize?",
|
||||||
|
"alwaysMinimize": "Always minimize",
|
||||||
|
"minimize": "Minimize",
|
||||||
|
"exit": "Exit"
|
||||||
}
|
}
|
@@ -24,5 +24,9 @@
|
|||||||
"successfullyConnected": "已连接",
|
"successfullyConnected": "已连接",
|
||||||
"macOrIpAlreadyInUse": "MAC或IP地址已被占用或者未被中转服务器释放",
|
"macOrIpAlreadyInUse": "MAC或IP地址已被占用或者未被中转服务器释放",
|
||||||
"otherReasonFail": "连接失败",
|
"otherReasonFail": "连接失败",
|
||||||
"clearLog": "清除日志"
|
"clearLog": "清除日志",
|
||||||
|
"exitAlert": "退出或者最小化程序?",
|
||||||
|
"alwaysMinimize": "总是最小化",
|
||||||
|
"minimize": "最小化",
|
||||||
|
"exit": "退出"
|
||||||
}
|
}
|
@@ -19,4 +19,8 @@ class SharedPrefSingleton {
|
|||||||
Future<bool> setSavedConnection(String config) =>
|
Future<bool> setSavedConnection(String config) =>
|
||||||
_pref.setString('saved_connection', config);
|
_pref.setString('saved_connection', config);
|
||||||
String get savedConnection => _pref.getString('saved_connection') ?? '[]';
|
String get savedConnection => _pref.getString('saved_connection') ?? '[]';
|
||||||
|
|
||||||
|
Future<bool> setMinimizeOrNot(bool min) =>
|
||||||
|
_pref.setBool('minimize_on_quit', min);
|
||||||
|
bool? get minimizeOnQuit => _pref.getBool('minimize_on_quit');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user