Skip to content

Commit

Permalink
Merge pull request #390 from lamarios/feature/add_settings_export_for…
Browse files Browse the repository at this point in the history
…_debugging

add option to copy settings as json for debugging purpose
  • Loading branch information
lamarios authored Nov 30, 2023
2 parents 520f849 + c38ad06 commit 979b814
Show file tree
Hide file tree
Showing 11 changed files with 1,324 additions and 1,283 deletions.
2,402 changes: 1,205 additions & 1,197 deletions lib/l10n/app_en.arb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/l10n/app_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"@password": {
"description": "Password label for login to a server"
},
"wrongUsernamePassword": "Неправильне ім'я користувача або пароль",
"wrongUsernamePassword": "Неправильне ім''я користувача або пароль",
"@wrongUsernamePassword": {
"description": "Error message when authentication fails"
},
Expand Down
8 changes: 8 additions & 0 deletions lib/settings/models/db/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:objectbox/objectbox.dart';

part 'settings.g.dart';

@Entity()
@JsonSerializable()
class SettingsValue {
@Id()
int id = 0;
Expand All @@ -11,4 +15,8 @@ class SettingsValue {
String value;

SettingsValue(this.name, this.value);

factory SettingsValue.fromJson(Map<String, dynamic> json) => _$SettingsValueFromJson(json);

Map<String, dynamic> toJson() => _$SettingsValueToJson(this);
}
20 changes: 20 additions & 0 deletions lib/settings/models/db/settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions lib/settings/states/settings.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:convert';

import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:bloc/bloc.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:easy_debounce/easy_debounce.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/app/states/app.dart';
import 'package:invidious/main.dart';
import 'package:invidious/workmanager.dart';
import 'package:locale_names/locale_names.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -310,7 +312,10 @@ class SettingsCubit extends Cubit<SettingsState> {

String? getLocaleDisplayName() {
List<String>? localeString = state.locale?.split('_');
Locale? l = localeString != null ? Locale.fromSubtags(languageCode: localeString[0], scriptCode: localeString.length >= 2 ? localeString[1] : null) : null;
Locale? l = localeString != null
? Locale.fromSubtags(
languageCode: localeString[0], scriptCode: localeString.length >= 2 ? localeString[1] : null)
: null;

return l?.nativeDisplayLanguageScript;
}
Expand Down Expand Up @@ -381,6 +386,19 @@ class SettingsCubit extends Cubit<SettingsState> {
});
}
}

copySettingsAsJson(BuildContext context) {
var encoder = const JsonEncoder.withIndent(' ');
String json = encoder.convert(state.settings);
Clipboard.setData(ClipboardData(text: json));
}

saveSetting(SettingsValue settings){
var newSettings = state.settings;
newSettings[settings.name] = settings;
emit(state.copyWith(settings: newSettings));
}

}

@CopyWith(constructor: "_")
Expand Down Expand Up @@ -479,26 +497,31 @@ class SettingsState {

set forceLandscapeFullScreen(bool b) => _set(LOCK_ORIENTATION_FULLSCREEN, b);

ThemeMode get themeMode => ThemeMode.values.firstWhere((element) => element.name == _get(THEME_MODE)?.value, orElse: () => ThemeMode.system);
ThemeMode get themeMode =>
ThemeMode.values.firstWhere((element) => element.name == _get(THEME_MODE)?.value, orElse: () => ThemeMode.system);

set themeMode(ThemeMode t) => _set(THEME_MODE, t.name);

bool get useSearchHistory => _get(USE_SEARCH_HISTORY)?.value == 'true';

set useSearchHistory(bool b) => _set(USE_SEARCH_HISTORY, b);

List<HomeDataSource> get appLayout => (_get(APP_LAYOUT)?.value ?? HomeDataSource.defaultSettings().map((e) => e.name).join(","))
.split(',')
.where((element) => element.isNotEmpty)
.map((e) => HomeDataSource.values.firstWhere((element) => element.name == e))
.toList();
List<HomeDataSource> get appLayout =>
(_get(APP_LAYOUT)?.value ?? HomeDataSource.defaultSettings().map((e) => e.name).join(","))
.split(',')
.where((element) => element.isNotEmpty)
.map((e) => HomeDataSource.values.firstWhere((element) => element.name == e))
.toList();

set appLayout(List<HomeDataSource> layout) => _set(APP_LAYOUT, layout.map((e) => e.name).join(","));

NavigationDestinationLabelBehavior get navigationBarLabelBehavior =>
NavigationDestinationLabelBehavior.values.firstWhere((e) => e.name == (_get(NAVIGATION_BAR_LABEL_BEHAVIOR)?.value ?? NavigationDestinationLabelBehavior.onlyShowSelected.name));
NavigationDestinationLabelBehavior.values.firstWhere((e) =>
e.name ==
(_get(NAVIGATION_BAR_LABEL_BEHAVIOR)?.value ?? NavigationDestinationLabelBehavior.onlyShowSelected.name));

set navigationBarLabelBehavior(NavigationDestinationLabelBehavior behavior) => _set(NAVIGATION_BAR_LABEL_BEHAVIOR, behavior.name);
set navigationBarLabelBehavior(NavigationDestinationLabelBehavior behavior) =>
_set(NAVIGATION_BAR_LABEL_BEHAVIOR, behavior.name);

bool get distractionFreeMode => _get(DISTRACTION_FREE_MODE)?.value == "true";

Expand Down
15 changes: 0 additions & 15 deletions lib/settings/states/sponsor_block_settings.dart

This file was deleted.

10 changes: 1 addition & 9 deletions lib/settings/views/screens/app_logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/settings/states/app_logs.dart';

import '../../../globals.dart';
import '../../../main.dart';
import '../../models/db/app_logs.dart';

@RoutePage()
Expand Down Expand Up @@ -68,14 +67,7 @@ class AppLogsScreen extends StatelessWidget {
bottom: _.selected.isNotEmpty ? 0 : -50,
duration: animationDuration,
child: InkWell(
onTap: () {
cubit.copySelectedLogsToClipboard();
final ScaffoldMessengerState? scaffold = scaffoldKey.currentState;
scaffold?.showSnackBar(SnackBar(
content: Text(locals.logsCopied),
duration: const Duration(seconds: 1),
));
},
onTap: cubit.copySelectedLogsToClipboard,
child: Container(
alignment: Alignment.center,
height: 50,
Expand Down
6 changes: 6 additions & 0 deletions lib/settings/views/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class SettingsScreen extends StatelessWidget {
title: Text(locals.appLogs),
description: Text(locals.appLogsDescription),
onPressed: openAppLogs,
),
SettingsTile(
leading: const Icon(Icons.settings),
title: Text(locals.copySettingsAsJson),
description: Text(locals.copySettingsAsJsonDescription),
onPressed: cubit.copySettingsAsJson,
)
])
],
Expand Down
56 changes: 27 additions & 29 deletions lib/settings/views/screens/sponsor_block_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:auto_route/annotations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/settings/states/sponsor_block_settings.dart';
import 'package:invidious/settings/models/db/settings.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/videos/models/sponsor_segment_types.dart';
import 'package:settings_ui/settings_ui.dart';

Expand All @@ -18,35 +19,32 @@ class SponsorBlockSettingsScreen extends StatelessWidget {
ColorScheme colorScheme = Theme.of(context).colorScheme;
SettingsThemeData theme = settingsTheme(colorScheme);

return BlocProvider(
create: (BuildContext context) => SponsorBlockCubit(0),
child: BlocBuilder<SponsorBlockCubit, int>(
builder: (context, _) {
var cubit = context.read<SponsorBlockCubit>();
return Scaffold(
appBar: AppBar(
backgroundColor: colorScheme.background,
scrolledUnderElevation: 0,
title: const Text('SponsorBlock'),
),
return BlocBuilder<SettingsCubit, SettingsState>(
builder: (context, _) {
var cubit = context.read<SettingsCubit>();
return Scaffold(
appBar: AppBar(
backgroundColor: colorScheme.background,
body: SafeArea(
bottom: false,
child: SettingsList(lightTheme: theme, darkTheme: theme, sections: [
SettingsSection(
title: Text(locals.sponsorBlockSettingsQuickDescription),
tiles: SponsorSegmentType.values
.map((t) => SettingsTile.switchTile(
initialValue: cubit.value(t),
onToggle: (bool value) => cubit.setValue(t, value),
title: Text(SponsorSegmentType.getLabel(t, locals)),
description: Text(SponsorSegmentType.getDescription(t, locals)),
))
.toList()),
]),
));
},
),
scrolledUnderElevation: 0,
title: const Text('SponsorBlock'),
),
backgroundColor: colorScheme.background,
body: SafeArea(
bottom: false,
child: SettingsList(lightTheme: theme, darkTheme: theme, sections: [
SettingsSection(
title: Text(locals.sponsorBlockSettingsQuickDescription),
tiles: SponsorSegmentType.values
.map((t) => SettingsTile.switchTile(
initialValue: _.settings[t.settingsName()]?.value == 'true',
onToggle: (bool value) => cubit.saveSetting(SettingsValue(t.settingsName(), value.toString())),
title: Text(SponsorSegmentType.getLabel(t, locals)),
description: Text(SponsorSegmentType.getDescription(t, locals)),
))
.toList()),
]),
));
},
);
}
}
43 changes: 22 additions & 21 deletions lib/settings/views/tv/screens/sponsor_block_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:auto_route/annotations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/settings/states/sponsor_block_settings.dart';
import 'package:invidious/settings/models/db/settings.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/settings/views/tv/screens/settings.dart';
import 'package:invidious/utils/views/tv/components/tv_overscan.dart';

Expand All @@ -16,26 +17,26 @@ class TvSponsorBlockSettingsScreen extends StatelessWidget {
Widget build(BuildContext context) {
AppLocalizations locals = AppLocalizations.of(context)!;
return Scaffold(
body: BlocProvider(
create: (context) => SponsorBlockCubit(0),
child: BlocBuilder<SponsorBlockCubit, int>(
builder: (context, _) {
var cubit = context.read<SponsorBlockCubit>();
return TvOverscan(
child: ListView(
children: [
SettingsTitle(title: locals.sponsorBlockSettingsQuickDescription),
...SponsorSegmentType.values.map((t) => SettingsTile(
trailing: Switch(value: cubit.value(t), onChanged: (value) {}),
onSelected: (context) => cubit.setValue(t, !cubit.value(t)),
title: SponsorSegmentType.getLabel(t, locals),
description: SponsorSegmentType.getDescription(t, locals),
))
],
),
);
},
),
body: BlocBuilder<SettingsCubit, SettingsState>(
builder: (context, _) {
var cubit = context.read<SettingsCubit>();
return TvOverscan(
child: ListView(
children: [
SettingsTitle(title: locals.sponsorBlockSettingsQuickDescription),
...SponsorSegmentType.values.map((t) {
bool value = _.settings[t.settingsName()]?.value == 'true';
return SettingsTile(
trailing: Switch(value: value, onChanged: (value) {}),
onSelected: (context) => cubit.saveSetting(SettingsValue(t.settingsName(), (!value).toString())),
title: SponsorSegmentType.getLabel(t, locals),
description: SponsorSegmentType.getDescription(t, locals),
);
})
],
),
);
},
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.17.3+4037
version: 1.17.4+4038

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit 979b814

Please sign in to comment.