Skip to content

Commit

Permalink
full support reconstruct Image
Browse files Browse the repository at this point in the history
some widget issue when reconstruct image.
  • Loading branch information
appdevelpo committed May 28, 2024
1 parent aa08b95 commit bc29408
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 200 deletions.
45 changes: 32 additions & 13 deletions lib/data/services/extension_service_api_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ExtensionServiceApi2 extends ExtensionService {
);
if (useByteToDecode) {
res.data = utf8.decode(res.data);
} else {}
}
log.requestHeaders = res.requestOptions.headers;
log.responseBody = res.data;
log.responseHeaders = res.headers.map.map(
Expand Down Expand Up @@ -238,12 +238,10 @@ class ExtensionServiceApi2 extends ExtensionService {
String result = to == "utf8"
? utf8.decode(byte, allowMalformed: true)
: typeMap[to]!.decode(byte);
logger.info(result);
return result;
} catch (e) {
return e.toString();
}
;
}

jsQueryXPath(args) {
Expand Down Expand Up @@ -390,7 +388,7 @@ console.log = function (message) {
const package = "${extension.package}";
const name = "${extension.name}";
// 在 load 中注册的 keys
settingKeys = [];
const settingKeys = [];
Expand Down Expand Up @@ -440,7 +438,7 @@ const Miru = {
},
registerSetting: async (settings) => {
console.log(JSON.stringify([settings]));
this.settingKeys.push(settings.key);
settingKeys.push(settings.key);
return await handlePromise("registerSetting$className", JSON.stringify([settings]));
},
getSetting: async (key) => {
Expand Down Expand Up @@ -470,7 +468,7 @@ var checkUpdate = () => {
}
var load = () => { }
async function load() { }
const handlePromise = async (channelName, message) => {
const waitForChange = new Promise(resolve => {
Expand Down Expand Up @@ -538,7 +536,7 @@ console.log = function (message) {
const package = "${extension.package}";
const name = "${extension.name}";
// 在 load 中注册的 keys
settingKeys = [];
const settingKeys = [];
const Miru = {
request: async (url, options) => {
Expand Down Expand Up @@ -594,7 +592,7 @@ const Miru = {
},
registerSetting: async (settings) => {
console.log(JSON.stringify([settings]));
this.settingKeys.push(settings.key);
settingKeys.push(settings.key);
return sendMessage("registerSetting", JSON.stringify([settings]));
},
convert: async (data, from, to) => {
Expand All @@ -619,7 +617,7 @@ var watch = () => {
var checkUpdate = () => {
throw new Error("not implement checkUpdate");
}
var load = () => { }
async function load() { }
const stringify = async (callback) => {
Expand All @@ -630,10 +628,15 @@ const stringify = async (callback) => {
runtime.evaluate('''
$ext
$extScript
if(${Platform.isLinux}){
DartBridge.sendMessage("cleanSettings$className",JSON.stringify([extension.settingKeys]));
}else
{sendMessage("cleanSettings", JSON.stringify([extension.settingKeys]))};
load().then(()=>
{
if (${Platform.isLinux}) {
DartBridge.sendMessage("cleanSettings$className", JSON.stringify([settingKeys]));
} else {
sendMessage("cleanSettings", JSON.stringify([settingKeys]))
}
}
);
''');
}

Expand Down Expand Up @@ -711,6 +714,22 @@ const stringify = async (callback) => {
});
}

Future<List<ReconstructPicVertex>> recompseImage(
int width, int height, int imageIndex) {
return runExtension(() async {
final jsResult = await runtime.handlePromise(
await runtime.evaluateAsync(Platform.isLinux
? 'recomposeImage($width,$height,$imageIndex)'
: 'stringify(()=>recomposeImage($width,$height,$imageIndex))'),
);
final List<ReconstructPicVertex> result = (jsonDecode(
jsResult.stringResult) as List<dynamic>)
.map((e) => ReconstructPicVertex.fromJson(e as Map<String, dynamic>))
.toList();
return result;
});
}

@override
Future<ExtensionDetail> detail(
String url, material.BuildContext context) async {
Expand Down
44 changes: 42 additions & 2 deletions lib/models/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ class ExtensionMangaWatch {
ExtensionMangaWatch({
required this.urls,
this.headers,
this.reconstructKey,
this.needReconstruct,
});

final List<String> urls;
late Map<String, String>? headers;
late List<List<List<int>>>? reconstructKey;
late bool? needReconstruct;
factory ExtensionMangaWatch.fromJson(Map<String, dynamic> json) =>
_$ExtensionMangaWatchFromJson(json);

Expand Down Expand Up @@ -265,3 +265,43 @@ class ExtensionNetworkLog {

Map<String, dynamic> toJson() => _$ExtensionNetworkLogToJson(this);
}

@JsonSerializable()
class ReconstructPicVertex {
final double sx1;
final double sy1;
final double sx2;
final double sy2;
final double dx1;
final double dy1;
final double dx2;
final double dy2;

ReconstructPicVertex({
required this.sx1,
required this.sy1,
required this.sx2,
required this.sy2,
required this.dx1,
required this.dy1,
required this.dx2,
required this.dy2,
});

factory ReconstructPicVertex.fromJson(Map<String, dynamic> json) {
return ReconstructPicVertex(
sx1: json['sx1'].toDouble(),
sy1: json['sy1'].toDouble(),
sx2: json['sx2'].toDouble(),
sy2: json['sy2'].toDouble(),
dx1: json['dx1'].toDouble(),
dy1: json['dy1'].toDouble(),
dx2: json['dx2'].toDouble(),
dy2: json['dy2'].toDouble(),
);
}
@override
String toString() {
return 'ReconstructPicVertex(sx1: $sx1, sy1: $sy1, sx2: $sx2, sy2: $sy2, dx1: $dx1, dy1: $dy1, dx2: $dx2, dy2: $dy2)';
}
}
34 changes: 28 additions & 6 deletions lib/models/extension.g.dart

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

17 changes: 8 additions & 9 deletions lib/views/pages/watch/reader/comic/comic_reader_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@ class _ComicReaderContentState extends State<ComicReaderContent> {
fit: BoxFit.fitWidth,
placeholder: _buildPlaceholder(context),
headers: _c.watchData.value?.headers,
reconstructKey:
(_c.watchData.value?.reconstructKey == null)
? null
: _c.watchData.value
?.reconstructKey![index],
needReconstruct:
_c.watchData.value?.needReconstruct ?? false,
runtime: _c.runtime,
imageIndex: index,
);
},
itemCount: images.length,
Expand Down Expand Up @@ -185,10 +184,10 @@ class _ComicReaderContentState extends State<ComicReaderContent> {
fit: BoxFit.contain,
placeholder: _buildPlaceholder(context),
headers: _c.watchData.value?.headers,
reconstructKey:
(_c.watchData.value?.reconstructKey == null)
? null
: _c.watchData.value?.reconstructKey![index],
needReconstruct:
_c.watchData.value?.needReconstruct ?? false,
imageIndex: index,
runtime: _c.runtime,
),
);
},
Expand Down
Loading

0 comments on commit bc29408

Please sign in to comment.