Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #116 from CCXXXI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
CCXXXI authored Oct 19, 2021
2 parents f126de2 + 2ff6f69 commit a998f19
Show file tree
Hide file tree
Showing 22 changed files with 997 additions and 355 deletions.
63 changes: 45 additions & 18 deletions lib/dev/dev_logic.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
import 'package:flutter_loggy/flutter_loggy.dart';
import 'package:get/get.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';

import '../toolbox/toolbox_logic.dart';
import '../utils/database.dart';
import '../utils/gu.dart';
import '../utils/loading.dart';
import '../utils/log.dart';
import 'cheater_view.dart';
import 'trivia_view.dart';

class DevLogic extends GetxController with L {
void updateLog(_) => Get.snackbar('日志设置已更新', '重启后生效');
final toolboxLogic = Get.find<ToolboxLogic>();

void suckerOnChanged(bool v) {
toolbox
..sucker = v
..save();
toolboxLogic.updateSuckerEnabled(v);
}

void cheaterOnChanged(bool v) {
toolbox
..cheater = v
..save();
toolboxLogic.updateCheaterEnabled(v);
}

void juanOnChanged(bool v) {
toolbox
..juan = v
..save();
toolboxLogic.updateJuanEnabled(v);
}

void levelOnChanged(String v) {
log
..level = v
..save();
Get.snackbar('日志设置已更新', '重启后生效');
}

void stackTraceLevelOnChanged(String v) {
log
..stackTraceLevel = v
..save();
Get.snackbar('日志设置已更新', '重启后生效');
}

void includeCallerInfoOnChanged(bool v) {
log
..includeCallerInfo = v
..save();
Get.snackbar('日志设置已更新', '重启后生效');
}

void logOnTap() => Get.to(() => const LoggyStreamScreen());

Expand All @@ -24,19 +66,4 @@ class DevLogic extends GetxController with L {
title: 'Loading',
content: Loading(),
);

final jsonFile = ''.obs;

@override
void onInit() async {
if (GetPlatform.isDesktop && !GetPlatform.isWeb) {
final baseDir = (await getApplicationSupportDirectory()).path;
l.info(jsonFile.value = '$baseDir\\shared_preferences.json');
}
super.onInit();
}

void jsonOnTap() async {
l.info((await OpenFile.open(jsonFile.value)).message);
}
}
45 changes: 17 additions & 28 deletions lib/dev/dev_view.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_settings_screens/flutter_settings_screens.dart';
import 'package:get/get.dart';
import 'package:loggy/loggy.dart';

import '../toolbox/toolbox_logic.dart';
import '../utils/database.dart';
import 'dev_logic.dart';

class DevPage extends StatelessWidget {
DevPage({Key? key}) : super(key: key);

final logic = Get.put(DevLogic());
final toolboxLogic = Get.find<ToolboxLogic>();

@override
Widget build(BuildContext context) {
Expand All @@ -24,41 +22,45 @@ class DevPage extends StatelessWidget {
SwitchSettingsTile(
title: 'sucker',
settingKey: 'toolbox.sucker',
onChange: (v) => toolboxLogic.updateSuckerEnabled(v),
defaultValue: toolbox.sucker,
onChange: logic.suckerOnChanged,
),
SwitchSettingsTile(
title: 'cheater',
settingKey: 'toolbox.cheater',
onChange: (v) => toolboxLogic.updateCheaterEnabled(v),
defaultValue: toolbox.cheater,
onChange: logic.cheaterOnChanged,
),
SwitchSettingsTile(
title: 'juan',
settingKey: 'toolbox.juan',
onChange: (v) => toolboxLogic.updateJuanEnabled(v),
defaultValue: toolbox.juan,
onChange: logic.juanOnChanged,
),
],
),
SettingsGroup(
title: '日志',
children: [
DropDownSettingsTile(
SimpleDropDownSettingsTile(
title: 'level',
settingKey: 'log.level',
selected: 2,
values: _logLevels,
onChange: logic.updateLog,
selected: log.level,
values: log.levels,
onChange: logic.levelOnChanged,
),
DropDownSettingsTile(
SimpleDropDownSettingsTile(
title: 'stackTraceLevel',
settingKey: 'log.stackTraceLevel',
selected: 5,
values: _logLevels,
onChange: logic.updateLog,
selected: log.stackTraceLevel,
values: log.levels,
onChange: logic.stackTraceLevelOnChanged,
),
SwitchSettingsTile(
title: 'includeCallerInfo',
settingKey: 'log.includeCallerInfo',
onChange: logic.updateLog,
defaultValue: log.includeCallerInfo,
onChange: logic.includeCallerInfoOnChanged,
),
ListTile(
title: const Text('log'),
Expand Down Expand Up @@ -88,14 +90,6 @@ class DevPage extends StatelessWidget {
title: const Text('loading'),
onTap: logic.loadingOnTap,
),
Obx(
() => ListTile(
title: const Text('shared_preferences.json'),
subtitle: Text(logic.jsonFile.value),
enabled: logic.jsonFile.value.isNotEmpty,
onTap: logic.jsonOnTap,
),
),
],
).toList(),
),
Expand All @@ -104,8 +98,3 @@ class DevPage extends StatelessWidget {
);
}
}

final _logLevels = {
for (var i = 0; i != LogLevel.values.length; ++i)
i: LogLevel.values[i].toString(),
};
4 changes: 2 additions & 2 deletions lib/home/home_logic.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_settings_screens/flutter_settings_screens.dart';
import 'package:get/get.dart';

import '../dev/dev_view.dart';
import '../timetable/timetable_logic.dart';
import '../utils/database.dart';
import '../utils/log.dart';

class HomeLogic extends GetxController with L {
final idx = Settings.getValue('launchPage', 1).obs;
final idx = misc.launchPage_.obs;
final isAnimating = false.obs;

late PageController _pageController;
Expand Down
28 changes: 5 additions & 23 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import 'package:window_size/window_size.dart';

import 'home/home_view.dart';
import 'settings/theme.dart';
import 'utils/database.dart' as db;
import 'utils/log.dart';
import 'utils/sentry.dart';
import 'utils/string.dart';

void main() async {
await Settings.init();
await db.initDatabase();
Settings.init();
initLog();
if (GetPlatform.isDesktop && !GetPlatform.isWeb) initDesktop();
await initMessages();
updateUser();
await initSentry(const MyApp());
}

Expand Down Expand Up @@ -46,25 +50,3 @@ void initDesktop() {

logInfo('initDesktop end.');
}

Future<void> initSentry(Widget app) async {
final id_ = Settings.getValue('ecnu.id', '');
final id = id_.isEmpty ? null : id_;
final username_ = Settings.getValue('ecnu.name', '');
final username = username_.isEmpty ? null : username_;
logInfo('id: $id, username: $username');
logInfo('release: $release');

Sentry.configureScope((scope) => scope.user =
SentryUser(id: id, username: username, ipAddress: '{{auto}}'));

await SentryFlutter.init(
(options) => options
..dsn =
'https://[email protected]/5975191'
..tracesSampleRate = 1
..sendDefaultPii = true
..release = release,
appRunner: () => runApp(app),
);
}
50 changes: 49 additions & 1 deletion lib/settings/settings_logic.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:quiver/iterables.dart';

import '../utils/database.dart' as db;
import '../utils/log.dart';
import '../utils/string.dart';
import '../utils/web.dart';
Expand All @@ -12,7 +14,53 @@ class SettingsLogic extends GetxController with L {

SettingsLogic({Dio? dio}) : dio = dio ?? defaultDio;

void updateTheme(_) => theme.updateTheme();
void modeOnChanged(String v) {
db.theme
..mode = v
..save();
theme.updateTheme();
}

void fontOnChanged(String v) {
db.theme
..font = v
..save();
theme.updateTheme();
}

void overrideColorOnChanged(bool v) {
db.theme
..overrideColor = v
..save();
theme.updateTheme();
}

void primaryOnChanged(Color v) {
db.theme
..primary = v
..save();
theme.updateTheme();
}

void secondaryOnChanged(Color v) {
db.theme
..secondary = v
..save();
theme.updateTheme();
}

void surfaceOnChanged(Color v) {
db.theme
..surface = v
..save();
theme.updateTheme();
}

void launchPageOnChanged(String v) {
db.misc
..launchPage = v
..save();
}

/// - null: loading
/// - empty: failed
Expand Down
Loading

0 comments on commit a998f19

Please sign in to comment.