Skip to content

Commit

Permalink
refactor: settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Jan 8, 2024
1 parent b090bbb commit e778cdb
Show file tree
Hide file tree
Showing 12 changed files with 681 additions and 17 deletions.
22 changes: 22 additions & 0 deletions lib/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@ import 'dart:async';
import 'dart:convert';

import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart';

class SettingsController extends GetxController {
final contributors = [].obs;
final extensionLogWindowId = (-1).obs;

final links = {
'Github': 'https://github.com/miru-project/miru-app',
'Telegram Group': 'https://t.me/MiruChat',
'Website': 'https://miru.js.org',
};

@override
void onInit() {
super.onInit();
_getContributors();
}

void toggleExtensionLogWindow(bool open) async {
if (open && extensionLogWindowId.value == -1) {
final window = await DesktopMultiWindow.createWindow(jsonEncode({
Expand Down Expand Up @@ -35,4 +49,12 @@ class SettingsController extends GetxController {
WindowController.fromWindowId(extensionLogWindowId.value).close();
extensionLogWindowId.value = -1;
}

_getContributors() async {
final res = await Dio()
.get("https://api.github.com/repos/miru-project/miru-app/contributors");
contributors.value = List.from(res.data)
.where((element) => element["type"] == "User")
.toList();
}
}
2 changes: 1 addition & 1 deletion lib/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:miru_app/views/pages/home_page.dart';
import 'package:miru_app/views/pages/main_page.dart';
import 'package:miru_app/views/pages/search/extension_searcher_page.dart';
import 'package:miru_app/views/pages/search/search_page.dart';
import 'package:miru_app/views/pages/settings_page.dart';
import 'package:miru_app/views/pages/settings/settings_page.dart';

final rootNavigatorKey = GlobalKey<NavigatorState>();
final _shellNavigatorKey = GlobalKey<NavigatorState>();
Expand Down
14 changes: 10 additions & 4 deletions lib/views/pages/extension/extension_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import 'package:miru_app/views/widgets/card_tile.dart';
import 'package:miru_app/views/widgets/messenger.dart';
import 'package:miru_app/views/widgets/platform_widget.dart';
import 'package:miru_app/views/widgets/progress.dart';
import 'package:miru_app/views/widgets/settings_input_tile.dart';
import 'package:miru_app/views/widgets/settings_radios_tile.dart';
import 'package:miru_app/views/widgets/settings_switch_tile.dart';
import 'package:miru_app/views/widgets/settings_tile.dart';
import 'package:miru_app/views/widgets/settings/settings_input_tile.dart';
import 'package:miru_app/views/widgets/settings/settings_radios_tile.dart';
import 'package:miru_app/views/widgets/settings/settings_switch_tile.dart';
import 'package:miru_app/views/widgets/settings/settings_tile.dart';

class ExtensionSettingsPage extends StatefulWidget {
const ExtensionSettingsPage({
Expand Down Expand Up @@ -58,6 +58,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
for (final setting in c.settings) {
if (setting.type == ExtensionSettingType.input) {
list.add(SettingsIntpuTile(
isCard: true,
title: setting.title,
onChanged: (value) async {
await DatabaseService.putExtensionSetting(
Expand All @@ -83,6 +84,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
if (setting.type == ExtensionSettingType.radio) {
final map = Map<String, String>.from(jsonDecode(setting.options!));
list.add(SettingsRadiosTile(
isCard: true,
title: setting.title,
itemNameValue: () {
return map;
Expand All @@ -102,6 +104,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
}
if (setting.type == ExtensionSettingType.toggle) {
list.add(SettingsSwitchTile(
isCard: true,
title: setting.title,
onChanged: (value) {
DatabaseService.putExtensionSetting(
Expand Down Expand Up @@ -220,6 +223,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
if (!LayoutUtils.isTablet) ...[
const Divider(),
SettingsTile(
isCard: true,
title: 'cookie-clean.title'.i18n,
buildSubtitle: () => 'cookie-clean.subtitle'.i18n,
trailing: TextButton(
Expand Down Expand Up @@ -253,6 +257,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
child: Column(
children: [
SettingsTile(
isCard: true,
title: 'cookie-clean.title'.i18n,
buildSubtitle: () => 'cookie-clean.subtitle'.i18n,
trailing: TextButton(
Expand Down Expand Up @@ -408,6 +413,7 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
),
const SizedBox(height: 16),
SettingsTile(
isCard: true,
title: 'cookie-clean.title'.i18n,
buildSubtitle: () => 'cookie-clean.subtitle'.i18n,
trailing: fluent.FilledButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/views/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:miru_app/views/pages/extension/extension_page.dart';
import 'package:miru_app/views/pages/home_page.dart';
import 'package:miru_app/controllers/main_controller.dart';
import 'package:miru_app/views/pages/search/search_page.dart';
import 'package:miru_app/views/pages/settings_page.dart';
import 'package:miru_app/views/pages/settings/settings_page.dart';
import 'package:miru_app/router/router.dart';
import 'package:miru_app/utils/application.dart';
import 'package:miru_app/utils/i18n.dart';
Expand Down
Loading

2 comments on commit e778cdb

@bachig26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiaoMint i think it'll nice to have the update check option to be moved to About. also it doesn't have to show the current version twice on the same page? what do you think?

@MiaoMint
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiaoMint i think it'll nice to have the update check option to be moved to About. also it doesn't have to show the current version twice on the same page? what do you think?

you're right

Please sign in to comment.