Skip to content

Commit

Permalink
Add settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jun 3, 2023
1 parent 75d31e2 commit 8d4d8ff
Show file tree
Hide file tree
Showing 16 changed files with 1,209 additions and 411 deletions.
2 changes: 1 addition & 1 deletion FLUTTER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.0
3.10.3
10 changes: 10 additions & 0 deletions app/lib/api/open_release_notes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:url_launcher/url_launcher.dart';

Future<bool> openReleaseNotes() {
return launchUrl(
Uri(
scheme: 'https',
host: 'go.linwood.dev',
pathSegments: ['qeck', '1.0']),
mode: LaunchMode.externalApplication);
}
11 changes: 11 additions & 0 deletions app/lib/api/settings.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';

import '../pages/settings/page.dart';

Future<void> openSettings(BuildContext context) => showDialog<void>(
context: context,
builder: (context) => Dialog(
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 600, maxWidth: 800),
child: const SettingsPage(isDialog: true))));
47 changes: 29 additions & 18 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,60 @@ class QeckSettings with _$QeckSettings {
const QeckSettings._();

const factory QeckSettings({
@Default('') String locale,
@Default(ThemeMode.system) ThemeMode themeMode,
@Default(false) bool nativeTitleBar,
@Default('') String localeTag,
@Default(ThemeMode.system) ThemeMode theme,
@Default('') String design,
@Default(false) bool nativeTitleBar,
}) = _FlowSettings;

Locale? get locale {
if (localeTag.isEmpty) {
return null;
}
if (localeTag.contains('-')) {
return Locale(localeTag.split('-')[0], localeTag.split('-')[1]);
}
return Locale(localeTag);
}

factory QeckSettings.fromPrefs(SharedPreferences prefs) => QeckSettings(
themeMode:
ThemeMode.values.byName(prefs.getString('themeMode') ?? 'system'),
theme: ThemeMode.values.byName(prefs.getString('theme') ?? 'system'),
design: prefs.getString('design') ?? '',
nativeTitleBar: prefs.getBool('nativeTitleBar') ?? false,
locale: prefs.getString('locale') ?? '',
localeTag: prefs.getString('locale') ?? '',
);

Future<void> save() async {
final prefs = await SharedPreferences.getInstance();
prefs.setString('themeMode', themeMode.name);
prefs.setString('theme', theme.name);
prefs.setString('design', design);
prefs.setBool('nativeTitleBar', nativeTitleBar);
prefs.setString('locale', locale);
prefs.setString('locale', localeTag);
}
}

class SettingsCubit extends Cubit<QeckSettings> {
SettingsCubit(SharedPreferences prefs) : super(QeckSettings.fromPrefs(prefs));

Future<void> setThemeMode(ThemeMode mode) {
emit(state.copyWith(themeMode: mode));
return state.save();
Future<void> changeTheme(ThemeMode theme) {
emit(state.copyWith(theme: theme));
return save();
}

Future<void> setDesign(String design) {
Future<void> changeDesign(String design) {
emit(state.copyWith(design: design));
return state.save();
return save();
}

Future<void> setNativeTitleBar(bool nativeTitleBar) {
Future<void> changeNativeTitleBar(bool nativeTitleBar) {
emit(state.copyWith(nativeTitleBar: nativeTitleBar));
return state.save();
return save();
}

Future<void> setLocale(String locale) {
emit(state.copyWith(locale: locale));
return state.save();
Future<void> changeLocale(Locale? locale) {
emit(state.copyWith(localeTag: locale?.toLanguageTag() ?? ''));
return save();
}

Future<void> save() => state.save();
}
108 changes: 54 additions & 54 deletions app/lib/cubits/settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ final _privateConstructorUsedError = UnsupportedError(

/// @nodoc
mixin _$QeckSettings {
String get locale => throw _privateConstructorUsedError;
ThemeMode get themeMode => throw _privateConstructorUsedError;
bool get nativeTitleBar => throw _privateConstructorUsedError;
String get localeTag => throw _privateConstructorUsedError;
ThemeMode get theme => throw _privateConstructorUsedError;
String get design => throw _privateConstructorUsedError;
bool get nativeTitleBar => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$QeckSettingsCopyWith<QeckSettings> get copyWith =>
Expand All @@ -33,7 +33,7 @@ abstract class $QeckSettingsCopyWith<$Res> {
_$QeckSettingsCopyWithImpl<$Res, QeckSettings>;
@useResult
$Res call(
{String locale, ThemeMode themeMode, bool nativeTitleBar, String design});
{String localeTag, ThemeMode theme, String design, bool nativeTitleBar});
}

/// @nodoc
Expand All @@ -49,28 +49,28 @@ class _$QeckSettingsCopyWithImpl<$Res, $Val extends QeckSettings>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? locale = null,
Object? themeMode = null,
Object? nativeTitleBar = null,
Object? localeTag = null,
Object? theme = null,
Object? design = null,
Object? nativeTitleBar = null,
}) {
return _then(_value.copyWith(
locale: null == locale
? _value.locale
: locale // ignore: cast_nullable_to_non_nullable
localeTag: null == localeTag
? _value.localeTag
: localeTag // ignore: cast_nullable_to_non_nullable
as String,
themeMode: null == themeMode
? _value.themeMode
: themeMode // ignore: cast_nullable_to_non_nullable
theme: null == theme
? _value.theme
: theme // ignore: cast_nullable_to_non_nullable
as ThemeMode,
nativeTitleBar: null == nativeTitleBar
? _value.nativeTitleBar
: nativeTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
design: null == design
? _value.design
: design // ignore: cast_nullable_to_non_nullable
as String,
nativeTitleBar: null == nativeTitleBar
? _value.nativeTitleBar
: nativeTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
Expand All @@ -84,7 +84,7 @@ abstract class _$$_FlowSettingsCopyWith<$Res>
@override
@useResult
$Res call(
{String locale, ThemeMode themeMode, bool nativeTitleBar, String design});
{String localeTag, ThemeMode theme, String design, bool nativeTitleBar});
}

/// @nodoc
Expand All @@ -98,28 +98,28 @@ class __$$_FlowSettingsCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? locale = null,
Object? themeMode = null,
Object? nativeTitleBar = null,
Object? localeTag = null,
Object? theme = null,
Object? design = null,
Object? nativeTitleBar = null,
}) {
return _then(_$_FlowSettings(
locale: null == locale
? _value.locale
: locale // ignore: cast_nullable_to_non_nullable
localeTag: null == localeTag
? _value.localeTag
: localeTag // ignore: cast_nullable_to_non_nullable
as String,
themeMode: null == themeMode
? _value.themeMode
: themeMode // ignore: cast_nullable_to_non_nullable
theme: null == theme
? _value.theme
: theme // ignore: cast_nullable_to_non_nullable
as ThemeMode,
nativeTitleBar: null == nativeTitleBar
? _value.nativeTitleBar
: nativeTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
design: null == design
? _value.design
: design // ignore: cast_nullable_to_non_nullable
as String,
nativeTitleBar: null == nativeTitleBar
? _value.nativeTitleBar
: nativeTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
Expand All @@ -128,46 +128,46 @@ class __$$_FlowSettingsCopyWithImpl<$Res>
class _$_FlowSettings extends _FlowSettings {
const _$_FlowSettings(
{this.locale = '',
this.themeMode = ThemeMode.system,
this.nativeTitleBar = false,
this.design = ''})
{this.localeTag = '',
this.theme = ThemeMode.system,
this.design = '',
this.nativeTitleBar = false})
: super._();

@override
@JsonKey()
final String locale;
final String localeTag;
@override
@JsonKey()
final ThemeMode themeMode;
final ThemeMode theme;
@override
@JsonKey()
final bool nativeTitleBar;
final String design;
@override
@JsonKey()
final String design;
final bool nativeTitleBar;

@override
String toString() {
return 'QeckSettings(locale: $locale, themeMode: $themeMode, nativeTitleBar: $nativeTitleBar, design: $design)';
return 'QeckSettings(localeTag: $localeTag, theme: $theme, design: $design, nativeTitleBar: $nativeTitleBar)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_FlowSettings &&
(identical(other.locale, locale) || other.locale == locale) &&
(identical(other.themeMode, themeMode) ||
other.themeMode == themeMode) &&
(identical(other.localeTag, localeTag) ||
other.localeTag == localeTag) &&
(identical(other.theme, theme) || other.theme == theme) &&
(identical(other.design, design) || other.design == design) &&
(identical(other.nativeTitleBar, nativeTitleBar) ||
other.nativeTitleBar == nativeTitleBar) &&
(identical(other.design, design) || other.design == design));
other.nativeTitleBar == nativeTitleBar));
}

@override
int get hashCode =>
Object.hash(runtimeType, locale, themeMode, nativeTitleBar, design);
Object.hash(runtimeType, localeTag, theme, design, nativeTitleBar);

@JsonKey(ignore: true)
@override
Expand All @@ -178,21 +178,21 @@ class _$_FlowSettings extends _FlowSettings {

abstract class _FlowSettings extends QeckSettings {
const factory _FlowSettings(
{final String locale,
final ThemeMode themeMode,
final bool nativeTitleBar,
final String design}) = _$_FlowSettings;
{final String localeTag,
final ThemeMode theme,
final String design,
final bool nativeTitleBar}) = _$_FlowSettings;
const _FlowSettings._() : super._();

@override
String get locale;
String get localeTag;
@override
ThemeMode get themeMode;
@override
bool get nativeTitleBar;
ThemeMode get theme;
@override
String get design;
@override
bool get nativeTitleBar;
@override
@JsonKey(ignore: true)
_$$_FlowSettingsCopyWith<_$_FlowSettings> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
32 changes: 31 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,35 @@
"change": "Change",
"secure": "Secure",
"port": "Port",
"otherSeats": "Other seats"
"otherSeats": "Other seats",
"general": "General",
"settings": "Settings",
"connections": "Connections",
"personalization": "Personalization",
"lightTheme": "Light theme",
"darkTheme": "Dark theme",
"systemTheme": "System theme",
"defaultLocale": "Default locale",
"update": "Update",
"stable": "Stable",
"nightly": "Nightly",
"checkForUpdates": "Check for updates",
"usingLatestStable": "You are using the latest stable version",
"usingLatestNightly": "You are using the latest nightly version",
"currentVersion": "Current version",
"updateNow": "Update now",
"updateAvailable": "Update available",
"error": "Error",
"documentation": "Documentation",
"releaseNotes": "Release notes",
"imprint": "Imprint",
"source": "Source",
"changelog": "Changelog",
"license": "License",
"privacypolicy": "Privacy policy",
"thirdPartyLicenses": "Third party licenses",
"theme": "Theme",
"design": "Design",
"locale": "Locale",
"nativeTitleBar": "Native window title bar"
}
Loading

1 comment on commit 8d4d8ff

@vercel
Copy link

@vercel vercel bot commented on 8d4d8ff Jun 3, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

qeck – ./app

qeck-git-develop-linwood.vercel.app
qeck-linwood.vercel.app
qeck.vercel.app
qeck.linwood.dev

Please sign in to comment.