Skip to content

Commit

Permalink
chore: backup
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 28, 2023
1 parent 49e77a8 commit ed0e0b4
Show file tree
Hide file tree
Showing 22 changed files with 881 additions and 123 deletions.
8 changes: 8 additions & 0 deletions .phrasey/schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,11 @@ description = "Rose"
[[keys]]
name = "YouCanCloseThisWindow"
description = "You can close this window"

[[keys]]
name = "TenkaRepositories"
description = "Tenka repositories"

[[keys]]
name = "Add"
description = "Add"
2 changes: 2 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ Fuchsia = "Fuchsia"
Pink = "Pink"
Rose = "Rose"
YouCanCloseThisWindow = "You can close this window."
TenkaRepositories = "Tenka repositories"
Add = "Add"
4 changes: 2 additions & 2 deletions lib/core/app/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AppEvent {
@override
int get hashCode => Object.hash(name, data);

static const AppEvent initialized = AppEvent('initialized');
static const AppEvent afterInitialized = AppEvent('after_initialized');
static const AppEvent initializedL1 = AppEvent('initialized_l1');
static const AppEvent initializedL2 = AppEvent('initialized_l2');
static const AppEvent anilistStateChange = AppEvent('anilist_state_change');
static const AppEvent settingsChange = AppEvent('settings_change');
static const AppEvent translationsChange = AppEvent('translations_change');
Expand Down
17 changes: 10 additions & 7 deletions lib/core/app/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import 'package:media_kit/media_kit.dart';
abstract class AppLoader {
static bool ready = false;

static Future<void> initialize() async {
static Future<void> initializeLevel0() async {
await Paths.initialize();
await SettingsDatabase.initialize();
await Translator.initialize();
}

static Future<void> initializeLevel1() async {
await SecureDatabase.initialize();
await CacheDatabase.initialize();
await TenkaManager.initialize();
await Translator.initialize();
await AnilistAuth.initialize();
await InternalServer.initialize();
MediaKit.ensureInitialized();
ready = true;
AppEvents.controller.add(AppEvent.initialized);
await initializeAfterLoad();
AppEvents.controller.add(AppEvent.initializedL1);
await initializeLevel2();
}

static Future<void> initializeAfterLoad() async {
await InternalDeeplink.initializeAfterLoad();
AppEvents.controller.add(AppEvent.afterInitialized);
static Future<void> initializeLevel2() async {
await InternalDeeplink.initialize();
AppEvents.controller.add(AppEvent.initializedL2);
}
}
2 changes: 1 addition & 1 deletion lib/core/internals/deeplink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:uni_links/uni_links.dart' as uni_links;
abstract class InternalDeeplink {
static String? initialLink;

static Future<void> initializeAfterLoad() async {
static Future<void> initialize() async {
if (Platform.isAndroid) {
final String? path = await uni_links.getInitialLink();
if (path != null) handle(path);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/packages.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export 'dart:ui' show ImageFilter;
export 'package:animations/animations.dart';
export 'package:flutter/material.dart' hide Locale;
export 'package:flutter/widgets.dart' hide Locale;
export 'package:provider/provider.dart';
export 'package:provider/single_child_widget.dart';
export 'package:url_launcher/url_launcher.dart'
Expand Down
3 changes: 3 additions & 0 deletions lib/core/tenka/manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ abstract class TenkaManager {
static Future<void> uninstallStore(final String storeUrl) =>
repository.uninstall(storeUrl);

static Iterable<String> allStoresIterable() => repository.installed.keys;
static List<String> allStores() => allStoresIterable().toList();

static TenkaStoreRepository? findStoreFromMetadataId(
final String metadataId,
) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:kazahana/core/internals/exports.dart';
import 'package:kazahana/ui/exports.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/ui/pages/anilist/components/body/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class AnilistPageLoginBody extends StatelessWidget {
if (!didLaunch) {
throw Exception('Failed to launch URL');
}
} catch (err) {
} catch (error) {
if (!context.mounted) return;
Toast(
content: Text('${context.t.somethingWentWrong} $err'),
content: Text('${context.t.somethingWentWrong} $error'),
).show();
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/home/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
AppLoader.initialize().then((final _) async {
AppLoader.initializeLevel1().then((final _) async {
if (mounted) {
setState(() {});
}
Expand Down
1 change: 1 addition & 0 deletions lib/ui/pages/modules/components/exports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'tenka_repositories_dialog.dart';
115 changes: 115 additions & 0 deletions lib/ui/pages/modules/components/tenka_repositories_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:kazahana/core/exports.dart';
import 'package:kazahana/ui/exports.dart';
import 'package:kazahana/ui/pages/modules/provider.dart';

class ModulesPageTenkaRepositoriesDialog extends StatefulWidget {
const ModulesPageTenkaRepositoriesDialog({
required this.provider,
super.key,
});

final ModulesPageProvider provider;

@override
State<ModulesPageTenkaRepositoriesDialog> createState() =>
_ModulesPageTenkaRepositoriesDialogState();
}

class _ModulesPageTenkaRepositoriesDialogState
extends State<ModulesPageTenkaRepositoriesDialog> {
late TextEditingController textEditingController;
bool showTextInput = false;
bool hasTextInput = false;

@override
void initState() {
super.initState();
textEditingController = TextEditingController();
}

@override
void dispose() {
super.dispose();
textEditingController.dispose();
}

@override
Widget build(final BuildContext context) => Dialog(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: HorizontalBodyPadding.paddingValue(context),
vertical: context.r.scale(0.5),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
context.t.tenkaRepositories,
style: Theme.of(context).textTheme.headlineSmall,
),
...TenkaManager.allStoresIterable().map(
(final String x) => ListTile(
title: Text(x),
trailing: IconButton(
onPressed: () {
widget.provider.uninstallTenkaStore(x);
},
icon: const Icon(Icons.close),
),
),
),
if (showTextInput)
LayoutBuilder(
builder: (
final BuildContext context,
final BoxConstraints constraints,
) =>
SizedBox(
width: constraints.minWidth,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
controller: textEditingController,
onChanged: (final String text) {
setState(() {
hasTextInput = text.isNotEmpty;
});
},
),
IconButton(
onPressed: () {
if (hasTextInput) {
widget.provider.installTenkaStore(
textEditingController.text);
}
textEditingController.text = '';
showTextInput = false;
},
icon:
Icon(hasTextInput ? Icons.check : Icons.close),
),
],
),
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextButton(
onPressed: () {
setState(() {
showTextInput = !showTextInput;
});
},
child: Text(context.t.add),
),
],
),
],
),
),
),
);
}
24 changes: 22 additions & 2 deletions lib/ui/pages/modules/provider.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import 'package:kazahana/core/exports.dart';
import 'package:kazahana/ui/exports.dart';

class ModulesPageProvider extends StatedChangeNotifier {
final Set<String> installing = <String>{};
final Set<String> uninstalling = <String>{};

Future<void> install(final TenkaMetadata metadata) async {
Future<void> installTenkaStore(final String storeUrl) async {
try {
await TenkaManager.installStore(storeUrl);
} catch (error) {
Toast(
content:
Text('${Translator.currentTranslation.somethingWentWrong} $error'),
).show();
}
if (!mounted) return;
notifyListeners();
}

Future<void> uninstallTenkaStore(final String storeUrl) async {
await TenkaManager.uninstallStore(storeUrl);
if (!mounted) return;
notifyListeners();
}

Future<void> installTenkaModule(final TenkaMetadata metadata) async {
installing.add(metadata.id);
notifyListeners();
await TenkaManager.installModule(metadata);
Expand All @@ -13,7 +33,7 @@ class ModulesPageProvider extends StatedChangeNotifier {
notifyListeners();
}

Future<void> uninstall(final TenkaMetadata metadata) async {
Future<void> uninstallTenkaModule(final TenkaMetadata metadata) async {
uninstalling.add(metadata.id);
notifyListeners();
await TenkaManager.uninstallModule(metadata);
Expand Down
22 changes: 19 additions & 3 deletions lib/ui/pages/modules/view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:kazahana/core/exports.dart';
import 'package:kazahana/ui/exports.dart';
import 'package:kazahana/ui/pages/modules/components/exports.dart';
import 'package:kazahana/ui/pages/modules/provider.dart';

class ModulesPage extends StatelessWidget {
Expand All @@ -13,10 +14,10 @@ class ModulesPage extends StatelessWidget {
}) =>
() {
if (TenkaManager.isModuleInstalled(metadata)) {
provider.uninstall(metadata);
provider.uninstallTenkaModule(metadata);
return;
}
provider.install(metadata);
provider.installTenkaModule(metadata);
};

Widget buildModuleTile({
Expand Down Expand Up @@ -104,7 +105,22 @@ class ModulesPage extends StatelessWidget {
final _,
) =>
Scaffold(
appBar: AppBar(title: Text(context.t.modules)),
appBar: AppBar(
title: Text(context.t.modules),
actions: <Widget>[
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (final _) => ModulesPageTenkaRepositoriesDialog(
provider: provider,
),
);
},
icon: const Icon(Icons.settings),
),
],
),
body: SingleChildScrollView(
child: Column(
children: TenkaManager.allModulesIterable()
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/pages/search/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class SearchPageProvider extends StatedChangeNotifier {
await AnilistMediaEndpoints.search(terms),
),
);
} catch (err, trace) {
results.fail(err, trace);
} catch (error, stackTrace) {
results.fail(error, stackTrace);
}
if (!mounted) return;
notifyListeners();
Expand Down
6 changes: 2 additions & 4 deletions lib/ui/pages/view/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ class ViewPageProvider extends StatedChangeNotifier {
notifyListeners();
return;
}

await fetch();
}

Future<void> fetch() async {
media.loading();
notifyListeners();

try {
media.finish(await AnilistMediaEndpoints.fetchId(mediaId));
await media.value.fetchAll();
} catch (err, trace) {
media.fail(err, trace);
} catch (error, stackTrace) {
media.fail(error, stackTrace);
}
if (!mounted) return;
notifyListeners();
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/utils/exports.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export 'animations.dart';
export 'placeholders.dart';
export 'relative_scale.dart';
export 'themer.dart';
export 'text_theme.dart';
export 'theme.dart';
export 'themes.dart';
export 'translations.dart';
Loading

0 comments on commit ed0e0b4

Please sign in to comment.