feat: use notify-rust, remove dart/windows_ui

This commit is contained in:
xkeyC 2024-04-27 14:25:11 +08:00
parent d2694a1e25
commit 0f349bee33
10 changed files with 169 additions and 24 deletions

View File

@ -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<void> 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);

View File

@ -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 // 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/http_api.dart';
import 'api/notify_api.dart';
import 'api/rs_process.dart'; import 'api/rs_process.dart';
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
@ -56,7 +57,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.0.0-dev.32'; String get codegenVersion => '2.0.0-dev.32';
@override @override
int get rustContentHash => 1270049297; int get rustContentHash => 1067953400;
static const kDefaultExternalLibraryLoaderConfig = static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig( ExternalLibraryLoaderConfig(
@ -82,6 +83,13 @@ abstract class RustLibApi extends BaseApi {
Future<void> setDefaultHeader( Future<void> setDefaultHeader(
{required Map<String, String> headers, dynamic hint}); {required Map<String, String> headers, dynamic hint});
Future<void> sendNotify(
{String? summary,
String? body,
String? appName,
String? appId,
dynamic hint});
Stream<RsProcessStreamData> start( Stream<RsProcessStreamData> start(
{required String executable, {required String executable,
required List<String> arguments, required List<String> arguments,
@ -202,6 +210,37 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["headers"], argNames: ["headers"],
); );
@override
Future<void> 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 @override
Stream<RsProcessStreamData> start( Stream<RsProcessStreamData> start(
{required String executable, {required String executable,

View File

@ -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 // 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/http_api.dart';
import 'api/notify_api.dart';
import 'api/rs_process.dart'; import 'api/rs_process.dart';
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
@ -548,6 +549,39 @@ class RustLibWire implements BaseWire {
late final _wire_set_default_header = _wire_set_default_headerPtr.asFunction< late final _wire_set_default_header = _wire_set_default_headerPtr.asFunction<
void Function(int, ffi.Pointer<wire_cst_list_record_string_string>)>(); void Function(int, ffi.Pointer<wire_cst_list_record_string_string>)>();
void wire_send_notify(
int port_,
ffi.Pointer<wire_cst_list_prim_u_8_strict> summary,
ffi.Pointer<wire_cst_list_prim_u_8_strict> body,
ffi.Pointer<wire_cst_list_prim_u_8_strict> app_name,
ffi.Pointer<wire_cst_list_prim_u_8_strict> 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<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>)>>(
'frbgen_starcitizen_doctor_wire_send_notify');
late final _wire_send_notify = _wire_send_notifyPtr.asFunction<
void Function(
int,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>)>();
void wire_start( void wire_start(
int port_, int port_,
ffi.Pointer<wire_cst_list_prim_u_8_strict> executable, ffi.Pointer<wire_cst_list_prim_u_8_strict> executable,

View File

@ -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/log_helper.dart';
import 'package:starcitizen_doctor/common/helper/system_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/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/async.dart';
import 'package:starcitizen_doctor/common/utils/base_utils.dart'; import 'package:starcitizen_doctor/common/utils/base_utils.dart';
import 'package:starcitizen_doctor/common/utils/log.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:url_launcher/url_launcher_string.dart';
import 'package:html/parser.dart' as html; import 'package:html/parser.dart' as html;
import 'package:html/dom.dart' as html_dom; import 'package:html/dom.dart' as html_dom;
import 'package:windows_ui/windows_ui.dart';
import '../webview/webview.dart'; import '../webview/webview.dart';
import 'localization/localization_ui_model.dart'; import 'localization/localization_ui_model.dart';
@ -290,25 +291,14 @@ class HomeUIModel extends _$HomeUIModel {
_appUpdateTimer?.cancel(); _appUpdateTimer?.cancel();
_appUpdateTimer = null; _appUpdateTimer = null;
// //
final toastNotifier = ToastNotificationManager.createToastNotifierWithId( await notify_api.sendNotify(
S.current.home_title_app_name); summary: S.current.home_localization_new_version_available,
if (toastNotifier != null) { body:
final toastContent = ToastNotificationManager.getTemplateContent( S.current.home_localization_new_version_installed(updates.first),
ToastTemplateType.toastText02); appName: S.current.home_title_app_name,
if (toastContent != null) { appId: ConstConf.isMSE
final xmlNodeList = toastContent.getElementsByTagName('text'); ? "56575xkeyC.MSE_bsn1nexg8e4qe!starcitizendoctor"
final title = S.current.home_localization_new_version_available; : "{6D809377-6AF0-444B-8957-A3773F02200E}\\Starcitizen_Doctor\\starcitizen_doctor.exe");
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);
}
}
} }
} }

View File

@ -65,7 +65,6 @@ dependencies:
flutter_rust_bridge: ^2.0.0-dev.32 flutter_rust_bridge: ^2.0.0-dev.32
freezed_annotation: ^2.4.1 freezed_annotation: ^2.4.1
meta: ^1.9.1 meta: ^1.9.1
windows_ui: ^0.2.0
cryptography: ^2.7.0 cryptography: ^2.7.0
cryptography_flutter: ^2.3.2 cryptography_flutter: ^2.3.2
hexcolor: ^3.0.1 hexcolor: ^3.0.1

View File

@ -21,4 +21,5 @@ hickory-resolver = { version = "0.24" }
anyhow = "1.0" anyhow = "1.0"
win32job = "2" win32job = "2"
lazy_static = "1.4" lazy_static = "1.4"
scopeguard = "1.2" scopeguard = "1.2"
notify-rust = "4"

View File

@ -4,3 +4,4 @@
pub mod http_api; pub mod http_api;
pub mod rs_process; pub mod rs_process;
pub mod notify_api;

View File

@ -0,0 +1,19 @@
use notify_rust::Notification;
pub fn send_notify(summary: Option<String>, body: Option<String>, app_name: Option<String>, app_id: Option<String>) -> 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(())
}

View File

@ -204,6 +204,17 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_set_default_header(
wire_set_default_header_impl(port_, headers) 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] #[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_start( pub extern "C" fn frbgen_starcitizen_doctor_wire_start(
port_: i64, port_: i64,

View File

@ -31,7 +31,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueNom, 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_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 // 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<Option<String>>,
body: impl CstDecode<Option<String>>,
app_name: impl CstDecode<Option<String>>,
app_id: impl CstDecode<Option<String>>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
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( fn wire_start_impl(
port_: flutter_rust_bridge::for_generated::MessagePort, port_: flutter_rust_bridge::for_generated::MessagePort,
executable: impl CstDecode<String>, executable: impl CstDecode<String>,