webview_cef (linux webview) not works in other platforms

This commit is contained in:
DASHU
2025-05-01 21:21:01 +08:00
parent 78e0b83e16
commit 3d02ff8216
11 changed files with 458 additions and 477 deletions

View File

@@ -1,420 +1,420 @@
import 'dart:convert'; // import 'dart:convert';
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:nostr_sdk/event.dart'; // import 'package:nostr_sdk/event.dart';
import 'package:nostr_sdk/utils/string_util.dart'; // import 'package:nostr_sdk/utils/string_util.dart';
import 'package:nowser/component/webview/web_info.dart'; // import 'package:nowser/component/webview/web_info.dart';
import 'package:nowser/const/app_type.dart'; // import 'package:nowser/const/app_type.dart';
import 'package:nowser/const/auth_type.dart'; // import 'package:nowser/const/auth_type.dart';
import 'package:nowser/main.dart'; // import 'package:nowser/main.dart';
import 'package:nowser/provider/permission_check_mixin.dart'; // import 'package:nowser/provider/permission_check_mixin.dart';
import 'package:webview_cef/webview_cef.dart'; // import 'package:webview_cef/webview_cef.dart';
import 'package:webview_cef/src/webview_inject_user_script.dart'; // import 'package:webview_cef/src/webview_inject_user_script.dart';
import '../../data/app.dart'; // import '../../data/app.dart';
class WebViewLinuxComponent extends StatefulWidget { // class WebViewLinuxComponent extends StatefulWidget {
WebInfo webInfo; // WebInfo webInfo;
Function(WebInfo, WebViewController) onWebViewCreated; // Function(WebInfo, WebViewController) onWebViewCreated;
Function(WebInfo, WebViewController, String?) onTitleChanged; // Function(WebInfo, WebViewController, String?) onTitleChanged;
Function(WebInfo, WebViewController, String?) onUrlChanged; // Function(WebInfo, WebViewController, String?) onUrlChanged;
Function(WebInfo, WebViewController) onLoadStop; // Function(WebInfo, WebViewController) onLoadStop;
WebViewLinuxComponent( // WebViewLinuxComponent(
this.webInfo, // this.webInfo,
this.onWebViewCreated, // this.onWebViewCreated,
this.onTitleChanged, // this.onTitleChanged,
this.onUrlChanged, // this.onUrlChanged,
this.onLoadStop, // this.onLoadStop,
); // );
@override // @override
State<StatefulWidget> createState() { // State<StatefulWidget> createState() {
return _WebViewLinuxComponent(); // return _WebViewLinuxComponent();
} // }
} // }
class _WebViewLinuxComponent extends State<WebViewLinuxComponent> // class _WebViewLinuxComponent extends State<WebViewLinuxComponent>
with PermissionCheckMixin { // with PermissionCheckMixin {
late WebViewController controller; // late WebViewController controller;
double progress = 0; // double progress = 0;
Set<JavascriptChannel> javascriptChannels = {}; // Set<JavascriptChannel> javascriptChannels = {};
InjectUserScripts injectScript = InjectUserScripts(); // InjectUserScripts injectScript = InjectUserScripts();
String url = ""; // String url = "";
String title = ""; // String title = "";
@override // @override
void initState() { // void initState() {
super.initState(); // super.initState();
initInjectScript(); // initInjectScript();
initJSHandle(); // initJSHandle();
controller = WebviewManager().createWebView( // controller = WebviewManager().createWebView(
loading: const Text("Loading"), // loading: const Text("Loading"),
injectUserScripts: injectScript); // injectUserScripts: injectScript);
controller.setWebviewListener(WebviewEventsListener( // controller.setWebviewListener(WebviewEventsListener(
onTitleChanged: (title) { // onTitleChanged: (title) {
title = title; // title = title;
widget.onTitleChanged(widget.webInfo, controller, title); // widget.onTitleChanged(widget.webInfo, controller, title);
},
onUrlChanged: (url) {
url = url;
widget.onUrlChanged(widget.webInfo, controller, url);
},
onConsoleMessage: (int level, String message, String source, int line) {
print("$level $source $line $message");
},
// onLoadStart: (controller, url) {
// }, // },
onLoadEnd: (controller, url) { // onUrlChanged: (url) {
widget.onLoadStop(widget.webInfo, controller); // url = url;
}, // widget.onUrlChanged(widget.webInfo, controller, url);
)); // },
// onConsoleMessage: (int level, String message, String source, int line) {
// print("$level $source $line $message");
// },
// // onLoadStart: (controller, url) {
// // },
// onLoadEnd: (controller, url) {
// widget.onLoadStop(widget.webInfo, controller);
// },
// ));
controller.initialize(widget.webInfo.url).then((v) { // controller.initialize(widget.webInfo.url).then((v) {
controller.setJavaScriptChannels(javascriptChannels); // controller.setJavaScriptChannels(javascriptChannels);
setState(() { // setState(() {
inited = true; // inited = true;
}); // });
// controller.openDevTools(); // // controller.openDevTools();
}); // });
} // }
var inited = false; // var inited = false;
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return Container( // return Container(
child: inited ? controller.webviewWidget : controller.loadingWidget, // child: inited ? controller.webviewWidget : controller.loadingWidget,
); // );
} // }
Future<void> nip07Reject(String resultId, String contnet) async { // Future<void> nip07Reject(String resultId, String contnet) async {
var script = "window.nostr.reject(\"$resultId\", \"${contnet}\");"; // var script = "window.nostr.reject(\"$resultId\", \"${contnet}\");";
await controller.executeJavaScript(script); // await controller.executeJavaScript(script);
} // }
void initJSHandle() { // void initJSHandle() {
javascriptChannels.add(JavascriptChannel(name: "NowserJSgetPublicKey", // javascriptChannels.add(JavascriptChannel(name: "NowserJSgetPublicKey",
onMessageReceived: (javascriptMessage) async { // onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message; // var jsMsg = javascriptMessage.message;
print("NowserJSgetPublicKey $jsMsg"); // print("NowserJSgetPublicKey $jsMsg");
var jsonObj = jsonDecode(jsMsg); // var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"]; // var resultId = jsonObj["resultId"];
String? code = await getCode(); // String? code = await getCode();
if (code == null) { // if (code == null) {
return; // return;
} // }
checkPermission(context, AppType.WEB, code, AuthType.GET_PUBLIC_KEY, // checkPermission(context, AppType.WEB, code, AuthType.GET_PUBLIC_KEY,
(app) { // (app) {
nip07Reject(resultId, "Forbid"); // nip07Reject(resultId, "Forbid");
}, (app, signer) { // }, (app, signer) {
print("confirm get pubkey"); // print("confirm get pubkey");
var pubkey = app.pubkey; // var pubkey = app.pubkey;
var script = "window.nostr.callback(\"$resultId\", \"$pubkey\");"; // var script = "window.nostr.callback(\"$resultId\", \"$pubkey\");";
controller.executeJavaScript(script); // controller.executeJavaScript(script);
}); // });
},) // },)
); // );
javascriptChannels.add(JavascriptChannel(name: "NowserJSsignEvent", // javascriptChannels.add(JavascriptChannel(name: "NowserJSsignEvent",
onMessageReceived: (javascriptMessage) async { // onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message; // var jsMsg = javascriptMessage.message;
print("NowserJSsignEvent $jsMsg"); // print("NowserJSsignEvent $jsMsg");
var jsonObj = jsonDecode(jsMsg); // var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"]; // var resultId = jsonObj["resultId"];
var content = jsonObj["msg"]; // var content = jsonObj["msg"];
String? code = await getCode(); // String? code = await getCode();
if (code == null) { // if (code == null) {
return; // return;
} // }
try { // try {
var eventObj = jsonDecode(content); // var eventObj = jsonDecode(content);
var eventKind = eventObj["kind"]; // var eventKind = eventObj["kind"];
if (eventKind is int) { // if (eventKind is int) {
checkPermission(context, AppType.WEB, code, AuthType.SIGN_EVENT, // checkPermission(context, AppType.WEB, code, AuthType.SIGN_EVENT,
eventKind: eventKind, authDetail: content, (app) { // eventKind: eventKind, authDetail: content, (app) {
nip07Reject(resultId, "Forbid"); // nip07Reject(resultId, "Forbid");
}, (app, signer) async { // }, (app, signer) async {
var tags = eventObj["tags"]; // var tags = eventObj["tags"];
Event? event = Event(app.pubkey!, eventObj["kind"], tags ?? [], // Event? event = Event(app.pubkey!, eventObj["kind"], tags ?? [],
eventObj["content"], // eventObj["content"],
createdAt: eventObj["created_at"]); // createdAt: eventObj["created_at"]);
event = await signer.signEvent(event); // event = await signer.signEvent(event);
if (event == null) { // if (event == null) {
return; // return;
} // }
var eventResultStr = jsonEncode(event.toJson()); // var eventResultStr = jsonEncode(event.toJson());
// TODO this method to handle " may be error // // TODO this method to handle " may be error
eventResultStr = eventResultStr.replaceAll("\"", "\\\""); // eventResultStr = eventResultStr.replaceAll("\"", "\\\"");
var script = // var script =
"window.nostr.callback(\"$resultId\", JSON.parse(\"$eventResultStr\"));"; // "window.nostr.callback(\"$resultId\", JSON.parse(\"$eventResultStr\"));";
controller.executeJavaScript(script); // controller.executeJavaScript(script);
}); // });
} // }
} catch (e) { // } catch (e) {
nip07Reject(resultId, "Sign fail"); // nip07Reject(resultId, "Sign fail");
} // }
},) // },)
); // );
javascriptChannels.add(JavascriptChannel(name: "NowserJSgetRelays", // javascriptChannels.add(JavascriptChannel(name: "NowserJSgetRelays",
onMessageReceived: (javascriptMessage) async { // onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message; // var jsMsg = javascriptMessage.message;
print("NowserJSgetRelays $jsMsg"); // print("NowserJSgetRelays $jsMsg");
var jsonObj = jsonDecode(jsMsg); // var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"]; // var resultId = jsonObj["resultId"];
String? code = await getCode(); // String? code = await getCode();
if (code == null) { // if (code == null) {
return; // return;
} // }
checkPermission(context, AppType.WEB, code, AuthType.GET_RELAYS, (app) { // checkPermission(context, AppType.WEB, code, AuthType.GET_RELAYS, (app) {
nip07Reject(resultId, "Forbid"); // nip07Reject(resultId, "Forbid");
}, (app, signer) { // }, (app, signer) {
// TODO handle getRelays // // TODO handle getRelays
// // var app = appProvider.getApp(AppType.WEB, code);
// // if (app != null) {
// // var relayMaps = {};
// // var relayAddrs = relayProvider.relayAddrs;
// // for (var relayAddr in relayAddrs) {
// // relayMaps[relayAddr] = {"read": true, "write": true};
// // }
// // var resultStr = jsonEncode(relayMaps);
// // resultStr = resultStr.replaceAll("\"", "\\\"");
// // var script =
// // "window.nostr.callback(\"$resultId\", JSON.parse(\"$resultStr\"));";
// // webViewController!.evaluateJavascript(source: script);
// // }
// });
// },)
// );
// javascriptChannels.add(JavascriptChannel(name: "NowserJSnip04encrypt",
// onMessageReceived: (javascriptMessage) async {
// var jsMsg = javascriptMessage.message;
// print("NowserJSnip04encrypt $jsMsg");
// var jsonObj = jsonDecode(jsMsg);
// var resultId = jsonObj["resultId"];
// var msg = jsonObj["msg"];
// if (msg != null && msg is Map) {
// var pubkey = msg["pubkey"];
// var plaintext = msg["plaintext"];
// String? code = await getCode();
// if (code == null) {
// return;
// }
// checkPermission(context, AppType.WEB, code, AuthType.NIP04_ENCRYPT,
// (app) {
// nip07Reject(resultId, "Forbid");
// }, (app, signer) async {
// var resultStr = await signer.encrypt(pubkey, plaintext);
// if (StringUtil.isBlank(resultStr)) {
// return;
// }
// var script =
// "window.nostr.callback(\"$resultId\", \"$resultStr\");";
// controller.executeJavaScript(script);
// });
// }
// },)
// );
// javascriptChannels.add(JavascriptChannel(name: "NowserJSnip04decrypt",
// onMessageReceived: (javascriptMessage) async {
// var jsMsg = javascriptMessage.message;
// print("NowserJSnip04decrypt $jsMsg");
// var jsonObj = jsonDecode(jsMsg);
// var resultId = jsonObj["resultId"];
// var msg = jsonObj["msg"];
// if (msg != null && msg is Map) {
// var pubkey = msg["pubkey"];
// var ciphertext = msg["ciphertext"];
// String? code = await getCode();
// if (code == null) {
// return;
// }
// checkPermission(context, AppType.WEB, code, AuthType.NIP04_DECRYPT,
// (app) {
// nip07Reject(resultId, "Forbid");
// }, (app, signer) async {
// var app = appProvider.getApp(AppType.WEB, code); // var app = appProvider.getApp(AppType.WEB, code);
// if (app != null) { // if (app != null) {
// var relayMaps = {}; // var resultStr = await signer.decrypt(pubkey, ciphertext);
// var relayAddrs = relayProvider.relayAddrs; // if (StringUtil.isBlank(resultStr)) {
// for (var relayAddr in relayAddrs) { // return;
// relayMaps[relayAddr] = {"read": true, "write": true};
// } // }
// var resultStr = jsonEncode(relayMaps);
// resultStr = resultStr.replaceAll("\"", "\\\"");
// var script = // var script =
// "window.nostr.callback(\"$resultId\", JSON.parse(\"$resultStr\"));"; // "window.nostr.callback(\"$resultId\", \"$resultStr\");";
// webViewController!.evaluateJavascript(source: script); // controller.executeJavaScript(script);
// } // }
}); // });
},)
);
javascriptChannels.add(JavascriptChannel(name: "NowserJSnip04encrypt",
onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message;
print("NowserJSnip04encrypt $jsMsg");
var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"];
var msg = jsonObj["msg"];
if (msg != null && msg is Map) {
var pubkey = msg["pubkey"];
var plaintext = msg["plaintext"];
String? code = await getCode();
if (code == null) {
return;
}
checkPermission(context, AppType.WEB, code, AuthType.NIP04_ENCRYPT,
(app) {
nip07Reject(resultId, "Forbid");
}, (app, signer) async {
var resultStr = await signer.encrypt(pubkey, plaintext);
if (StringUtil.isBlank(resultStr)) {
return;
}
var script =
"window.nostr.callback(\"$resultId\", \"$resultStr\");";
controller.executeJavaScript(script);
});
}
},)
);
javascriptChannels.add(JavascriptChannel(name: "NowserJSnip04decrypt",
onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message;
print("NowserJSnip04decrypt $jsMsg");
var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"];
var msg = jsonObj["msg"];
if (msg != null && msg is Map) {
var pubkey = msg["pubkey"];
var ciphertext = msg["ciphertext"];
String? code = await getCode();
if (code == null) {
return;
}
checkPermission(context, AppType.WEB, code, AuthType.NIP04_DECRYPT,
(app) {
nip07Reject(resultId, "Forbid");
}, (app, signer) async {
var app = appProvider.getApp(AppType.WEB, code);
if (app != null) {
var resultStr = await signer.decrypt(pubkey, ciphertext);
if (StringUtil.isBlank(resultStr)) {
return;
}
var script =
"window.nostr.callback(\"$resultId\", \"$resultStr\");";
controller.executeJavaScript(script);
}
});
}
},)
);
javascriptChannels.add(JavascriptChannel(name: "NowserJSnip44encrypt",
onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message;
print("NowserJSnip44encrypt $jsMsg");
var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"];
var msg = jsonObj["msg"];
if (msg != null && msg is Map) {
var pubkey = msg["pubkey"];
var plaintext = msg["plaintext"];
String? code = await getCode();
if (code == null) {
return;
}
checkPermission(context, AppType.WEB, code, AuthType.NIP44_ENCRYPT,
(app) {
nip07Reject(resultId, "Forbid");
}, (app, signer) async {
var resultStr = await signer.nip44Encrypt(pubkey, plaintext);
if (StringUtil.isBlank(resultStr)) {
return;
}
var script =
"window.nostr.callback(\"$resultId\", \"$resultStr\");";
controller.executeJavaScript(script);
});
}
},)
);
javascriptChannels.add(JavascriptChannel(name: "NowserJSnip44decrypt",
onMessageReceived: (javascriptMessage) async {
var jsMsg = javascriptMessage.message;
print("NowserJSnip44decrypt $jsMsg");
var jsonObj = jsonDecode(jsMsg);
var resultId = jsonObj["resultId"];
var msg = jsonObj["msg"];
if (msg != null && msg is Map) {
var pubkey = msg["pubkey"];
var ciphertext = msg["ciphertext"];
String? code = await getCode();
if (code == null) {
return;
}
checkPermission(context, AppType.WEB, code, AuthType.NIP44_DECRYPT,
(app) {
nip07Reject(resultId, "Forbid");
}, (app, signer) async {
var resultStr = await signer.nip44Decrypt(pubkey, ciphertext);
if (StringUtil.isBlank(resultStr)) {
return;
}
var script =
"window.nostr.callback(\"$resultId\", \"$resultStr\");";
controller.executeJavaScript(script);
});
}
},)
);
}
void initInjectScript() {
injectScript.add(UserScript("""
window.nostr = {
_call(channel, message) {
return new Promise((resolve, reject) => {
var resultId = "callbackResult_" + Math.floor(Math.random() * 100000000);
var arg = {"resultId": resultId};
if (message) {
arg["msg"] = message;
}
// var argStr = JSON.stringify(arg);
// window.flutter_inappwebview
// .callHandler(channel, argStr);
channel(arg);
window.nostr._requests[resultId] = {resolve, reject}
});
},
_requests: {},
callback(resultId, message) {
window.nostr._requests[resultId].resolve(message);
},
reject(resultId, message) {
window.nostr._requests[resultId].reject(message);
},
async getPublicKey() {
return window.nostr._call(NowserJSgetPublicKey);
},
async signEvent(event) {
return window.nostr._call(NowserJSsignEvent, JSON.stringify(event));
},
async getRelays() {
return window.nostr._call(NowserJSgetRelays);
},
nip04: {
async encrypt(pubkey, plaintext) {
return window.nostr._call(NowserJSnip04encrypt, {"pubkey": pubkey, "plaintext": plaintext});
},
async decrypt(pubkey, ciphertext) {
return window.nostr._call(NowserJSnip04decrypt, {"pubkey": pubkey, "ciphertext": ciphertext});
},
},
nip44: {
async encrypt(pubkey, plaintext) {
return window.nostr._call(NowserJSnip44encrypt, {"pubkey": pubkey, "plaintext": plaintext});
},
async decrypt(pubkey, ciphertext) {
return window.nostr._call(NowserJSnip44decrypt, {"pubkey": pubkey, "ciphertext": ciphertext});
},
},
};
""", ScriptInjectTime.LOAD_START));
// injectScript.add(UserScript("console.log(window.nostr);", ScriptInjectTime.LOAD_END));
}
Future<String?> getCode() async {
if (StringUtil.isBlank(url)) {
url = widget.webInfo.url;
}
if (StringUtil.isNotBlank(url)) {
var uri = Uri.parse(url);
return uri.host;
}
return null;
}
@override
Future<App> getApp(int appType, String code) async {
String? name = title;
String? image;
// var favicons = await webViewController!.getFavicons();
// if (favicons.isNotEmpty) {
// image = favicons.first.url.toString();
// } // }
return App(appType: appType, code: code, name: name, image: image); // },)
} // );
// javascriptChannels.add(JavascriptChannel(name: "NowserJSnip44encrypt",
// onMessageReceived: (javascriptMessage) async {
// var jsMsg = javascriptMessage.message;
// print("NowserJSnip44encrypt $jsMsg");
// var jsonObj = jsonDecode(jsMsg);
// var resultId = jsonObj["resultId"];
// var msg = jsonObj["msg"];
// if (msg != null && msg is Map) {
// var pubkey = msg["pubkey"];
// var plaintext = msg["plaintext"];
@override // String? code = await getCode();
void dispose() { // if (code == null) {
super.dispose(); // return;
controller.dispose(); // }
}
} // checkPermission(context, AppType.WEB, code, AuthType.NIP44_ENCRYPT,
// (app) {
// nip07Reject(resultId, "Forbid");
// }, (app, signer) async {
// var resultStr = await signer.nip44Encrypt(pubkey, plaintext);
// if (StringUtil.isBlank(resultStr)) {
// return;
// }
// var script =
// "window.nostr.callback(\"$resultId\", \"$resultStr\");";
// controller.executeJavaScript(script);
// });
// }
// },)
// );
// javascriptChannels.add(JavascriptChannel(name: "NowserJSnip44decrypt",
// onMessageReceived: (javascriptMessage) async {
// var jsMsg = javascriptMessage.message;
// print("NowserJSnip44decrypt $jsMsg");
// var jsonObj = jsonDecode(jsMsg);
// var resultId = jsonObj["resultId"];
// var msg = jsonObj["msg"];
// if (msg != null && msg is Map) {
// var pubkey = msg["pubkey"];
// var ciphertext = msg["ciphertext"];
// String? code = await getCode();
// if (code == null) {
// return;
// }
// checkPermission(context, AppType.WEB, code, AuthType.NIP44_DECRYPT,
// (app) {
// nip07Reject(resultId, "Forbid");
// }, (app, signer) async {
// var resultStr = await signer.nip44Decrypt(pubkey, ciphertext);
// if (StringUtil.isBlank(resultStr)) {
// return;
// }
// var script =
// "window.nostr.callback(\"$resultId\", \"$resultStr\");";
// controller.executeJavaScript(script);
// });
// }
// },)
// );
// }
// void initInjectScript() {
// injectScript.add(UserScript("""
// window.nostr = {
// _call(channel, message) {
// return new Promise((resolve, reject) => {
// var resultId = "callbackResult_" + Math.floor(Math.random() * 100000000);
// var arg = {"resultId": resultId};
// if (message) {
// arg["msg"] = message;
// }
// // var argStr = JSON.stringify(arg);
// // window.flutter_inappwebview
// // .callHandler(channel, argStr);
// channel(arg);
// window.nostr._requests[resultId] = {resolve, reject}
// });
// },
// _requests: {},
// callback(resultId, message) {
// window.nostr._requests[resultId].resolve(message);
// },
// reject(resultId, message) {
// window.nostr._requests[resultId].reject(message);
// },
// async getPublicKey() {
// return window.nostr._call(NowserJSgetPublicKey);
// },
// async signEvent(event) {
// return window.nostr._call(NowserJSsignEvent, JSON.stringify(event));
// },
// async getRelays() {
// return window.nostr._call(NowserJSgetRelays);
// },
// nip04: {
// async encrypt(pubkey, plaintext) {
// return window.nostr._call(NowserJSnip04encrypt, {"pubkey": pubkey, "plaintext": plaintext});
// },
// async decrypt(pubkey, ciphertext) {
// return window.nostr._call(NowserJSnip04decrypt, {"pubkey": pubkey, "ciphertext": ciphertext});
// },
// },
// nip44: {
// async encrypt(pubkey, plaintext) {
// return window.nostr._call(NowserJSnip44encrypt, {"pubkey": pubkey, "plaintext": plaintext});
// },
// async decrypt(pubkey, ciphertext) {
// return window.nostr._call(NowserJSnip44decrypt, {"pubkey": pubkey, "ciphertext": ciphertext});
// },
// },
// };
// """, ScriptInjectTime.LOAD_START));
// // injectScript.add(UserScript("console.log(window.nostr);", ScriptInjectTime.LOAD_END));
// }
// Future<String?> getCode() async {
// if (StringUtil.isBlank(url)) {
// url = widget.webInfo.url;
// }
// if (StringUtil.isNotBlank(url)) {
// var uri = Uri.parse(url);
// return uri.host;
// }
// return null;
// }
// @override
// Future<App> getApp(int appType, String code) async {
// String? name = title;
// String? image;
// // var favicons = await webViewController!.getFavicons();
// // if (favicons.isNotEmpty) {
// // image = favicons.first.url.toString();
// // }
// return App(appType: appType, code: code, name: name, image: image);
// }
// @override
// void dispose() {
// super.dispose();
// controller.dispose();
// }
// }

View File

@@ -1,70 +1,70 @@
import 'package:webview_cef/webview_cef.dart'; // import 'package:webview_cef/webview_cef.dart';
import 'webview_controller_interface.dart'; // import 'webview_controller_interface.dart';
class WebviewLinuxController extends WebviewControllerInterface { // class WebviewLinuxController extends WebviewControllerInterface {
WebViewController controller; // WebViewController controller;
WebviewLinuxController(this.controller); // WebviewLinuxController(this.controller);
@override // @override
Future<void> reload() async { // Future<void> reload() async {
await controller.reload(); // await controller.reload();
} // }
@override // @override
Future<void> goBack() async { // Future<void> goBack() async {
await controller.goBack(); // await controller.goBack();
} // }
@override // @override
Future<bool> canGoBack() async { // Future<bool> canGoBack() async {
return true; // return true;
} // }
@override // @override
Future<void> goForward() async { // Future<void> goForward() async {
await controller.goForward(); // await controller.goForward();
} // }
@override // @override
Future<Uri?> getUrl() async { // Future<Uri?> getUrl() async {
try { // try {
if (url != null) { // if (url != null) {
return Uri.parse(url!); // return Uri.parse(url!);
} // }
} catch (e) {} // } catch (e) {}
return null; // return null;
} // }
@override // @override
Future<String?> getFavicon() async { // Future<String?> getFavicon() async {
return null; // return null;
} // }
@override // @override
Future<void> loadUrl(String url) async { // Future<void> loadUrl(String url) async {
await controller.loadUrl(url); // await controller.loadUrl(url);
} // }
@override // @override
Future<String?> getTitle() async { // Future<String?> getTitle() async {
return title; // return title;
} // }
String? title; // String? title;
String? url; // String? url;
void setTitle(String title) { // void setTitle(String title) {
title = title; // title = title;
} // }
void setUrl(String url) { // void setUrl(String url) {
url = url; // url = url;
} // }
} // }

View File

@@ -35,7 +35,6 @@ import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart'; import 'package:quick_actions/quick_actions.dart';
import 'package:receive_intent/receive_intent.dart' as receiveIntent; import 'package:receive_intent/receive_intent.dart' as receiveIntent;
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:webview_cef/webview_cef.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
import 'const/base.dart'; import 'const/base.dart';
@@ -107,9 +106,10 @@ Future<void> main() async {
print(e); print(e);
} }
if (Platform.isLinux) { // linux webview, only open in linux platform
WebviewManager().initialize(userAgent: Base.USER_AGENT); // if (Platform.isLinux) {
} // WebviewManager().initialize(userAgent: Base.USER_AGENT);
// }
await doInit(); await doInit();

View File

@@ -80,35 +80,35 @@ class _IndexWebComponent extends State<IndexWebComponent> {
webProvider.onLoadStop(webInfo); webProvider.onLoadStop(webInfo);
}); });
} else { } else {
webComp = WebViewLinuxComponent(webInfo, (webInfo, controller) { // webComp = WebViewLinuxComponent(webInfo, (webInfo, controller) {
webInfo.controller = WebviewLinuxController(controller); // webInfo.controller = WebviewLinuxController(controller);
webProvider.updateWebInfo(webInfo); // webProvider.updateWebInfo(webInfo);
}, (webInfo, controller, title) { // }, (webInfo, controller, title) {
if (webInfo.controller is WebviewLinuxController && // if (webInfo.controller is WebviewLinuxController &&
StringUtil.isNotBlank(title)) { // StringUtil.isNotBlank(title)) {
(webInfo.controller as WebviewLinuxController).setTitle(title!); // (webInfo.controller as WebviewLinuxController).setTitle(title!);
webInfo.title = title; // webInfo.title = title;
webProvider.updateWebInfo(webInfo); // webProvider.updateWebInfo(webInfo);
} // }
}, (webInfo, controller, url) { // }, (webInfo, controller, url) {
if (webInfo.controller is WebviewLinuxController && // if (webInfo.controller is WebviewLinuxController &&
StringUtil.isNotBlank(url)) { // StringUtil.isNotBlank(url)) {
if (url!.startsWith("https")) { // if (url!.startsWith("https")) {
webInfo.isSecure = true; // webInfo.isSecure = true;
} else { // } else {
webInfo.isSecure = false; // webInfo.isSecure = false;
} // }
print("url change! $url"); // print("url change! $url");
(webInfo.controller as WebviewLinuxController).setUrl(url!); // (webInfo.controller as WebviewLinuxController).setUrl(url!);
webInfo.url = url; // webInfo.url = url;
} // }
}, (webInfo, controller) async { // }, (webInfo, controller) async {
webInfo.controller ??= WebviewLinuxController(controller); // webInfo.controller ??= WebviewLinuxController(controller);
var title = await webInfo.controller!.getTitle(); // var title = await webInfo.controller!.getTitle();
webInfo.title = title; // webInfo.title = title;
webProvider.onLoadStop(webInfo); // webProvider.onLoadStop(webInfo);
}); // });
} }
return Container( return Container(

View File

@@ -8,7 +8,6 @@
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h> #include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <screen_retriever_linux/screen_retriever_linux_plugin.h> #include <screen_retriever_linux/screen_retriever_linux_plugin.h>
#include <webview_cef/webview_cef_plugin.h>
#include <window_manager/window_manager_plugin.h> #include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
@@ -18,9 +17,6 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar = g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin");
screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar); screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar);
g_autoptr(FlPluginRegistrar) webview_cef_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WebviewCefPlugin");
webview_cef_plugin_register_with_registrar(webview_cef_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar = g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar); window_manager_plugin_register_with_registrar(window_manager_registrar);

View File

@@ -5,7 +5,6 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux flutter_secure_storage_linux
screen_retriever_linux screen_retriever_linux
webview_cef
window_manager window_manager
) )

View File

@@ -13,7 +13,6 @@ import path_provider_foundation
import screen_retriever_macos import screen_retriever_macos
import shared_preferences_foundation import shared_preferences_foundation
import sqflite_darwin import sqflite_darwin
import webview_cef
import window_manager import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
@@ -25,6 +24,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin")) ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
WebviewCefPlugin.register(with: registry.registrar(forPlugin: "WebviewCefPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
} }

View File

@@ -1137,14 +1137,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.3" version: "3.0.3"
webview_cef:
dependency: "direct main"
description:
name: webview_cef
sha256: "2e660bf593dc1168beb7b765dd477a703e0b29968669f017e178c2c716f6437f"
url: "https://pub.dev"
source: hosted
version: "0.2.2"
win32: win32:
dependency: transitive dependency: transitive
description: description:

View File

@@ -58,7 +58,7 @@ dependencies:
flutter_cache_manager: ^3.4.1 flutter_cache_manager: ^3.4.1
# searchfield: 1.2.0 # searchfield: 1.2.0
searchfield: ^1.2.7 searchfield: ^1.2.7
webview_cef: ^0.2.2 # webview_cef: ^0.2.2
flutter_font_icons: ^2.2.7 flutter_font_icons: ^2.2.7
dev_dependencies: dev_dependencies:

View File

@@ -9,7 +9,6 @@
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h> #include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h> #include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h> #include <screen_retriever_windows/screen_retriever_windows_plugin_c_api.h>
#include <webview_cef/webview_cef_plugin_c_api.h>
#include <window_manager/window_manager_plugin.h> #include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
@@ -19,8 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar( ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi")); registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi"));
WebviewCefPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WebviewCefPluginCApi"));
WindowManagerPluginRegisterWithRegistrar( WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin")); registry->GetRegistrarForPlugin("WindowManagerPlugin"));
} }

View File

@@ -6,7 +6,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_inappwebview_windows flutter_inappwebview_windows
flutter_secure_storage_windows flutter_secure_storage_windows
screen_retriever_windows screen_retriever_windows
webview_cef
window_manager window_manager
) )