From 0f349bee332df458ed769fb7db8c83f375c81d0b Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Sat, 27 Apr 2024 14:25:11 +0800 Subject: [PATCH] feat: use notify-rust, remove dart/windows_ui --- lib/common/rust/api/notify_api.dart | 20 +++++++++++++ lib/common/rust/frb_generated.dart | 41 ++++++++++++++++++++++++++- lib/common/rust/frb_generated.io.dart | 34 ++++++++++++++++++++++ lib/ui/home/home_ui_model.dart | 30 +++++++------------- pubspec.yaml | 1 - rust/Cargo.toml | 3 +- rust/src/api/mod.rs | 1 + rust/src/api/notify_api.rs | 19 +++++++++++++ rust/src/frb_generated.io.rs | 11 +++++++ rust/src/frb_generated.rs | 33 ++++++++++++++++++++- 10 files changed, 169 insertions(+), 24 deletions(-) create mode 100644 lib/common/rust/api/notify_api.dart create mode 100644 rust/src/api/notify_api.rs diff --git a/lib/common/rust/api/notify_api.dart b/lib/common/rust/api/notify_api.dart new file mode 100644 index 0000000..0cb5c0d --- /dev/null +++ b/lib/common/rust/api/notify_api.dart @@ -0,0 +1,20 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0-dev.32. + +// 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'; + +Future sendNotify( + {String? summary, + String? body, + String? appName, + String? appId, + dynamic hint}) => + RustLib.instance.api.sendNotify( + summary: summary, + body: body, + appName: appName, + appId: appId, + hint: hint); diff --git a/lib/common/rust/frb_generated.dart b/lib/common/rust/frb_generated.dart index c9faf82..f5abb6d 100644 --- a/lib/common/rust/frb_generated.dart +++ b/lib/common/rust/frb_generated.dart @@ -4,6 +4,7 @@ // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field import 'api/http_api.dart'; +import 'api/notify_api.dart'; import 'api/rs_process.dart'; import 'dart:async'; import 'dart:convert'; @@ -56,7 +57,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.0.0-dev.32'; @override - int get rustContentHash => 1270049297; + int get rustContentHash => 1067953400; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -82,6 +83,13 @@ abstract class RustLibApi extends BaseApi { Future setDefaultHeader( {required Map headers, dynamic hint}); + Future sendNotify( + {String? summary, + String? body, + String? appName, + String? appId, + dynamic hint}); + Stream start( {required String executable, required List arguments, @@ -202,6 +210,37 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["headers"], ); + @override + Future sendNotify( + {String? summary, + String? body, + String? appName, + String? appId, + dynamic hint}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + var arg0 = cst_encode_opt_String(summary); + var arg1 = cst_encode_opt_String(body); + var arg2 = cst_encode_opt_String(appName); + var arg3 = cst_encode_opt_String(appId); + return wire.wire_send_notify(port_, arg0, arg1, arg2, arg3); + }, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, + decodeErrorData: dco_decode_AnyhowException, + ), + constMeta: kSendNotifyConstMeta, + argValues: [summary, body, appName, appId], + apiImpl: this, + hint: hint, + )); + } + + TaskConstMeta get kSendNotifyConstMeta => const TaskConstMeta( + debugName: "send_notify", + argNames: ["summary", "body", "appName", "appId"], + ); + @override Stream start( {required String executable, diff --git a/lib/common/rust/frb_generated.io.dart b/lib/common/rust/frb_generated.io.dart index 8148e52..e38424c 100644 --- a/lib/common/rust/frb_generated.io.dart +++ b/lib/common/rust/frb_generated.io.dart @@ -4,6 +4,7 @@ // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field import 'api/http_api.dart'; +import 'api/notify_api.dart'; import 'api/rs_process.dart'; import 'dart:async'; import 'dart:convert'; @@ -548,6 +549,39 @@ class RustLibWire implements BaseWire { late final _wire_set_default_header = _wire_set_default_headerPtr.asFunction< void Function(int, ffi.Pointer)>(); + void wire_send_notify( + int port_, + ffi.Pointer summary, + ffi.Pointer body, + ffi.Pointer app_name, + ffi.Pointer app_id, + ) { + return _wire_send_notify( + port_, + summary, + body, + app_name, + app_id, + ); + } + + late final _wire_send_notifyPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_send_notify'); + late final _wire_send_notify = _wire_send_notifyPtr.asFunction< + void Function( + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + void wire_start( int port_, ffi.Pointer executable, diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index 372ca6e..3e4002f 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -16,6 +16,8 @@ import 'package:starcitizen_doctor/common/conf/url_conf.dart'; import 'package:starcitizen_doctor/common/helper/log_helper.dart'; import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/common/io/rs_http.dart'; +import 'package:starcitizen_doctor/common/rust/api/notify_api.dart' + as notify_api; import 'package:starcitizen_doctor/common/utils/async.dart'; import 'package:starcitizen_doctor/common/utils/base_utils.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; @@ -27,7 +29,6 @@ import 'package:starcitizen_doctor/ui/home/dialogs/home_game_login_dialog_ui.dar import 'package:url_launcher/url_launcher_string.dart'; import 'package:html/parser.dart' as html; import 'package:html/dom.dart' as html_dom; -import 'package:windows_ui/windows_ui.dart'; import '../webview/webview.dart'; import 'localization/localization_ui_model.dart'; @@ -290,25 +291,14 @@ class HomeUIModel extends _$HomeUIModel { _appUpdateTimer?.cancel(); _appUpdateTimer = null; // 发送通知 - final toastNotifier = ToastNotificationManager.createToastNotifierWithId( - S.current.home_title_app_name); - if (toastNotifier != null) { - final toastContent = ToastNotificationManager.getTemplateContent( - ToastTemplateType.toastText02); - if (toastContent != null) { - final xmlNodeList = toastContent.getElementsByTagName('text'); - final title = S.current.home_localization_new_version_available; - final content = - S.current.home_localization_new_version_installed(updates.first); - xmlNodeList.item(0)?.appendChild(toastContent.createTextNode(title)); - xmlNodeList - .item(1) - ?.appendChild(toastContent.createTextNode(content)); - final toastNotification = - ToastNotification.createToastNotification(toastContent); - toastNotifier.show(toastNotification); - } - } + await notify_api.sendNotify( + summary: S.current.home_localization_new_version_available, + body: + S.current.home_localization_new_version_installed(updates.first), + appName: S.current.home_title_app_name, + appId: ConstConf.isMSE + ? "56575xkeyC.MSE_bsn1nexg8e4qe!starcitizendoctor" + : "{6D809377-6AF0-444B-8957-A3773F02200E}\\Starcitizen_Doctor\\starcitizen_doctor.exe"); } } diff --git a/pubspec.yaml b/pubspec.yaml index 6300f19..c3e27e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,7 +65,6 @@ dependencies: flutter_rust_bridge: ^2.0.0-dev.32 freezed_annotation: ^2.4.1 meta: ^1.9.1 - windows_ui: ^0.2.0 cryptography: ^2.7.0 cryptography_flutter: ^2.3.2 hexcolor: ^3.0.1 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 94a898e..33c81c0 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -21,4 +21,5 @@ hickory-resolver = { version = "0.24" } anyhow = "1.0" win32job = "2" lazy_static = "1.4" -scopeguard = "1.2" \ No newline at end of file +scopeguard = "1.2" +notify-rust = "4" \ No newline at end of file diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rs index 0fb9059..6109034 100644 --- a/rust/src/api/mod.rs +++ b/rust/src/api/mod.rs @@ -4,3 +4,4 @@ pub mod http_api; pub mod rs_process; +pub mod notify_api; diff --git a/rust/src/api/notify_api.rs b/rust/src/api/notify_api.rs new file mode 100644 index 0000000..7f65e86 --- /dev/null +++ b/rust/src/api/notify_api.rs @@ -0,0 +1,19 @@ +use notify_rust::Notification; + +pub fn send_notify(summary: Option, body: Option, app_name: Option, app_id: Option) -> anyhow::Result<()> { + let mut n = Notification::new(); + if let Some(summary) = summary { + n.summary(&summary); + } + if let Some(body) = body { + n.body(&body); + } + if let Some(app_name) = app_name { + n.appname(&app_name); + } + if let Some(app_id) = app_id { + n.app_id(&app_id); + } + n.show()?; + Ok(()) +} \ No newline at end of file diff --git a/rust/src/frb_generated.io.rs b/rust/src/frb_generated.io.rs index 1825b84..5cdfaa7 100644 --- a/rust/src/frb_generated.io.rs +++ b/rust/src/frb_generated.io.rs @@ -204,6 +204,17 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_set_default_header( wire_set_default_header_impl(port_, headers) } +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_send_notify( + port_: i64, + summary: *mut wire_cst_list_prim_u_8_strict, + body: *mut wire_cst_list_prim_u_8_strict, + app_name: *mut wire_cst_list_prim_u_8_strict, + app_id: *mut wire_cst_list_prim_u_8_strict, +) { + wire_send_notify_impl(port_, summary, body, app_name, app_id) +} + #[no_mangle] pub extern "C" fn frbgen_starcitizen_doctor_wire_start( port_: i64, diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index f1a0c30..aec255f 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -31,7 +31,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueNom, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.32"; -pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1270049297; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1067953400; // Section: executor @@ -139,6 +139,37 @@ fn wire_set_default_header_impl( }, ) } +fn wire_send_notify_impl( + port_: flutter_rust_bridge::for_generated::MessagePort, + summary: impl CstDecode>, + body: impl CstDecode>, + app_name: impl CstDecode>, + app_id: impl CstDecode>, +) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "send_notify", + port: Some(port_), + mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, + }, + move || { + let api_summary = summary.cst_decode(); + let api_body = body.cst_decode(); + let api_app_name = app_name.cst_decode(); + let api_app_id = app_id.cst_decode(); + move |context| { + transform_result_dco((move || { + crate::api::notify_api::send_notify( + api_summary, + api_body, + api_app_name, + api_app_id, + ) + })()) + } + }, + ) +} fn wire_start_impl( port_: flutter_rust_bridge::for_generated::MessagePort, executable: impl CstDecode,