Skip to content

Commit

Permalink
Simplify entry API
Browse files Browse the repository at this point in the history
  • Loading branch information
r52 committed Sep 10, 2024
1 parent 349635e commit c390e71
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
2 changes: 0 additions & 2 deletions lib/web/eval/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class WebSourcePlugin implements EvalPlugin {
$WebChapter.configureForCompile(registry);
$WebManga.configureForCompile(registry);
$HistoryLink.configureForCompile(registry);
$WebSourceInfo.configureForCompile(registry);
// html
$Document.configureForCompile(registry);
$Element.configureForCompile(registry);
Expand Down Expand Up @@ -49,7 +48,6 @@ class WebSourcePlugin implements EvalPlugin {
$WebChapter.configureForRuntime(runtime);
$WebManga.configureForRuntime(runtime);
$HistoryLink.configureForRuntime(runtime);
$WebSourceInfo.configureForRuntime(runtime);
//html
$Document.configureForRuntime(runtime);
$Element.configureForRuntime(runtime);
Expand Down
2 changes: 2 additions & 0 deletions lib/web/eval/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:dart_eval/src/eval/utils/wap_helper.dart';
import 'package:gagaku/web/eval/util.dart';
import 'package:gagaku/web/model/types.dart';

/*
class $WebSourceInfo implements $Instance {
static void configureForCompile(BridgeDeclarationRegistry registry) {
registry.defineBridgeClass($declaration);
Expand Down Expand Up @@ -112,6 +113,7 @@ class $WebSourceInfo implements $Instance {
@override
int $getRuntimeType(Runtime runtime) => runtime.lookupType($type.spec!);
}
*/

class $HistoryLink implements $Instance {
static void configureForCompile(BridgeDeclarationRegistry registry) {
Expand Down
10 changes: 7 additions & 3 deletions lib/web/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import 'dart:io';

import 'package:dart_eval/dart_eval.dart';
import 'package:dart_eval/dart_eval_security.dart';
import 'package:dart_eval/stdlib/core.dart';
import 'package:flutter/material.dart';
import 'package:gagaku/cache.dart';
import 'package:gagaku/http.dart';
import 'package:gagaku/log.dart';
import 'package:gagaku/model.dart';
import 'package:gagaku/util.dart';
import 'package:gagaku/web/eval/plugin.dart';
import 'package:gagaku/web/eval/types.dart';
import 'package:gagaku/web/eval/util.dart';
import 'package:gagaku/web/model/config.dart';
import 'package:gagaku/web/model/types.dart';
Expand Down Expand Up @@ -600,8 +600,12 @@ class WebSourceManager extends _$WebSourceManager {
final source = WebSource(runtime: runtime);

for (final key in sourcefiles.keys) {
final info =
(runtime.executeLib('${GagakuWebSources.getPackagePath}/$key', 'getSourceInfo') as $WebSourceInfo).$value;
final result =
(runtime.executeLib('${GagakuWebSources.getPackagePath}/$key', 'getSourceInfo') as $String).$value;

final Map<String, dynamic> dat = json.decode(result);
final info = WebSourceInfo.fromJson(dat);

source.sources.putIfAbsent(key, () => info);
runtime.grant(NetworkPermission.url(info.baseUrl));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web/model/model.g.dart

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

2 changes: 2 additions & 0 deletions lib/web/model/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ class WebSourceInfo with _$WebSourceInfo {
required String manga,
required String pages,
}) = _WebSourceInfo;

factory WebSourceInfo.fromJson(Map<String, dynamic> json) => _$WebSourceInfoFromJson(json);
}

@freezed
Expand Down
23 changes: 22 additions & 1 deletion lib/web/model/types.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,10 @@ abstract class _ImgurPage implements ImgurPage {
throw _privateConstructorUsedError;
}

WebSourceInfo _$WebSourceInfoFromJson(Map<String, dynamic> json) {
return _WebSourceInfo.fromJson(json);
}

/// @nodoc
mixin _$WebSourceInfo {
String get name => throw _privateConstructorUsedError;
Expand All @@ -1128,6 +1132,9 @@ mixin _$WebSourceInfo {
String get manga => throw _privateConstructorUsedError;
String get pages => throw _privateConstructorUsedError;

/// Serializes this WebSourceInfo to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

/// Create a copy of WebSourceInfo
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
Expand Down Expand Up @@ -1280,7 +1287,7 @@ class __$$WebSourceInfoImplCopyWithImpl<$Res>
}

/// @nodoc
@JsonSerializable()
class _$WebSourceInfoImpl implements _WebSourceInfo {
const _$WebSourceInfoImpl(
{required this.name,
Expand All @@ -1291,6 +1298,9 @@ class _$WebSourceInfoImpl implements _WebSourceInfo {
required this.manga,
required this.pages});

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

@override
final String name;
@override
Expand Down Expand Up @@ -1326,6 +1336,7 @@ class _$WebSourceInfoImpl implements _WebSourceInfo {
(identical(other.pages, pages) || other.pages == pages));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType, name, version, baseUrl, mangaPath, search, manga, pages);
Expand All @@ -1337,6 +1348,13 @@ class _$WebSourceInfoImpl implements _WebSourceInfo {
@pragma('vm:prefer-inline')
_$$WebSourceInfoImplCopyWith<_$WebSourceInfoImpl> get copyWith =>
__$$WebSourceInfoImplCopyWithImpl<_$WebSourceInfoImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$WebSourceInfoImplToJson(
this,
);
}
}

abstract class _WebSourceInfo implements WebSourceInfo {
Expand All @@ -1349,6 +1367,9 @@ abstract class _WebSourceInfo implements WebSourceInfo {
required final String manga,
required final String pages}) = _$WebSourceInfoImpl;

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

@override
String get name;
@override
Expand Down
22 changes: 22 additions & 0 deletions lib/web/model/types.g.dart

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

4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9"
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
url: "https://pub.dev"
source: hosted
version: "2.3.6"
version: "2.3.7"
device_info_plus:
dependency: "direct main"
description:
Expand Down

0 comments on commit c390e71

Please sign in to comment.