Skip to content

Commit 34e7409

Browse files
committed
Add settings features from butterfly
1 parent b4a4314 commit 34e7409

File tree

12 files changed

+742
-453
lines changed

12 files changed

+742
-453
lines changed

api/pubspec.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ packages:
55
dependency: transitive
66
description:
77
name: _fe_analyzer_shared
8-
sha256: dc27559385e905ad30838356c5f5d574014ba39872d732111cd07ac0beff4c57
8+
sha256: e55636ed79578b9abca5fecf9437947798f5ef7456308b5cb85720b793eac92f
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "80.0.0"
11+
version: "82.0.0"
1212
analyzer:
1313
dependency: transitive
1414
description:
1515
name: analyzer
16-
sha256: "192d1c5b944e7e53b24b5586db760db934b177d4147c42fbca8c8c5f1eb8d11e"
16+
sha256: "13c1e6c6fd460522ea840abec3f677cc226f5fec7872c04ad7b425517ccf54f7"
1717
url: "https://pub.dev"
1818
source: hosted
19-
version: "7.3.0"
19+
version: "7.4.4"
2020
ansicolor:
2121
dependency: transitive
2222
description:
@@ -574,18 +574,18 @@ packages:
574574
dependency: transitive
575575
description:
576576
name: web_socket
577-
sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83"
577+
sha256: bfe6f435f6ec49cb6c01da1e275ae4228719e59a6b067048c51e72d9d63bcc4b
578578
url: "https://pub.dev"
579579
source: hosted
580-
version: "0.1.6"
580+
version: "1.0.0"
581581
web_socket_channel:
582582
dependency: "direct main"
583583
description:
584584
name: web_socket_channel
585-
sha256: "0b8e2457400d8a859b7b2030786835a28a8e80836ef64402abef392ff4f1d0e5"
585+
sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8
586586
url: "https://pub.dev"
587587
source: hosted
588-
version: "3.0.2"
588+
version: "3.0.3"
589589
webkit_inspection_protocol:
590590
dependency: transitive
591591
description:

app/android/Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ GEM
1111
artifactory (3.0.17)
1212
atomos (0.1.3)
1313
aws-eventstream (1.3.2)
14-
aws-partitions (1.1086.0)
15-
aws-sdk-core (3.222.1)
14+
aws-partitions (1.1090.0)
15+
aws-sdk-core (3.222.2)
1616
aws-eventstream (~> 1, >= 1.3.0)
1717
aws-partitions (~> 1, >= 1.992.0)
1818
aws-sigv4 (~> 1.9)

app/lib/cubits/settings.dart

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,42 @@ import '../api/storage/remote/model.dart';
1111

1212
part 'settings.mapper.dart';
1313

14+
@MappableEnum()
1415
enum ThemeDensity {
1516
system,
17+
maximize,
18+
desktop,
1619
compact,
1720
comfortable,
1821
standard;
1922

2023
VisualDensity toFlutter() => switch (this) {
21-
ThemeDensity.comfortable => VisualDensity.comfortable,
24+
ThemeDensity.maximize =>
25+
const VisualDensity(horizontal: -4, vertical: -4),
26+
ThemeDensity.desktop =>
27+
const VisualDensity(horizontal: -3, vertical: -3),
2228
ThemeDensity.compact => VisualDensity.compact,
29+
ThemeDensity.comfortable => VisualDensity.comfortable,
2330
ThemeDensity.standard => VisualDensity.standard,
2431
ThemeDensity.system => VisualDensity.adaptivePlatformDensity,
2532
};
2633
}
2734

28-
@MappableClass()
35+
final class ThemeModeMapper extends SimpleMapper<ThemeMode> {
36+
const ThemeModeMapper();
37+
38+
@override
39+
ThemeMode decode(Object value) {
40+
return ThemeMode.values.byName(value.toString());
41+
}
42+
43+
@override
44+
String encode(ThemeMode value) {
45+
return value.name;
46+
}
47+
}
48+
49+
@MappableClass(includeCustomMappers: [ThemeModeMapper()])
2950
class FlowSettings with FlowSettingsMappable, LeapSettings {
3051
final String locale;
3152
final ThemeMode themeMode;
@@ -84,6 +105,7 @@ class FlowSettings with FlowSettingsMappable, LeapSettings {
84105
}
85106
}
86107

108+
@MappableEnum()
87109
enum SyncMode { always, noMobile, manual }
88110

89111
enum SyncStatus { synced, syncing, error }
@@ -146,4 +168,16 @@ class SettingsCubit extends Cubit<FlowSettings>
146168
emit(state.copyWith(highContrast: highContrast));
147169
return state.save();
148170
}
171+
172+
Future<void> importSettings(String data) {
173+
final settings = FlowSettingsMapper.fromJson(data).copyWith(
174+
remotes: state.remotes,
175+
);
176+
emit(settings);
177+
return state.save();
178+
}
179+
180+
Future<String> exportSettings() async {
181+
return state.toJson();
182+
}
149183
}

app/lib/cubits/settings.mapper.dart

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/lib/l10n/app_en.arb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,9 @@
318318
"example": "1"
319319
}
320320
}
321-
}
321+
},
322+
"systemTheme": "System theme",
323+
"desktop": "Desktop",
324+
"restoreSettingsFromFile": "Restore settings from file",
325+
"exportSettingsToFile": "Export settings to file"
322326
}

app/lib/pages/settings/data.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import 'dart:convert';
2+
3+
import 'package:file_selector/file_selector.dart';
14
import 'package:flow/api/storage/sources.dart';
25
import 'package:flow/theme.dart';
36
import 'package:flow/visualizer/sync.dart';
47
import 'package:flutter/material.dart';
58
import 'package:flutter_bloc/flutter_bloc.dart';
69
import 'package:flow/src/generated/i18n/app_localizations.dart';
10+
import 'package:lw_sysapi/lw_sysapi.dart';
711
import 'package:material_leap/material_leap.dart';
812
import 'package:phosphor_flutter/phosphor_flutter.dart';
913

@@ -85,9 +89,60 @@ class DataSettingsPage extends StatelessWidget {
8589
]),
8690
),
8791
),
92+
Card(
93+
margin: settingsCardMargin,
94+
child: Padding(
95+
padding: settingsCardPadding,
96+
child: Column(
97+
crossAxisAlignment: CrossAxisAlignment.stretch,
98+
children: [
99+
ListTile(
100+
title: Text(
101+
AppLocalizations.of(context).restoreSettingsFromFile),
102+
leading: Icon(PhosphorIconsLight.arrowSquareIn),
103+
onTap: () => _importSettings(context),
104+
),
105+
ListTile(
106+
title: Text(
107+
AppLocalizations.of(context).exportSettingsToFile),
108+
leading: Icon(PhosphorIconsLight.arrowSquareOut),
109+
onTap: () => _exportSettings(context),
110+
),
111+
],
112+
),
113+
),
114+
),
88115
],
89116
),
90117
),
91118
);
92119
}
120+
121+
void _importSettings(BuildContext context) async {
122+
final settingsCubit = context.read<SettingsCubit>();
123+
final file = await openFile(acceptedTypeGroups: [
124+
XTypeGroup(
125+
label: 'Settings',
126+
extensions: ['json'],
127+
),
128+
]);
129+
if (file == null) return;
130+
final data = await file.readAsString();
131+
settingsCubit.importSettings(data);
132+
}
133+
134+
void _exportSettings(BuildContext context) async {
135+
final settingsCubit = context.read<SettingsCubit>();
136+
final data = await settingsCubit.exportSettings();
137+
if (!context.mounted) return;
138+
await exportFile(
139+
bytes: utf8.encode(data),
140+
context: context,
141+
fileExtension: 'json',
142+
fileName: 'settings',
143+
label: AppLocalizations.of(context).exportSettingsToFile,
144+
mimeType: 'application/json',
145+
uniformTypeIdentifier: 'public.json',
146+
);
147+
}
93148
}

app/lib/pages/settings/personalization.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ class PersonalizationSettingsPage extends StatelessWidget {
2525

2626
String _getDensityName(BuildContext context, ThemeDensity density) =>
2727
switch (density) {
28-
ThemeDensity.system => AppLocalizations.of(context).systemDefault,
29-
ThemeDensity.comfortable => AppLocalizations.of(context).comfortable,
28+
ThemeDensity.system => AppLocalizations.of(context).systemTheme,
29+
ThemeDensity.maximize => LeapLocalizations.of(context).maximize,
30+
ThemeDensity.desktop => AppLocalizations.of(context).desktop,
3031
ThemeDensity.compact => AppLocalizations.of(context).compact,
3132
ThemeDensity.standard => AppLocalizations.of(context).standard,
33+
ThemeDensity.comfortable => AppLocalizations.of(context).comfortable,
3234
};
3335

3436
@override

0 commit comments

Comments
 (0)