Skip to content

Commit

Permalink
feat: After switching servers, the system menu will be refreshed auto…
Browse files Browse the repository at this point in the history
…matically
  • Loading branch information
zmhu committed Nov 30, 2023
1 parent b3f98a2 commit a2c9083
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 17 additions & 4 deletions lib/components/settings/geekerchat_active.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:geek_chat/controller/main_controller.dart';
import 'package:geek_chat/controller/settings.dart';
import 'package:geek_chat/controller/settings_server_controller.dart';
import 'package:geek_chat/models/model.dart';
Expand All @@ -16,6 +17,7 @@ class GeekerChatSettingsComponent extends StatelessWidget {

TextEditingController textEditingController = TextEditingController();
SettingsServerController settingsServerController = Get.find();
MainController mainController = Get.find();

Icon getTextInputIcon(bool isActive, bool needReactive) {
if (isActive && !needReactive) {
Expand Down Expand Up @@ -98,7 +100,7 @@ class GeekerChatSettingsComponent extends StatelessWidget {
onPressed: () {
submitActive(controller, context);
},
child: Text("Active".tr)),
child: Text("Save".tr)),
const SizedBox(width: 10),
OutlinedButton(
onPressed: () {
Expand All @@ -120,8 +122,11 @@ class GeekerChatSettingsComponent extends StatelessWidget {
}

submitActive(SettingsServerController controller, BuildContext context) {
logger.d(
"default server provider: ${settingsServerController.defaultServer.provider}");
logger.d("settings server provider: ${settingsServerController.provider}");
if (controller.defaultServer.license.isNotEmpty) {
if (controller.needReactive || !controller.defaultServer.isActived) {
if (controller.needReactive) {
controller
.activeLicense(controller.defaultServer.license,
settingsController.settings.uuid, settingsController.lang)
Expand All @@ -148,11 +153,19 @@ class GeekerChatSettingsComponent extends StatelessWidget {
}
});
} else {
//
if (settingsServerController.defaultServer.isActived) {
// settingsController.settings.provider = value.provider;
settingsController.settings.provider =
settingsServerController.provider;
settingsController.saveSettings();
showCustomToast(title: "Save successful".tr, context: context);
}
}
} else {
showCustomToast(title: "Please Input License".tr, context: context);
showCustomToast(title: "Save successful".tr, context: context);
}
// mainController.update();
// settingsController.update(['subscription']);
}

List<Widget> getPaymentInfo(
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GeekChatTranslations extends Translations {
"Active": "Active",
"Server Settings": "Server Settings",
"Please Select a server": "Please Select a server",
"Save successful": "Save successful",
},
'zh_Hans_CN': {
"appTitle": "GeekerChat",
Expand Down Expand Up @@ -134,6 +135,7 @@ class GeekChatTranslations extends Translations {
"Active": "激活",
"Server Settings": "服务器设置",
"Please Select a server": "请选择服务器",
"Save successful": "保存成功",
}
};
}
13 changes: 10 additions & 3 deletions lib/pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:geek_chat/components/desktop_main_right_component.dart';
import 'package:geek_chat/controller/chat_list_controller.dart';
import 'package:geek_chat/controller/chat_message_controller.dart';
import 'package:geek_chat/controller/settings.dart';
import 'package:geek_chat/controller/settings_server_controller.dart';
import 'package:geek_chat/models/session.dart';
import 'package:get/get.dart';

Expand All @@ -23,7 +24,7 @@ class DesktopHomePage extends StatelessWidget {
ChatMessageController chatMessageController =
Get.find<ChatMessageController>();

List<Widget> getLeftMenus() {
List<Widget> getLeftMenus(SettingsServerController controller) {
List<Widget> leftMenus = [
LeftMenuButtonComponent(
title: "Prompts".tr,
Expand All @@ -35,7 +36,9 @@ class DesktopHomePage extends StatelessWidget {
LeftMenuButtonComponent(
title: "Settings".tr,
onPressed: () {
Get.toNamed("/dsettings");
Get.toNamed("/dsettings")?.then((value) {
controller.update(['subscription']);
});
},
icon: Icons.settings,
),
Expand Down Expand Up @@ -119,7 +122,11 @@ class DesktopHomePage extends StatelessWidget {
),
SizedBox(
width: double.infinity,
child: Column(children: getLeftMenus()),
child: GetBuilder<SettingsServerController>(
id: 'subscription',
builder: (controler) {
return Column(children: getLeftMenus(controler));
}),
),
],
),
Expand Down

0 comments on commit a2c9083

Please sign in to comment.