Skip to content

Commit

Permalink
chnage flutter_js dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
appdevelpo committed Apr 11, 2024
1 parent c409650 commit 9a151fc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/prbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ jobs:
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
path: "build/linux/x64/release/Miru-App"
path: "build/linux/x64/release/Miru-App"
name: Miru-pr-${{ github.event.pull_request.number }}-linux.zip
45 changes: 28 additions & 17 deletions lib/data/services/extension_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_js/extensions/fetch.dart';
import 'package:get/get.dart';
import 'package:html/dom.dart';
import 'package:html/parser.dart';
Expand All @@ -17,13 +18,14 @@ import 'package:flutter_js/flutter_js.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/data/services/database_service.dart';
import 'package:miru_app/utils/extension.dart';
import 'package:flutter_js/javascriptcore/jscore_runtime.dart';

class ExtensionService {
late JavascriptRuntime runtime;
late Extension extension;
String _cuurentRequestUrl = '';
String evalString = '';
JsBridge? jsBridge;
late JsBridge jsBridge;
static Map<dynamic, dynamic> evalMap = {};
String className = '';
bool isinit = false;
Expand All @@ -39,7 +41,17 @@ class ExtensionService {
final content = file.readAsStringSync();

// 初始化runtime
runtime = getJavascriptRuntime();
if (Platform.isAndroid) {
runtime = QuickJsRuntime2(stackSize: 1024 * 1024);
} else if (Platform.isWindows) {
runtime = QuickJsRuntime2();
} else if (Platform.isLinux) {
runtime = JavascriptCoreRuntime();
} else {
runtime = JavascriptCoreRuntime();
}
runtime.enableFetch();
runtime.enableHandlePromises();
// 注册方法
// 日志
runtime.onMessage('log', (dynamic args) {
Expand Down Expand Up @@ -225,7 +237,7 @@ class ExtensionService {

if (Platform.isLinux) {
jsBridge = JsBridge(jsRuntime: runtime);
jsBridge!.setHandler('request$className', (arg) async {
jsBridge.setHandler('request$className', (arg) async {
final message = jsonDecode(arg);
_cuurentRequestUrl = message[0];
final options = message[1];
Expand Down Expand Up @@ -272,7 +284,7 @@ class ExtensionService {
);
// await runtime
// .handlePromise(await runtime.evaluateAsync(evalMap[package]));
await jsBridge!.sendMessage('request$className', res.data);
await jsBridge.sendMessage('request$className', res.data);
} on DioException catch (e) {
log.url = e.requestOptions.uri.toString();
log.requestHeaders = e.requestOptions.headers;
Expand All @@ -291,7 +303,7 @@ class ExtensionService {
rethrow;
}
});
jsBridge!.setHandler('log$className', (dynamic message) async {
jsBridge.setHandler('log$className', (dynamic message) async {
final args = jsonDecode(message);
logger.info(args[0]);
ExtensionUtils.addLog(
Expand All @@ -300,16 +312,16 @@ class ExtensionService {
args[0],
);
});
jsBridge!.setHandler("getAttributeText$className", (message) async {
jsBridge.setHandler("getAttributeText$className", (message) async {
final args = jsonDecode(message);
final content = args[0];
final selector = args[1];
final attr = args[2];
final doc = parse(content).querySelector(selector);
await jsBridge!
.sendMessage('getAttributeText$className', doc?.attributes[attr]);
await jsBridge.sendMessage(
'getAttributeText$className', doc?.attributes[attr]);
});
jsBridge!.setHandler('querySelectorAll$className',
jsBridge.setHandler('querySelectorAll$className',
(dynamic message) async {
final args = jsonDecode(message);
final content = args["content"];
Expand All @@ -318,9 +330,9 @@ class ExtensionService {
final elements = jsonEncode(doc.map((e) {
return e.outerHtml;
}).toList());
await jsBridge!.sendMessage('querySelectorAll$className', elements);
await jsBridge.sendMessage('querySelectorAll$className', elements);
});
jsBridge!.setHandler('querySelector$className', (message) async {
jsBridge.setHandler('querySelector$className', (message) async {
final args = jsonDecode(message);
final content = args[0];
final selector = args[1];
Expand All @@ -338,13 +350,12 @@ class ExtensionService {
default:
result = doc?.outerHtml ?? '';
}
await jsBridge!.sendMessage('querySelector$className', result);
await jsBridge.sendMessage('querySelector$className', result);
});
jsBridge!.setHandler('registerSetting$className',
(dynamic message) async {
jsBridge.setHandler('registerSetting$className', (dynamic message) async {
final args = jsonDecode(message);
args[0]['package'] = extension.package;
jsBridge!.sendMessage(
jsBridge.sendMessage(
'registerSetting$className',
DatabaseService.registerExtensionSetting(
ExtensionSetting()
Expand All @@ -358,11 +369,11 @@ class ExtensionService {
..options = jsonEncode(args[0]['options']),
));
});
jsBridge!.setHandler('getSetting$className', (dynamic message) async {
jsBridge.setHandler('getSetting$className', (dynamic message) async {
final args = jsonDecode(message);
final setting = await DatabaseService.getExtensionSetting(
extension.package, args[0]);
await jsBridge!.sendMessage(
await jsBridge.sendMessage(
'getSetting$className', setting!.value ?? setting.defaultValue);
});
}
Expand Down
9 changes: 4 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,10 @@ packages:
flutter_js:
dependency: "direct main"
description:
path: "."
ref: miru-app
resolved-ref: da6142d61c51a74dd5ba68daaa18497e51b597e9
url: "https://github.com/appdevelpo/flutter_js.git"
source: git
name: flutter_js
sha256: "5bf5db354fe78fe24cb90a5fa6b4423d38712440c88e3445c3dc88bc134c452f"
url: "https://pub.dev"
source: hosted
version: "0.8.0"
flutter_lints:
dependency: "direct dev"
Expand Down
5 changes: 1 addition & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ dependencies:
flutter_code_editor: ^0.3.0
flutter_highlight: ^0.7.0
flutter_i18n: ^0.35.0
flutter_js:
git:
url: https://github.com/appdevelpo/flutter_js.git
ref: miru-app
flutter_js: ^0.8.0
flutter_markdown: ^0.6.17+1
get: ^4.6.5
go_router: ^13.2.2
Expand Down

0 comments on commit 9a151fc

Please sign in to comment.