feat: Replace desktop_webview_window with tao&wry , from tauri

This commit is contained in:
xkeyC
2025-12-05 01:29:48 +08:00
parent 125fedbc84
commit 6f0c760ab4
31 changed files with 6894 additions and 539 deletions

View File

@@ -0,0 +1,142 @@
// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.11.1.
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;
part 'webview_api.freezed.dart';
// These functions are ignored because they are not marked as `pub`: `handle_command`, `load_app_icon`, `run_webview_loop`, `send_command`
// These types are ignored because they are neither used by any `pub` functions nor (for structs and enums) marked `#[frb(unignore)]`: `UserEvent`, `WebViewCommand`, `WebViewInstance`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `clone`, `clone`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`
/// Create a new WebView window and return its ID
String webviewCreate({required WebViewConfiguration config}) =>
RustLib.instance.api.crateApiWebviewApiWebviewCreate(config: config);
/// Navigate to a URL
void webviewNavigate({required String id, required String url}) =>
RustLib.instance.api.crateApiWebviewApiWebviewNavigate(id: id, url: url);
/// Go back in history
void webviewGoBack({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewGoBack(id: id);
/// Go forward in history
void webviewGoForward({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewGoForward(id: id);
/// Reload the current page
void webviewReload({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewReload(id: id);
/// Stop loading
void webviewStop({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewStop(id: id);
/// Execute JavaScript in the WebView
void webviewExecuteScript({required String id, required String script}) =>
RustLib.instance.api.crateApiWebviewApiWebviewExecuteScript(
id: id,
script: script,
);
/// Set window visibility
void webviewSetVisibility({required String id, required bool visible}) =>
RustLib.instance.api.crateApiWebviewApiWebviewSetVisibility(
id: id,
visible: visible,
);
/// Close the WebView window
void webviewClose({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewClose(id: id);
/// Set window size
void webviewSetWindowSize({
required String id,
required int width,
required int height,
}) => RustLib.instance.api.crateApiWebviewApiWebviewSetWindowSize(
id: id,
width: width,
height: height,
);
/// Set window position
void webviewSetWindowPosition({
required String id,
required int x,
required int y,
}) => RustLib.instance.api.crateApiWebviewApiWebviewSetWindowPosition(
id: id,
x: x,
y: y,
);
/// Get the current navigation state
WebViewNavigationState webviewGetState({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewGetState(id: id);
/// Check if the WebView is closed
bool webviewIsClosed({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewIsClosed(id: id);
/// Poll for events from the WebView (non-blocking)
List<WebViewEvent> webviewPollEvents({required String id}) =>
RustLib.instance.api.crateApiWebviewApiWebviewPollEvents(id: id);
/// Get a list of all active WebView IDs
List<String> webviewListAll() =>
RustLib.instance.api.crateApiWebviewApiWebviewListAll();
/// WebView window configuration
@freezed
sealed class WebViewConfiguration with _$WebViewConfiguration {
const WebViewConfiguration._();
const factory WebViewConfiguration({
required String title,
required int width,
required int height,
String? userDataFolder,
required bool enableDevtools,
required bool transparent,
String? userAgent,
}) = _WebViewConfiguration;
static Future<WebViewConfiguration> default_() =>
RustLib.instance.api.crateApiWebviewApiWebViewConfigurationDefault();
}
@freezed
sealed class WebViewEvent with _$WebViewEvent {
const WebViewEvent._();
const factory WebViewEvent.navigationStarted({required String url}) =
WebViewEvent_NavigationStarted;
const factory WebViewEvent.navigationCompleted({required String url}) =
WebViewEvent_NavigationCompleted;
const factory WebViewEvent.titleChanged({required String title}) =
WebViewEvent_TitleChanged;
const factory WebViewEvent.webMessage({required String message}) =
WebViewEvent_WebMessage;
const factory WebViewEvent.windowClosed() = WebViewEvent_WindowClosed;
const factory WebViewEvent.error({required String message}) =
WebViewEvent_Error;
}
/// Navigation state of the WebView
@freezed
sealed class WebViewNavigationState with _$WebViewNavigationState {
const WebViewNavigationState._();
const factory WebViewNavigationState({
required String url,
required String title,
required bool canGoBack,
required bool canGoForward,
required bool isLoading,
}) = _WebViewNavigationState;
static Future<WebViewNavigationState> default_() =>
RustLib.instance.api.crateApiWebviewApiWebViewNavigationStateDefault();
}

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
// These functions are ignored because they are not marked as `pub`: `get_process_path`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `fmt`
Future<void> sendNotify({

View File

@@ -8,6 +8,7 @@ import 'api/http_api.dart';
import 'api/ort_api.dart';
import 'api/rs_process.dart';
import 'api/unp4k_api.dart';
import 'api/webview_api.dart';
import 'api/win32_api.dart';
import 'dart:async';
import 'dart:convert';
@@ -70,7 +71,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.11.1';
@override
int get rustContentHash => 1801517256;
int get rustContentHash => -1082688871;
static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
@@ -175,6 +176,62 @@ abstract class RustLibApi extends BaseApi {
Future<void> crateApiOrtApiUnloadTranslationModel({required String modelKey});
Future<WebViewConfiguration> crateApiWebviewApiWebViewConfigurationDefault();
Future<WebViewNavigationState>
crateApiWebviewApiWebViewNavigationStateDefault();
void crateApiWebviewApiWebviewClose({required String id});
String crateApiWebviewApiWebviewCreate({
required WebViewConfiguration config,
});
void crateApiWebviewApiWebviewExecuteScript({
required String id,
required String script,
});
WebViewNavigationState crateApiWebviewApiWebviewGetState({
required String id,
});
void crateApiWebviewApiWebviewGoBack({required String id});
void crateApiWebviewApiWebviewGoForward({required String id});
bool crateApiWebviewApiWebviewIsClosed({required String id});
List<String> crateApiWebviewApiWebviewListAll();
void crateApiWebviewApiWebviewNavigate({
required String id,
required String url,
});
List<WebViewEvent> crateApiWebviewApiWebviewPollEvents({required String id});
void crateApiWebviewApiWebviewReload({required String id});
void crateApiWebviewApiWebviewSetVisibility({
required String id,
required bool visible,
});
void crateApiWebviewApiWebviewSetWindowPosition({
required String id,
required int x,
required int y,
});
void crateApiWebviewApiWebviewSetWindowSize({
required String id,
required int width,
required int height,
});
void crateApiWebviewApiWebviewStop({required String id});
Future<void> crateApiRsProcessWrite({
required int rsPid,
required String data,
@@ -893,6 +950,451 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["modelKey"],
);
@override
Future<WebViewConfiguration> crateApiWebviewApiWebViewConfigurationDefault() {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
return wire
.wire__crate__api__webview_api__web_view_configuration_default(
port_,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_web_view_configuration,
decodeErrorData: null,
),
constMeta: kCrateApiWebviewApiWebViewConfigurationDefaultConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebViewConfigurationDefaultConstMeta =>
const TaskConstMeta(
debugName: "web_view_configuration_default",
argNames: [],
);
@override
Future<WebViewNavigationState>
crateApiWebviewApiWebViewNavigationStateDefault() {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
return wire
.wire__crate__api__webview_api__web_view_navigation_state_default(
port_,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_web_view_navigation_state,
decodeErrorData: null,
),
constMeta: kCrateApiWebviewApiWebViewNavigationStateDefaultConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebViewNavigationStateDefaultConstMeta =>
const TaskConstMeta(
debugName: "web_view_navigation_state_default",
argNames: [],
);
@override
void crateApiWebviewApiWebviewClose({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_close(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewCloseConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewCloseConstMeta =>
const TaskConstMeta(debugName: "webview_close", argNames: ["id"]);
@override
String crateApiWebviewApiWebviewCreate({
required WebViewConfiguration config,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_box_autoadd_web_view_configuration(config);
return wire.wire__crate__api__webview_api__webview_create(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_String,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewCreateConstMeta,
argValues: [config],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewCreateConstMeta =>
const TaskConstMeta(debugName: "webview_create", argNames: ["config"]);
@override
void crateApiWebviewApiWebviewExecuteScript({
required String id,
required String script,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
var arg1 = cst_encode_String(script);
return wire.wire__crate__api__webview_api__webview_execute_script(
arg0,
arg1,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewExecuteScriptConstMeta,
argValues: [id, script],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewExecuteScriptConstMeta =>
const TaskConstMeta(
debugName: "webview_execute_script",
argNames: ["id", "script"],
);
@override
WebViewNavigationState crateApiWebviewApiWebviewGetState({
required String id,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_get_state(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_web_view_navigation_state,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewGetStateConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewGetStateConstMeta =>
const TaskConstMeta(debugName: "webview_get_state", argNames: ["id"]);
@override
void crateApiWebviewApiWebviewGoBack({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_go_back(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewGoBackConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewGoBackConstMeta =>
const TaskConstMeta(debugName: "webview_go_back", argNames: ["id"]);
@override
void crateApiWebviewApiWebviewGoForward({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_go_forward(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewGoForwardConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewGoForwardConstMeta =>
const TaskConstMeta(debugName: "webview_go_forward", argNames: ["id"]);
@override
bool crateApiWebviewApiWebviewIsClosed({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_is_closed(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_bool,
decodeErrorData: null,
),
constMeta: kCrateApiWebviewApiWebviewIsClosedConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewIsClosedConstMeta =>
const TaskConstMeta(debugName: "webview_is_closed", argNames: ["id"]);
@override
List<String> crateApiWebviewApiWebviewListAll() {
return handler.executeSync(
SyncTask(
callFfi: () {
return wire.wire__crate__api__webview_api__webview_list_all();
},
codec: DcoCodec(
decodeSuccessData: dco_decode_list_String,
decodeErrorData: null,
),
constMeta: kCrateApiWebviewApiWebviewListAllConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewListAllConstMeta =>
const TaskConstMeta(debugName: "webview_list_all", argNames: []);
@override
void crateApiWebviewApiWebviewNavigate({
required String id,
required String url,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
var arg1 = cst_encode_String(url);
return wire.wire__crate__api__webview_api__webview_navigate(
arg0,
arg1,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewNavigateConstMeta,
argValues: [id, url],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewNavigateConstMeta =>
const TaskConstMeta(
debugName: "webview_navigate",
argNames: ["id", "url"],
);
@override
List<WebViewEvent> crateApiWebviewApiWebviewPollEvents({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_poll_events(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_list_web_view_event,
decodeErrorData: null,
),
constMeta: kCrateApiWebviewApiWebviewPollEventsConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewPollEventsConstMeta =>
const TaskConstMeta(debugName: "webview_poll_events", argNames: ["id"]);
@override
void crateApiWebviewApiWebviewReload({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_reload(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewReloadConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewReloadConstMeta =>
const TaskConstMeta(debugName: "webview_reload", argNames: ["id"]);
@override
void crateApiWebviewApiWebviewSetVisibility({
required String id,
required bool visible,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
var arg1 = cst_encode_bool(visible);
return wire.wire__crate__api__webview_api__webview_set_visibility(
arg0,
arg1,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewSetVisibilityConstMeta,
argValues: [id, visible],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewSetVisibilityConstMeta =>
const TaskConstMeta(
debugName: "webview_set_visibility",
argNames: ["id", "visible"],
);
@override
void crateApiWebviewApiWebviewSetWindowPosition({
required String id,
required int x,
required int y,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
var arg1 = cst_encode_i_32(x);
var arg2 = cst_encode_i_32(y);
return wire
.wire__crate__api__webview_api__webview_set_window_position(
arg0,
arg1,
arg2,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewSetWindowPositionConstMeta,
argValues: [id, x, y],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewSetWindowPositionConstMeta =>
const TaskConstMeta(
debugName: "webview_set_window_position",
argNames: ["id", "x", "y"],
);
@override
void crateApiWebviewApiWebviewSetWindowSize({
required String id,
required int width,
required int height,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
var arg1 = cst_encode_u_32(width);
var arg2 = cst_encode_u_32(height);
return wire.wire__crate__api__webview_api__webview_set_window_size(
arg0,
arg1,
arg2,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewSetWindowSizeConstMeta,
argValues: [id, width, height],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewSetWindowSizeConstMeta =>
const TaskConstMeta(
debugName: "webview_set_window_size",
argNames: ["id", "width", "height"],
);
@override
void crateApiWebviewApiWebviewStop({required String id}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(id);
return wire.wire__crate__api__webview_api__webview_stop(arg0);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_String,
),
constMeta: kCrateApiWebviewApiWebviewStopConstMeta,
argValues: [id],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiWebviewApiWebviewStopConstMeta =>
const TaskConstMeta(debugName: "webview_stop", argNames: ["id"]);
@override
Future<void> crateApiRsProcessWrite({
required int rsPid,
@@ -974,6 +1476,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return dco_decode_u_64(raw);
}
@protected
WebViewConfiguration dco_decode_box_autoadd_web_view_configuration(
dynamic raw,
) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return dco_decode_web_view_configuration(raw);
}
@protected
int dco_decode_i_32(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -1022,6 +1532,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return (raw as List<dynamic>).map(dco_decode_record_string_string).toList();
}
@protected
List<WebViewEvent> dco_decode_list_web_view_event(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return (raw as List<dynamic>).map(dco_decode_web_view_event).toList();
}
@protected
MyHttpVersion dco_decode_my_http_version(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -1187,6 +1703,59 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return dcoDecodeU64(raw);
}
@protected
WebViewConfiguration dco_decode_web_view_configuration(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 7)
throw Exception('unexpected arr length: expect 7 but see ${arr.length}');
return WebViewConfiguration(
title: dco_decode_String(arr[0]),
width: dco_decode_u_32(arr[1]),
height: dco_decode_u_32(arr[2]),
userDataFolder: dco_decode_opt_String(arr[3]),
enableDevtools: dco_decode_bool(arr[4]),
transparent: dco_decode_bool(arr[5]),
userAgent: dco_decode_opt_String(arr[6]),
);
}
@protected
WebViewEvent dco_decode_web_view_event(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
switch (raw[0]) {
case 0:
return WebViewEvent_NavigationStarted(url: dco_decode_String(raw[1]));
case 1:
return WebViewEvent_NavigationCompleted(url: dco_decode_String(raw[1]));
case 2:
return WebViewEvent_TitleChanged(title: dco_decode_String(raw[1]));
case 3:
return WebViewEvent_WebMessage(message: dco_decode_String(raw[1]));
case 4:
return WebViewEvent_WindowClosed();
case 5:
return WebViewEvent_Error(message: dco_decode_String(raw[1]));
default:
throw Exception("unreachable");
}
}
@protected
WebViewNavigationState dco_decode_web_view_navigation_state(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
final arr = raw as List<dynamic>;
if (arr.length != 5)
throw Exception('unexpected arr length: expect 5 but see ${arr.length}');
return WebViewNavigationState(
url: dco_decode_String(arr[0]),
title: dco_decode_String(arr[1]),
canGoBack: dco_decode_bool(arr[2]),
canGoForward: dco_decode_bool(arr[3]),
isLoading: dco_decode_bool(arr[4]),
);
}
@protected
AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -1245,6 +1814,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return (sse_decode_u_64(deserializer));
}
@protected
WebViewConfiguration sse_decode_box_autoadd_web_view_configuration(
SseDeserializer deserializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
return (sse_decode_web_view_configuration(deserializer));
}
@protected
int sse_decode_i_32(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -1323,6 +1900,20 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return ans_;
}
@protected
List<WebViewEvent> sse_decode_list_web_view_event(
SseDeserializer deserializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
var len_ = sse_decode_i_32(deserializer);
var ans_ = <WebViewEvent>[];
for (var idx_ = 0; idx_ < len_; ++idx_) {
ans_.add(sse_decode_web_view_event(deserializer));
}
return ans_;
}
@protected
MyHttpVersion sse_decode_my_http_version(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -1525,6 +2116,76 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return deserializer.buffer.getBigUint64();
}
@protected
WebViewConfiguration sse_decode_web_view_configuration(
SseDeserializer deserializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_title = sse_decode_String(deserializer);
var var_width = sse_decode_u_32(deserializer);
var var_height = sse_decode_u_32(deserializer);
var var_userDataFolder = sse_decode_opt_String(deserializer);
var var_enableDevtools = sse_decode_bool(deserializer);
var var_transparent = sse_decode_bool(deserializer);
var var_userAgent = sse_decode_opt_String(deserializer);
return WebViewConfiguration(
title: var_title,
width: var_width,
height: var_height,
userDataFolder: var_userDataFolder,
enableDevtools: var_enableDevtools,
transparent: var_transparent,
userAgent: var_userAgent,
);
}
@protected
WebViewEvent sse_decode_web_view_event(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
var tag_ = sse_decode_i_32(deserializer);
switch (tag_) {
case 0:
var var_url = sse_decode_String(deserializer);
return WebViewEvent_NavigationStarted(url: var_url);
case 1:
var var_url = sse_decode_String(deserializer);
return WebViewEvent_NavigationCompleted(url: var_url);
case 2:
var var_title = sse_decode_String(deserializer);
return WebViewEvent_TitleChanged(title: var_title);
case 3:
var var_message = sse_decode_String(deserializer);
return WebViewEvent_WebMessage(message: var_message);
case 4:
return WebViewEvent_WindowClosed();
case 5:
var var_message = sse_decode_String(deserializer);
return WebViewEvent_Error(message: var_message);
default:
throw UnimplementedError('');
}
}
@protected
WebViewNavigationState sse_decode_web_view_navigation_state(
SseDeserializer deserializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
var var_url = sse_decode_String(deserializer);
var var_title = sse_decode_String(deserializer);
var var_canGoBack = sse_decode_bool(deserializer);
var var_canGoForward = sse_decode_bool(deserializer);
var var_isLoading = sse_decode_bool(deserializer);
return WebViewNavigationState(
url: var_url,
title: var_title,
canGoBack: var_canGoBack,
canGoForward: var_canGoForward,
isLoading: var_isLoading,
);
}
@protected
bool cst_encode_bool(bool raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
@@ -1650,6 +2311,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_u_64(self, serializer);
}
@protected
void sse_encode_box_autoadd_web_view_configuration(
WebViewConfiguration self,
SseSerializer serializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_web_view_configuration(self, serializer);
}
@protected
void sse_encode_i_32(int self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -1729,6 +2399,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
void sse_encode_list_web_view_event(
List<WebViewEvent> self,
SseSerializer serializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_i_32(self.length, serializer);
for (final item in self) {
sse_encode_web_view_event(item, serializer);
}
}
@protected
void sse_encode_my_http_version(
MyHttpVersion self,
@@ -1908,4 +2590,56 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
// Codec=Sse (Serialization based), see doc to use other codecs
serializer.buffer.putBigUint64(self);
}
@protected
void sse_encode_web_view_configuration(
WebViewConfiguration self,
SseSerializer serializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_String(self.title, serializer);
sse_encode_u_32(self.width, serializer);
sse_encode_u_32(self.height, serializer);
sse_encode_opt_String(self.userDataFolder, serializer);
sse_encode_bool(self.enableDevtools, serializer);
sse_encode_bool(self.transparent, serializer);
sse_encode_opt_String(self.userAgent, serializer);
}
@protected
void sse_encode_web_view_event(WebViewEvent self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
switch (self) {
case WebViewEvent_NavigationStarted(url: final url):
sse_encode_i_32(0, serializer);
sse_encode_String(url, serializer);
case WebViewEvent_NavigationCompleted(url: final url):
sse_encode_i_32(1, serializer);
sse_encode_String(url, serializer);
case WebViewEvent_TitleChanged(title: final title):
sse_encode_i_32(2, serializer);
sse_encode_String(title, serializer);
case WebViewEvent_WebMessage(message: final message):
sse_encode_i_32(3, serializer);
sse_encode_String(message, serializer);
case WebViewEvent_WindowClosed():
sse_encode_i_32(4, serializer);
case WebViewEvent_Error(message: final message):
sse_encode_i_32(5, serializer);
sse_encode_String(message, serializer);
}
}
@protected
void sse_encode_web_view_navigation_state(
WebViewNavigationState self,
SseSerializer serializer,
) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_String(self.url, serializer);
sse_encode_String(self.title, serializer);
sse_encode_bool(self.canGoBack, serializer);
sse_encode_bool(self.canGoForward, serializer);
sse_encode_bool(self.isLoading, serializer);
}
}

View File

@@ -8,6 +8,7 @@ import 'api/http_api.dart';
import 'api/ort_api.dart';
import 'api/rs_process.dart';
import 'api/unp4k_api.dart';
import 'api/webview_api.dart';
import 'api/win32_api.dart';
import 'dart:async';
import 'dart:convert';
@@ -51,6 +52,11 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
BigInt dco_decode_box_autoadd_u_64(dynamic raw);
@protected
WebViewConfiguration dco_decode_box_autoadd_web_view_configuration(
dynamic raw,
);
@protected
int dco_decode_i_32(dynamic raw);
@@ -75,6 +81,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
List<(String, String)> dco_decode_list_record_string_string(dynamic raw);
@protected
List<WebViewEvent> dco_decode_list_web_view_event(dynamic raw);
@protected
MyHttpVersion dco_decode_my_http_version(dynamic raw);
@@ -135,6 +144,15 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
BigInt dco_decode_usize(dynamic raw);
@protected
WebViewConfiguration dco_decode_web_view_configuration(dynamic raw);
@protected
WebViewEvent dco_decode_web_view_event(dynamic raw);
@protected
WebViewNavigationState dco_decode_web_view_navigation_state(dynamic raw);
@protected
AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer);
@@ -166,6 +184,11 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
BigInt sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
@protected
WebViewConfiguration sse_decode_box_autoadd_web_view_configuration(
SseDeserializer deserializer,
);
@protected
int sse_decode_i_32(SseDeserializer deserializer);
@@ -194,6 +217,11 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
SseDeserializer deserializer,
);
@protected
List<WebViewEvent> sse_decode_list_web_view_event(
SseDeserializer deserializer,
);
@protected
MyHttpVersion sse_decode_my_http_version(SseDeserializer deserializer);
@@ -264,6 +292,19 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
BigInt sse_decode_usize(SseDeserializer deserializer);
@protected
WebViewConfiguration sse_decode_web_view_configuration(
SseDeserializer deserializer,
);
@protected
WebViewEvent sse_decode_web_view_event(SseDeserializer deserializer);
@protected
WebViewNavigationState sse_decode_web_view_navigation_state(
SseDeserializer deserializer,
);
@protected
ffi.Pointer<wire_cst_list_prim_u_8_strict> cst_encode_AnyhowException(
AnyhowException raw,
@@ -324,6 +365,15 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
return wire.cst_new_box_autoadd_u_64(cst_encode_u_64(raw));
}
@protected
ffi.Pointer<wire_cst_web_view_configuration>
cst_encode_box_autoadd_web_view_configuration(WebViewConfiguration raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
final ptr = wire.cst_new_box_autoadd_web_view_configuration();
cst_api_fill_to_wire_web_view_configuration(raw, ptr.ref);
return ptr;
}
@protected
int cst_encode_i_64(PlatformInt64 raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
@@ -395,6 +445,18 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
return ans;
}
@protected
ffi.Pointer<wire_cst_list_web_view_event> cst_encode_list_web_view_event(
List<WebViewEvent> raw,
) {
// Codec=Cst (C-struct based), see doc to use other codecs
final ans = wire.cst_new_list_web_view_event(raw.length);
for (var i = 0; i < raw.length; ++i) {
cst_api_fill_to_wire_web_view_event(raw[i], ans.ref.ptr[i]);
}
return ans;
}
@protected
ffi.Pointer<wire_cst_list_record_string_string>
cst_encode_opt_Map_String_String_None(Map<String, String>? raw) {
@@ -449,6 +511,14 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
cst_api_fill_to_wire_rsi_launcher_asar_data(apiObj, wireObj.ref);
}
@protected
void cst_api_fill_to_wire_box_autoadd_web_view_configuration(
WebViewConfiguration apiObj,
ffi.Pointer<wire_cst_web_view_configuration> wireObj,
) {
cst_api_fill_to_wire_web_view_configuration(apiObj, wireObj.ref);
}
@protected
void cst_api_fill_to_wire_p_4_k_file_item(
P4kFileItem apiObj,
@@ -518,6 +588,73 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
wireObj.data = cst_encode_opt_list_prim_u_8_strict(apiObj.data);
}
@protected
void cst_api_fill_to_wire_web_view_configuration(
WebViewConfiguration apiObj,
wire_cst_web_view_configuration wireObj,
) {
wireObj.title = cst_encode_String(apiObj.title);
wireObj.width = cst_encode_u_32(apiObj.width);
wireObj.height = cst_encode_u_32(apiObj.height);
wireObj.user_data_folder = cst_encode_opt_String(apiObj.userDataFolder);
wireObj.enable_devtools = cst_encode_bool(apiObj.enableDevtools);
wireObj.transparent = cst_encode_bool(apiObj.transparent);
wireObj.user_agent = cst_encode_opt_String(apiObj.userAgent);
}
@protected
void cst_api_fill_to_wire_web_view_event(
WebViewEvent apiObj,
wire_cst_web_view_event wireObj,
) {
if (apiObj is WebViewEvent_NavigationStarted) {
var pre_url = cst_encode_String(apiObj.url);
wireObj.tag = 0;
wireObj.kind.NavigationStarted.url = pre_url;
return;
}
if (apiObj is WebViewEvent_NavigationCompleted) {
var pre_url = cst_encode_String(apiObj.url);
wireObj.tag = 1;
wireObj.kind.NavigationCompleted.url = pre_url;
return;
}
if (apiObj is WebViewEvent_TitleChanged) {
var pre_title = cst_encode_String(apiObj.title);
wireObj.tag = 2;
wireObj.kind.TitleChanged.title = pre_title;
return;
}
if (apiObj is WebViewEvent_WebMessage) {
var pre_message = cst_encode_String(apiObj.message);
wireObj.tag = 3;
wireObj.kind.WebMessage.message = pre_message;
return;
}
if (apiObj is WebViewEvent_WindowClosed) {
wireObj.tag = 4;
return;
}
if (apiObj is WebViewEvent_Error) {
var pre_message = cst_encode_String(apiObj.message);
wireObj.tag = 5;
wireObj.kind.Error.message = pre_message;
return;
}
}
@protected
void cst_api_fill_to_wire_web_view_navigation_state(
WebViewNavigationState apiObj,
wire_cst_web_view_navigation_state wireObj,
) {
wireObj.url = cst_encode_String(apiObj.url);
wireObj.title = cst_encode_String(apiObj.title);
wireObj.can_go_back = cst_encode_bool(apiObj.canGoBack);
wireObj.can_go_forward = cst_encode_bool(apiObj.canGoForward);
wireObj.is_loading = cst_encode_bool(apiObj.isLoading);
}
@protected
bool cst_encode_bool(bool raw);
@@ -581,6 +718,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_box_autoadd_u_64(BigInt self, SseSerializer serializer);
@protected
void sse_encode_box_autoadd_web_view_configuration(
WebViewConfiguration self,
SseSerializer serializer,
);
@protected
void sse_encode_i_32(int self, SseSerializer serializer);
@@ -617,6 +760,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
SseSerializer serializer,
);
@protected
void sse_encode_list_web_view_event(
List<WebViewEvent> self,
SseSerializer serializer,
);
@protected
void sse_encode_my_http_version(MyHttpVersion self, SseSerializer serializer);
@@ -697,6 +846,21 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_usize(BigInt self, SseSerializer serializer);
@protected
void sse_encode_web_view_configuration(
WebViewConfiguration self,
SseSerializer serializer,
);
@protected
void sse_encode_web_view_event(WebViewEvent self, SseSerializer serializer);
@protected
void sse_encode_web_view_navigation_state(
WebViewNavigationState self,
SseSerializer serializer,
);
}
// Section: wire_class
@@ -1368,6 +1532,416 @@ class RustLibWire implements BaseWire {
void Function(int, ffi.Pointer<wire_cst_list_prim_u_8_strict>)
>();
void wire__crate__api__webview_api__web_view_configuration_default(
int port_,
) {
return _wire__crate__api__webview_api__web_view_configuration_default(
port_,
);
}
late final _wire__crate__api__webview_api__web_view_configuration_defaultPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__web_view_configuration_default',
);
late final _wire__crate__api__webview_api__web_view_configuration_default =
_wire__crate__api__webview_api__web_view_configuration_defaultPtr
.asFunction<void Function(int)>();
void wire__crate__api__webview_api__web_view_navigation_state_default(
int port_,
) {
return _wire__crate__api__webview_api__web_view_navigation_state_default(
port_,
);
}
late final _wire__crate__api__webview_api__web_view_navigation_state_defaultPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__web_view_navigation_state_default',
);
late final _wire__crate__api__webview_api__web_view_navigation_state_default =
_wire__crate__api__webview_api__web_view_navigation_state_defaultPtr
.asFunction<void Function(int)>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_close(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_close(id);
}
late final _wire__crate__api__webview_api__webview_closePtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_close',
);
late final _wire__crate__api__webview_api__webview_close =
_wire__crate__api__webview_api__webview_closePtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_create(
ffi.Pointer<wire_cst_web_view_configuration> config,
) {
return _wire__crate__api__webview_api__webview_create(config);
}
late final _wire__crate__api__webview_api__webview_createPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_web_view_configuration>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_create',
);
late final _wire__crate__api__webview_api__webview_create =
_wire__crate__api__webview_api__webview_createPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_web_view_configuration>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_execute_script(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
ffi.Pointer<wire_cst_list_prim_u_8_strict> script,
) {
return _wire__crate__api__webview_api__webview_execute_script(id, script);
}
late final _wire__crate__api__webview_api__webview_execute_scriptPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_execute_script',
);
late final _wire__crate__api__webview_api__webview_execute_script =
_wire__crate__api__webview_api__webview_execute_scriptPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_get_state(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_get_state(id);
}
late final _wire__crate__api__webview_api__webview_get_statePtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_get_state',
);
late final _wire__crate__api__webview_api__webview_get_state =
_wire__crate__api__webview_api__webview_get_statePtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_go_back(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_go_back(id);
}
late final _wire__crate__api__webview_api__webview_go_backPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_go_back',
);
late final _wire__crate__api__webview_api__webview_go_back =
_wire__crate__api__webview_api__webview_go_backPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_go_forward(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_go_forward(id);
}
late final _wire__crate__api__webview_api__webview_go_forwardPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_go_forward',
);
late final _wire__crate__api__webview_api__webview_go_forward =
_wire__crate__api__webview_api__webview_go_forwardPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_is_closed(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_is_closed(id);
}
late final _wire__crate__api__webview_api__webview_is_closedPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_is_closed',
);
late final _wire__crate__api__webview_api__webview_is_closed =
_wire__crate__api__webview_api__webview_is_closedPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_list_all() {
return _wire__crate__api__webview_api__webview_list_all();
}
late final _wire__crate__api__webview_api__webview_list_allPtr =
_lookup<ffi.NativeFunction<WireSyncRust2DartDco Function()>>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_list_all',
);
late final _wire__crate__api__webview_api__webview_list_all =
_wire__crate__api__webview_api__webview_list_allPtr
.asFunction<WireSyncRust2DartDco Function()>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_navigate(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
ffi.Pointer<wire_cst_list_prim_u_8_strict> url,
) {
return _wire__crate__api__webview_api__webview_navigate(id, url);
}
late final _wire__crate__api__webview_api__webview_navigatePtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_navigate',
);
late final _wire__crate__api__webview_api__webview_navigate =
_wire__crate__api__webview_api__webview_navigatePtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_poll_events(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_poll_events(id);
}
late final _wire__crate__api__webview_api__webview_poll_eventsPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_poll_events',
);
late final _wire__crate__api__webview_api__webview_poll_events =
_wire__crate__api__webview_api__webview_poll_eventsPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_reload(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_reload(id);
}
late final _wire__crate__api__webview_api__webview_reloadPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_reload',
);
late final _wire__crate__api__webview_api__webview_reload =
_wire__crate__api__webview_api__webview_reloadPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_set_visibility(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
bool visible,
) {
return _wire__crate__api__webview_api__webview_set_visibility(id, visible);
}
late final _wire__crate__api__webview_api__webview_set_visibilityPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Bool,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_set_visibility',
);
late final _wire__crate__api__webview_api__webview_set_visibility =
_wire__crate__api__webview_api__webview_set_visibilityPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
bool,
)
>();
WireSyncRust2DartDco
wire__crate__api__webview_api__webview_set_window_position(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
int x,
int y,
) {
return _wire__crate__api__webview_api__webview_set_window_position(
id,
x,
y,
);
}
late final _wire__crate__api__webview_api__webview_set_window_positionPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Int32,
ffi.Int32,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_set_window_position',
);
late final _wire__crate__api__webview_api__webview_set_window_position =
_wire__crate__api__webview_api__webview_set_window_positionPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
int,
int,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_set_window_size(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
int width,
int height,
) {
return _wire__crate__api__webview_api__webview_set_window_size(
id,
width,
height,
);
}
late final _wire__crate__api__webview_api__webview_set_window_sizePtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Uint32,
ffi.Uint32,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_set_window_size',
);
late final _wire__crate__api__webview_api__webview_set_window_size =
_wire__crate__api__webview_api__webview_set_window_sizePtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
int,
int,
)
>();
WireSyncRust2DartDco wire__crate__api__webview_api__webview_stop(
ffi.Pointer<wire_cst_list_prim_u_8_strict> id,
) {
return _wire__crate__api__webview_api__webview_stop(id);
}
late final _wire__crate__api__webview_api__webview_stopPtr =
_lookup<
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__webview_api__webview_stop',
);
late final _wire__crate__api__webview_api__webview_stop =
_wire__crate__api__webview_api__webview_stopPtr
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
)
>();
void wire__crate__api__rs_process__write(
int port_,
int rs_pid,
@@ -1431,6 +2005,23 @@ class RustLibWire implements BaseWire {
late final _cst_new_box_autoadd_u_64 = _cst_new_box_autoadd_u_64Ptr
.asFunction<ffi.Pointer<ffi.Uint64> Function(int)>();
ffi.Pointer<wire_cst_web_view_configuration>
cst_new_box_autoadd_web_view_configuration() {
return _cst_new_box_autoadd_web_view_configuration();
}
late final _cst_new_box_autoadd_web_view_configurationPtr =
_lookup<
ffi.NativeFunction<
ffi.Pointer<wire_cst_web_view_configuration> Function()
>
>('frbgen_starcitizen_doctor_cst_new_box_autoadd_web_view_configuration');
late final _cst_new_box_autoadd_web_view_configuration =
_cst_new_box_autoadd_web_view_configurationPtr
.asFunction<
ffi.Pointer<wire_cst_web_view_configuration> Function()
>();
ffi.Pointer<wire_cst_list_String> cst_new_list_String(int len) {
return _cst_new_list_String(len);
}
@@ -1519,6 +2110,21 @@ class RustLibWire implements BaseWire {
ffi.Pointer<wire_cst_list_record_string_string> Function(int)
>();
ffi.Pointer<wire_cst_list_web_view_event> cst_new_list_web_view_event(
int len,
) {
return _cst_new_list_web_view_event(len);
}
late final _cst_new_list_web_view_eventPtr =
_lookup<
ffi.NativeFunction<
ffi.Pointer<wire_cst_list_web_view_event> Function(ffi.Int32)
>
>('frbgen_starcitizen_doctor_cst_new_list_web_view_event');
late final _cst_new_list_web_view_event = _cst_new_list_web_view_eventPtr
.asFunction<ffi.Pointer<wire_cst_list_web_view_event> Function(int)>();
int dummy_method_to_enforce_bundling() {
return _dummy_method_to_enforce_bundling();
}
@@ -1582,6 +2188,26 @@ final class wire_cst_list_prim_u_8_loose extends ffi.Struct {
external int len;
}
final class wire_cst_web_view_configuration extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> title;
@ffi.Uint32()
external int width;
@ffi.Uint32()
external int height;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> user_data_folder;
@ffi.Bool()
external bool enable_devtools;
@ffi.Bool()
external bool transparent;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> user_agent;
}
final class wire_cst_p_4_k_file_item extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> name;
@@ -1621,6 +2247,52 @@ final class wire_cst_list_process_info extends ffi.Struct {
external int len;
}
final class wire_cst_WebViewEvent_NavigationStarted extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> url;
}
final class wire_cst_WebViewEvent_NavigationCompleted extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> url;
}
final class wire_cst_WebViewEvent_TitleChanged extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> title;
}
final class wire_cst_WebViewEvent_WebMessage extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> message;
}
final class wire_cst_WebViewEvent_Error extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> message;
}
final class WebViewEventKind extends ffi.Union {
external wire_cst_WebViewEvent_NavigationStarted NavigationStarted;
external wire_cst_WebViewEvent_NavigationCompleted NavigationCompleted;
external wire_cst_WebViewEvent_TitleChanged TitleChanged;
external wire_cst_WebViewEvent_WebMessage WebMessage;
external wire_cst_WebViewEvent_Error Error;
}
final class wire_cst_web_view_event extends ffi.Struct {
@ffi.Int32()
external int tag;
external WebViewEventKind kind;
}
final class wire_cst_list_web_view_event extends ffi.Struct {
external ffi.Pointer<wire_cst_web_view_event> ptr;
@ffi.Int32()
external int len;
}
final class wire_cst_rs_process_stream_data extends ffi.Struct {
@ffi.Int32()
external int data_type;
@@ -1648,3 +2320,18 @@ final class wire_cst_rust_http_response extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> data;
}
final class wire_cst_web_view_navigation_state extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> url;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> title;
@ffi.Bool()
external bool can_go_back;
@ffi.Bool()
external bool can_go_forward;
@ffi.Bool()
external bool is_loading;
}

View File

@@ -0,0 +1,350 @@
// Rust WebView 管理器
// 使用 wry + tao 实现的 WebView 窗口管理
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:starcitizen_doctor/common/rust/api/webview_api.dart'
as rust_webview;
import 'package:starcitizen_doctor/common/utils/log.dart';
typedef OnWebMessageCallback = void Function(String message);
typedef OnNavigationCallback = void Function(String url);
typedef OnNavigationCompletedCallback = void Function(String url);
typedef OnWindowClosedCallback = void Function();
/// Rust WebView 控制器
/// 封装 Rust wry + tao WebView 的业务逻辑
class RustWebViewController {
final String id;
final List<OnWebMessageCallback> _messageCallbacks = [];
final List<OnNavigationCallback> _navigationCallbacks = [];
final List<OnNavigationCompletedCallback> _navigationCompletedCallbacks = [];
final List<OnWindowClosedCallback> _closeCallbacks = [];
Timer? _pollTimer;
bool _isDisposed = false;
/// 本地化脚本(从 assets 加载)
String _localizationScript = "";
/// 请求拦截器脚本
String _requestInterceptorScript = "";
/// 当前 URL
String _currentUrl = "";
String get currentUrl => _currentUrl;
RustWebViewController._(this.id);
/// 创建新的 WebView 窗口
static Future<RustWebViewController> create({
String title = "WebView",
int width = 1280,
int height = 720,
String? userDataFolder,
bool enableDevtools = false,
bool transparent = false,
String? userAgent,
}) async {
try {
final config = rust_webview.WebViewConfiguration(
title: title,
width: width,
height: height,
userDataFolder: userDataFolder,
enableDevtools: enableDevtools,
transparent: transparent,
userAgent: userAgent,
);
final id = rust_webview.webviewCreate(config: config);
final controller = RustWebViewController._(id);
// 加载脚本资源
await controller._loadScripts();
// 启动事件轮询
controller._startEventPolling();
return controller;
} catch (e) {
throw Exception("Failed to create WebView: $e");
}
}
/// 加载本地化和拦截器脚本
Future<void> _loadScripts() async {
try {
_localizationScript = await rootBundle.loadString('assets/web_script.js');
_requestInterceptorScript = await rootBundle.loadString(
'assets/request_interceptor.js',
);
} catch (e) {
dPrint("Failed to load scripts: $e");
}
}
/// 启动事件轮询
void _startEventPolling() {
_pollTimer = Timer.periodic(const Duration(milliseconds: 50), (_) {
if (_isDisposed) return;
_pollEvents();
});
}
/// 轮询事件
void _pollEvents() {
try {
final events = rust_webview.webviewPollEvents(id: id);
for (final event in events) {
_handleEvent(event);
}
} catch (e) {
// WebView 可能已关闭
if (!_isDisposed) {
dPrint("Error polling events: $e");
}
}
}
/// 处理事件
void _handleEvent(rust_webview.WebViewEvent event) {
switch (event) {
case rust_webview.WebViewEvent_NavigationStarted(:final url):
dPrint("Navigation started: $url");
_currentUrl = url;
// 导航开始时通知
for (final callback in _navigationCallbacks) {
callback(url);
}
break;
case rust_webview.WebViewEvent_NavigationCompleted(:final url):
dPrint("Navigation completed: $url");
_currentUrl = url;
// 注入请求拦截器
if (_requestInterceptorScript.isNotEmpty) {
executeScript(_requestInterceptorScript);
}
// 导航完成回调(用于注入脚本)
for (final callback in _navigationCompletedCallbacks) {
callback(url);
}
for (final callback in _navigationCallbacks) {
callback(url);
}
break;
case rust_webview.WebViewEvent_TitleChanged(:final title):
dPrint("Title changed: $title");
break;
case rust_webview.WebViewEvent_WebMessage(:final message):
_handleWebMessage(message);
break;
case rust_webview.WebViewEvent_WindowClosed():
dPrint("Window closed");
for (final callback in _closeCallbacks) {
callback();
}
dispose();
break;
case rust_webview.WebViewEvent_Error(:final message):
dPrint("WebView error: $message");
break;
}
}
/// 处理来自 WebView 的消息
void _handleWebMessage(String message) {
dPrint("Web message: $message");
try {
final data = json.decode(message);
final action = data["action"];
switch (action) {
case "navigation_state":
// 从 JS 获取导航状态更新
final url = data["url"] ?? "";
final isLoading = data["isLoading"] ?? false;
_currentUrl = url;
if (!isLoading) {
for (final callback in _navigationCallbacks) {
callback(url);
}
}
break;
case "close_window":
// 处理来自导航栏的关闭请求
close();
break;
default:
// 转发其他消息给回调
for (final callback in _messageCallbacks) {
callback(message);
}
}
} catch (e) {
// 非 JSON 消息,直接转发
for (final callback in _messageCallbacks) {
callback(message);
}
}
}
/// 导航到 URL
void navigate(String url) {
if (_isDisposed) return;
_currentUrl = url;
rust_webview.webviewNavigate(id: id, url: url);
}
/// 后退
void goBack() {
if (_isDisposed) return;
rust_webview.webviewGoBack(id: id);
}
/// 前进
void goForward() {
if (_isDisposed) return;
rust_webview.webviewGoForward(id: id);
}
/// 刷新
void reload() {
if (_isDisposed) return;
rust_webview.webviewReload(id: id);
}
/// 停止加载
void stop() {
if (_isDisposed) return;
rust_webview.webviewStop(id: id);
}
/// 执行 JavaScript
void executeScript(String script) {
if (_isDisposed) return;
rust_webview.webviewExecuteScript(id: id, script: script);
}
/// 设置窗口可见性
void setVisible(bool visible) {
if (_isDisposed) return;
rust_webview.webviewSetVisibility(id: id, visible: visible);
}
/// 关闭窗口
void close() {
if (_isDisposed) return;
rust_webview.webviewClose(id: id);
dispose();
}
/// 设置窗口大小
void setWindowSize(int width, int height) {
if (_isDisposed) return;
rust_webview.webviewSetWindowSize(id: id, width: width, height: height);
}
/// 设置窗口位置
void setWindowPosition(int x, int y) {
if (_isDisposed) return;
rust_webview.webviewSetWindowPosition(id: id, x: x, y: y);
}
/// 获取当前导航状态
rust_webview.WebViewNavigationState getState() {
return rust_webview.webviewGetState(id: id);
}
/// 检查窗口是否已关闭
bool get isClosed {
if (_isDisposed) return true;
return rust_webview.webviewIsClosed(id: id);
}
/// 添加消息回调
void addOnWebMessageCallback(OnWebMessageCallback callback) {
_messageCallbacks.add(callback);
}
/// 移除消息回调
void removeOnWebMessageCallback(OnWebMessageCallback callback) {
_messageCallbacks.remove(callback);
}
/// 添加导航回调
void addOnNavigationCallback(OnNavigationCallback callback) {
_navigationCallbacks.add(callback);
}
/// 移除导航回调
void removeOnNavigationCallback(OnNavigationCallback callback) {
_navigationCallbacks.remove(callback);
}
/// 添加导航完成回调(用于在页面加载完成后注入脚本)
void addOnNavigationCompletedCallback(
OnNavigationCompletedCallback callback,
) {
_navigationCompletedCallbacks.add(callback);
}
/// 移除导航完成回调
void removeOnNavigationCompletedCallback(
OnNavigationCompletedCallback callback,
) {
_navigationCompletedCallbacks.remove(callback);
}
/// 添加关闭回调
void addOnCloseCallback(OnWindowClosedCallback callback) {
_closeCallbacks.add(callback);
}
/// 移除关闭回调
void removeOnCloseCallback(OnWindowClosedCallback callback) {
_closeCallbacks.remove(callback);
}
/// 注入本地化脚本
void injectLocalizationScript() {
if (_localizationScript.isNotEmpty) {
executeScript(_localizationScript);
}
}
/// 初始化网页本地化
void initWebLocalization() {
executeScript("InitWebLocalization()");
}
/// 更新翻译词典
void updateReplaceWords(List<Map<String, String>> words, bool enableCapture) {
final jsonWords = json.encode(words);
executeScript(
"WebLocalizationUpdateReplaceWords($jsonWords, $enableCapture)",
);
}
/// 执行 RSI 登录脚本
void executeRsiLogin(String channel) {
executeScript('getRSILauncherToken("$channel");');
}
/// 释放资源
void dispose() {
if (_isDisposed) return;
_isDisposed = true;
_pollTimer?.cancel();
_messageCallbacks.clear();
_navigationCallbacks.clear();
_navigationCompletedCallbacks.clear();
_closeCallbacks.clear();
}
}