Skip to content

Commit

Permalink
feat: Play (#207)
Browse files Browse the repository at this point in the history
* refactor: rename UserTile to UserPreview

* refactor: add a widget to display account info

* feat: do not remove tabs when sign out

* refactor: add showErrorMessageDialog

* refactor: make bottom ads rounded

* fix: do not save draft if guest

* feat: edit Play

* feat: support clickable mfm

* feat: play Play

* feat: backup aiscript storage

* ci: install rust
  • Loading branch information
poppingmoon authored Jun 16, 2024
1 parent 320a940 commit 09f3688
Show file tree
Hide file tree
Showing 121 changed files with 24,536 additions and 198 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ RUN ARCH=$(case $TARGETARCH in \
&& tar xzf fvm.tar.gz -C $FVM_DIR \
&& rm -f fvm.tar.gz \
&& ln -sf $FVM_DIR/fvm/fvm /usr/local/bin/fvm

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ analyzer:
exclude:
- "**/*.freezed.dart"
- "**/*.g.dart"
- "lib/rust/**"
- "rust_builder/**"
language:
strict-casts: true
strict-inference: true
Expand Down
2 changes: 2 additions & 0 deletions flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rust_input: rust/src/api/**/*.rs
dart_output: lib/rust
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'provider/general_settings_notifier_provider.dart';
import 'provider/shared_preferences_provider.dart';
import 'provider/theme_data_provider.dart';
import 'router/router.dart';
import 'rust/frb_generated.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -68,6 +69,7 @@ void main() async {
);
});
final prefs = await SharedPreferences.getInstance();
await RustLib.init();
runApp(
ProviderScope(
overrides: [sharedPreferencesProvider.overrideWithValue(prefs)],
Expand Down
1 change: 1 addition & 0 deletions lib/model/aria_backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AriaBackup with _$AriaBackup {
Map<String, AccountSettings>? accountSettings,
GeneralSettings? generalSettings,
List<String>? themes,
Map<String, Map<String, String>>? aiscriptStorage,
}) = _AriaBackup;

factory AriaBackup.fromJson(Map<String, dynamic> json) =>
Expand Down
57 changes: 45 additions & 12 deletions lib/model/aria_backup.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ mixin _$AriaBackup {
throw _privateConstructorUsedError;
GeneralSettings? get generalSettings => throw _privateConstructorUsedError;
List<String>? get themes => throw _privateConstructorUsedError;
Map<String, Map<String, String>>? get aiscriptStorage =>
throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -44,7 +46,8 @@ abstract class $AriaBackupCopyWith<$Res> {
List<TabSettings>? timelineTabs,
Map<String, AccountSettings>? accountSettings,
GeneralSettings? generalSettings,
List<String>? themes});
List<String>? themes,
Map<String, Map<String, String>>? aiscriptStorage});

$GeneralSettingsCopyWith<$Res>? get generalSettings;
}
Expand All @@ -67,6 +70,7 @@ class _$AriaBackupCopyWithImpl<$Res, $Val extends AriaBackup>
Object? accountSettings = freezed,
Object? generalSettings = freezed,
Object? themes = freezed,
Object? aiscriptStorage = freezed,
}) {
return _then(_value.copyWith(
metadata: freezed == metadata
Expand All @@ -89,6 +93,10 @@ class _$AriaBackupCopyWithImpl<$Res, $Val extends AriaBackup>
? _value.themes
: themes // ignore: cast_nullable_to_non_nullable
as List<String>?,
aiscriptStorage: freezed == aiscriptStorage
? _value.aiscriptStorage
: aiscriptStorage // ignore: cast_nullable_to_non_nullable
as Map<String, Map<String, String>>?,
) as $Val);
}

Expand Down Expand Up @@ -118,7 +126,8 @@ abstract class _$$AriaBackupImplCopyWith<$Res>
List<TabSettings>? timelineTabs,
Map<String, AccountSettings>? accountSettings,
GeneralSettings? generalSettings,
List<String>? themes});
List<String>? themes,
Map<String, Map<String, String>>? aiscriptStorage});

@override
$GeneralSettingsCopyWith<$Res>? get generalSettings;
Expand All @@ -140,6 +149,7 @@ class __$$AriaBackupImplCopyWithImpl<$Res>
Object? accountSettings = freezed,
Object? generalSettings = freezed,
Object? themes = freezed,
Object? aiscriptStorage = freezed,
}) {
return _then(_$AriaBackupImpl(
metadata: freezed == metadata
Expand All @@ -162,6 +172,10 @@ class __$$AriaBackupImplCopyWithImpl<$Res>
? _value._themes
: themes // ignore: cast_nullable_to_non_nullable
as List<String>?,
aiscriptStorage: freezed == aiscriptStorage
? _value._aiscriptStorage
: aiscriptStorage // ignore: cast_nullable_to_non_nullable
as Map<String, Map<String, String>>?,
));
}
}
Expand All @@ -174,11 +188,13 @@ class _$AriaBackupImpl implements _AriaBackup {
final List<TabSettings>? timelineTabs,
final Map<String, AccountSettings>? accountSettings,
this.generalSettings,
final List<String>? themes})
final List<String>? themes,
final Map<String, Map<String, String>>? aiscriptStorage})
: _metadata = metadata,
_timelineTabs = timelineTabs,
_accountSettings = accountSettings,
_themes = themes;
_themes = themes,
_aiscriptStorage = aiscriptStorage;

factory _$AriaBackupImpl.fromJson(Map<String, dynamic> json) =>
_$$AriaBackupImplFromJson(json);
Expand Down Expand Up @@ -225,9 +241,19 @@ class _$AriaBackupImpl implements _AriaBackup {
return EqualUnmodifiableListView(value);
}

final Map<String, Map<String, String>>? _aiscriptStorage;
@override
Map<String, Map<String, String>>? get aiscriptStorage {
final value = _aiscriptStorage;
if (value == null) return null;
if (_aiscriptStorage is EqualUnmodifiableMapView) return _aiscriptStorage;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}

@override
String toString() {
return 'AriaBackup(metadata: $metadata, timelineTabs: $timelineTabs, accountSettings: $accountSettings, generalSettings: $generalSettings, themes: $themes)';
return 'AriaBackup(metadata: $metadata, timelineTabs: $timelineTabs, accountSettings: $accountSettings, generalSettings: $generalSettings, themes: $themes, aiscriptStorage: $aiscriptStorage)';
}

@override
Expand All @@ -242,7 +268,9 @@ class _$AriaBackupImpl implements _AriaBackup {
.equals(other._accountSettings, _accountSettings) &&
(identical(other.generalSettings, generalSettings) ||
other.generalSettings == generalSettings) &&
const DeepCollectionEquality().equals(other._themes, _themes));
const DeepCollectionEquality().equals(other._themes, _themes) &&
const DeepCollectionEquality()
.equals(other._aiscriptStorage, _aiscriptStorage));
}

@JsonKey(ignore: true)
Expand All @@ -253,7 +281,8 @@ class _$AriaBackupImpl implements _AriaBackup {
const DeepCollectionEquality().hash(_timelineTabs),
const DeepCollectionEquality().hash(_accountSettings),
generalSettings,
const DeepCollectionEquality().hash(_themes));
const DeepCollectionEquality().hash(_themes),
const DeepCollectionEquality().hash(_aiscriptStorage));

@JsonKey(ignore: true)
@override
Expand All @@ -271,11 +300,13 @@ class _$AriaBackupImpl implements _AriaBackup {

abstract class _AriaBackup implements AriaBackup {
const factory _AriaBackup(
{final Map<String, dynamic>? metadata,
final List<TabSettings>? timelineTabs,
final Map<String, AccountSettings>? accountSettings,
final GeneralSettings? generalSettings,
final List<String>? themes}) = _$AriaBackupImpl;
{final Map<String, dynamic>? metadata,
final List<TabSettings>? timelineTabs,
final Map<String, AccountSettings>? accountSettings,
final GeneralSettings? generalSettings,
final List<String>? themes,
final Map<String, Map<String, String>>? aiscriptStorage}) =
_$AriaBackupImpl;

factory _AriaBackup.fromJson(Map<String, dynamic> json) =
_$AriaBackupImpl.fromJson;
Expand All @@ -291,6 +322,8 @@ abstract class _AriaBackup implements AriaBackup {
@override
List<String>? get themes;
@override
Map<String, Map<String, String>>? get aiscriptStorage;
@override
@JsonKey(ignore: true)
_$$AriaBackupImplCopyWith<_$AriaBackupImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
4 changes: 4 additions & 0 deletions lib/model/aria_backup.g.dart

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

4 changes: 0 additions & 4 deletions lib/provider/accounts_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import '../model/account.dart';
import 'dio_provider.dart';
import 'emojis_notifier_provider.dart';
import 'shared_preferences_provider.dart';
import 'timeline_tabs_notifier_provider.dart';
import 'tokens_notifier_provider.dart';

part 'accounts_notifier_provider.g.dart';
Expand Down Expand Up @@ -80,9 +79,6 @@ class AccountsNotifier extends _$AccountsNotifier {
}

Future<void> remove(Account account) async {
await ref
.read(timelineTabsNotifierProvider.notifier)
.deleteTabsOfAccount(account);
state = state.where((acct) => acct != account).toList();
await ref.read(tokensNotifierProvider.notifier).remove(account);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/accounts_notifier_provider.g.dart

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

46 changes: 46 additions & 0 deletions lib/provider/aiscript_storage_notifier_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dart:convert';

import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../model/account.dart';
import 'shared_preferences_provider.dart';

part 'aiscript_storage_notifier_provider.g.dart';

@riverpod
class AiscriptStorageNotifier extends _$AiscriptStorageNotifier {
@override
Map<String, String> build(Account account) {
final value = ref.watch(sharedPreferencesProvider).getString(_key);
if (value != null) {
final json = jsonDecode(value);
if (json is Map<String, dynamic>) {
return json.map((key, value) => MapEntry(key, value.toString()));
}
}
return {};
}

String get _key => '$account/aiscript';

Future<void> save(String key, String value) async {
state = {
...state,
key: value,
};
await ref
.read(sharedPreferencesProvider)
.setString(_key, jsonEncode(state));
}

String? load(String key) {
return state[key];
}

Future<void> import(Map<String, String> storage) async {
state = storage;
await ref
.read(sharedPreferencesProvider)
.setString(_key, jsonEncode(state));
}
}
Loading

0 comments on commit 09f3688

Please sign in to comment.