grpc import

This commit is contained in:
xkeyC 2023-12-02 12:26:17 +08:00
parent 9f6f9b2dc4
commit 5f4af52ef2
14 changed files with 319 additions and 10 deletions

19
assets/cert.pem Normal file
View File

@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDEDCCAfigAwIBAgIQd60aUiCLj0uhbJ9IdhfflzANBgkqhkiG9w0BAQsFADAS
MRAwDgYDVQQKEwdBY21lIENvMB4XDTIzMTIwMTE1MjkyN1oXDTMzMTEyODE1Mjky
N1owEjEQMA4GA1UEChMHQWNtZSBDbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBAKBov8KcT7N4bhf1RE5D2vKV+NVDMnHVkvij9VvixLALA0K9QHPUOPM+
ReDluJyeOk34lwXMd8S2HAWghKHB80lfFrUT0cj/BgSXQBRWL8oQNtCPMMOJmZ6A
TCKAQOXSJ86bwrEHWbuSjQtfDONPDg7qF8ysEjNfjIro/yxA9z+nxO07oHrtBLg+
C//hd3miGIyL5iwgIXH86Y6Mvp6K1/Sfc6dZhwiZwjG+8XR338Y69KL+5SPemE88
4fIa9p/QYKbkCRE2D5jjW4OCJOK/D105/DNSJu20HzdP1crZJsi4RXLLCE1OC/Mz
plzD9hdVovKtx6WfxgpFKZpNBlXs73ECAwEAAaNiMGAwDgYDVR0PAQH/BAQDAgWg
MBMGA1UdJQQMMAoGCCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwKwYDVR0RBCQwIoIg
Z3JwYy5zY3Rvb2xib3guZmFrZS5iaWxpYmlsaS5jb20wDQYJKoZIhvcNAQELBQAD
ggEBAHagncLc0hFp2bcCbp+V9nq5kYkc3iZ2eWgwwq7NeQVk5nAqMajFeoyJbN6C
Aksqbz+iNsJdzqpzfo2VC70Rd3n79i0krK2puDhSU+1CkHm5F4CcuJQXA44RWLt+
iINU3Op1upl2+TAujLb2ezmh7CoxlHbMkd0+5qa6DHoRB1wZ6MF4iYzGupr63uVv
6wQzzRGZgEt5iC2nRF9moilwVIrs3w6swpWh/m/YCPUUWIZGj1J6PmOTiDyOReSQ
xG6chIPhdzAKPoBPEQzG9v/t94w3kdF010BP2JzQoKg3lecCM1QWgpGV8qvbhtoS
hFhz6sZZ/sh6NiH0Cp0t55jhKDI=
-----END CERTIFICATE-----

20
lib/api/grpc_api.dart Normal file
View File

@ -0,0 +1,20 @@
import 'package:starcitizen_doctor/common/grpc/grpc.dart';
import 'package:starcitizen_doctor/generated/grpc/app.pbgrpc.dart';
import '../common/utils/base_utils.dart';
class GrpcApi {
static final _pingClient = PingServiceClient(GrpcClient.channel);
static Future pingServer() async {
try {
final result = await _pingClient.pingServer(PingRequest(name: "ping"));
if (result.pong == "pong") {
dPrint("[GrpcApi] gRPC service Connected");
return;
}
} catch (e) {
dPrint("[GrpcApi] pingServer Error: $e");
}
}
}

View File

@ -1,12 +1,14 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/services.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
import 'package:starcitizen_doctor/api/analytics.dart';
import 'package:starcitizen_doctor/api/api.dart';
import 'package:starcitizen_doctor/api/grpc_api.dart';
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/common/rust/ffi.dart';
import 'package:starcitizen_doctor/data/app_version_data.dart';
@ -54,6 +56,8 @@ class AppConf {
static Color? colorMenu;
static Color? colorMica;
static List<int>? certData;
static const isMSE =
String.fromEnvironment("MSE", defaultValue: "false") == "true";
@ -95,10 +99,16 @@ class AppConf {
colorMenu = HexColor("#132431").withOpacity(.95);
colorMica = HexColor("#0A3142");
/// init grpcKeys
certData = (await rootBundle.load("assets/cert.pem"))
.buffer
.asUint8List()
.toList();
/// init windows
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setSize(const Size(1280, 810));
await windowManager.setSize(const Size(1080, 810));
await windowManager.setMinimumSize(const Size(1280, 810));
await windowManager.center(animate: true);
await windowManager.setSkipTaskbar(false);
@ -124,6 +134,7 @@ class AppConf {
}
static Future<void> checkUpdate() async {
GrpcApi.pingServer();
// clean path
if (!isMSE) {
final dir = Directory(getUpgradePath());

17
lib/common/grpc/grpc.dart Normal file
View File

@ -0,0 +1,17 @@
import 'package:grpc/grpc.dart';
import 'package:starcitizen_doctor/common/conf.dart';
class GrpcClient {
static final channel = ClientChannel(
'grpc.sctoolbox.xkeyc.com',
port: 8439,
options: ChannelOptions(
credentials: ChannelCredentials.secure(
certificates: AppConf.certData,
authority: 'grpc.sctoolbox.fake.bilibili.com',
),
codecRegistry:
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
),
);
}

View File

@ -0,0 +1,118 @@
//
// Generated code. Do not modify.
// source: app.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb;
class PingRequest extends $pb.GeneratedMessage {
factory PingRequest({
$core.String? name,
}) {
final $result = create();
if (name != null) {
$result.name = name;
}
return $result;
}
PingRequest._() : super();
factory PingRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory PingRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PingRequest', createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'name')
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
PingRequest clone() => PingRequest()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
PingRequest copyWith(void Function(PingRequest) updates) => super.copyWith((message) => updates(message as PingRequest)) as PingRequest;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static PingRequest create() => PingRequest._();
PingRequest createEmptyInstance() => create();
static $pb.PbList<PingRequest> createRepeated() => $pb.PbList<PingRequest>();
@$core.pragma('dart2js:noInline')
static PingRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<PingRequest>(create);
static PingRequest? _defaultInstance;
@$pb.TagNumber(1)
$core.String get name => $_getSZ(0);
@$pb.TagNumber(1)
set name($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasName() => $_has(0);
@$pb.TagNumber(1)
void clearName() => clearField(1);
}
class PingResult extends $pb.GeneratedMessage {
factory PingResult({
$core.String? pong,
}) {
final $result = create();
if (pong != null) {
$result.pong = pong;
}
return $result;
}
PingResult._() : super();
factory PingResult.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory PingResult.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'PingResult', createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'pong')
..hasRequiredFields = false
;
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
PingResult clone() => PingResult()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
PingResult copyWith(void Function(PingResult) updates) => super.copyWith((message) => updates(message as PingResult)) as PingResult;
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static PingResult create() => PingResult._();
PingResult createEmptyInstance() => create();
static $pb.PbList<PingResult> createRepeated() => $pb.PbList<PingResult>();
@$core.pragma('dart2js:noInline')
static PingResult getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<PingResult>(create);
static PingResult? _defaultInstance;
@$pb.TagNumber(1)
$core.String get pong => $_getSZ(0);
@$pb.TagNumber(1)
set pong($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasPong() => $_has(0);
@$pb.TagNumber(1)
void clearPong() => clearField(1);
}
const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names');

View File

@ -0,0 +1,11 @@
//
// Generated code. Do not modify.
// source: app.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import

View File

@ -0,0 +1,59 @@
//
// Generated code. Do not modify.
// source: app.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:async' as $async;
import 'dart:core' as $core;
import 'package:grpc/service_api.dart' as $grpc;
import 'package:protobuf/protobuf.dart' as $pb;
import 'app.pb.dart' as $0;
export 'app.pb.dart';
@$pb.GrpcServiceName('PingService')
class PingServiceClient extends $grpc.Client {
static final _$pingServer = $grpc.ClientMethod<$0.PingRequest, $0.PingResult>(
'/PingService/PingServer',
($0.PingRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.PingResult.fromBuffer(value));
PingServiceClient($grpc.ClientChannel channel,
{$grpc.CallOptions? options,
$core.Iterable<$grpc.ClientInterceptor>? interceptors})
: super(channel, options: options,
interceptors: interceptors);
$grpc.ResponseFuture<$0.PingResult> pingServer($0.PingRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$pingServer, request, options: options);
}
}
@$pb.GrpcServiceName('PingService')
abstract class PingServiceBase extends $grpc.Service {
$core.String get $name => 'PingService';
PingServiceBase() {
$addMethod($grpc.ServiceMethod<$0.PingRequest, $0.PingResult>(
'PingServer',
pingServer_Pre,
false,
false,
($core.List<$core.int> value) => $0.PingRequest.fromBuffer(value),
($0.PingResult value) => value.writeToBuffer()));
}
$async.Future<$0.PingResult> pingServer_Pre($grpc.ServiceCall call, $async.Future<$0.PingRequest> request) async {
return pingServer(call, await request);
}
$async.Future<$0.PingResult> pingServer($grpc.ServiceCall call, $0.PingRequest request);
}

View File

@ -0,0 +1,39 @@
//
// Generated code. Do not modify.
// source: app.proto
//
// @dart = 2.12
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
// ignore_for_file: constant_identifier_names, library_prefixes
// ignore_for_file: non_constant_identifier_names, prefer_final_fields
// ignore_for_file: unnecessary_import, unnecessary_this, unused_import
import 'dart:convert' as $convert;
import 'dart:core' as $core;
import 'dart:typed_data' as $typed_data;
@$core.Deprecated('Use pingRequestDescriptor instead')
const PingRequest$json = {
'1': 'PingRequest',
'2': [
{'1': 'name', '3': 1, '4': 1, '5': 9, '10': 'name'},
],
};
/// Descriptor for `PingRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List pingRequestDescriptor = $convert.base64Decode(
'CgtQaW5nUmVxdWVzdBISCgRuYW1lGAEgASgJUgRuYW1l');
@$core.Deprecated('Use pingResultDescriptor instead')
const PingResult$json = {
'1': 'PingResult',
'2': [
{'1': 'pong', '3': 1, '4': 1, '5': 9, '10': 'pong'},
],
};
/// Descriptor for `PingResult`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List pingResultDescriptor = $convert.base64Decode(
'CgpQaW5nUmVzdWx0EhIKBHBvbmcYASABKAlSBHBvbmc=');

View File

@ -119,7 +119,7 @@ class AboutUI extends BaseUI<AboutUIModel> {
),
onPressed: () {
launchUrlString(
"https://github.com/xkeyC/StarCitizenToolBox");
"https://github.com/StarCitizenToolBox/app");
},
),
],

View File

@ -147,7 +147,7 @@ class HomeUI extends BaseUI<HomeUIModel> {
? null
: () => model.launchRSI(),
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(6),
child: Icon(
model.isCurGameRunning
? FluentIcons.stop_solid
@ -161,7 +161,7 @@ class HomeUI extends BaseUI<HomeUIModel> {
const SizedBox(width: 12),
Button(
child: const Padding(
padding: EdgeInsets.all(8.0),
padding: EdgeInsets.all(6),
child: Icon(FluentIcons.folder_open),
),
onPressed: () => model.openDir(model.scInstalledPath)),

View File

@ -48,7 +48,7 @@ class IndexUI extends BaseUI<IndexUIModel> {
pane: NavigationPane(
selected: model.curIndex,
items: getNavigationPaneItems(model),
size: const NavigationPaneSize(openWidth: 160),
size: const NavigationPaneSize(openWidth: 64),
),
paneBodyBuilder: (item, child) {
// final name =
@ -97,8 +97,20 @@ class IndexUI extends BaseUI<IndexUIModel> {
return [
for (final kv in menus.entries)
PaneItem(
icon: Icon(kv.key),
title: Text(kv.value),
icon: Padding(
padding: const EdgeInsets.only(top: 6, bottom: 6, left: 4),
child: Column(
children: [
Icon(kv.key, size: 18),
const SizedBox(height: 3),
Text(
kv.value,
style: const TextStyle(fontSize: 11),
)
],
),
),
// title: Text(kv.value),
body: const SizedBox.shrink(),
onTap: () {
model.onIndexMenuTap(kv.value);

View File

@ -29,7 +29,7 @@ class ToolsUI extends BaseUI<ToolsUIModel> {
onPressed: model.working ? null : model.loadData,
child: const Padding(
padding: EdgeInsets.only(
top: 32, bottom: 32, left: 12, right: 12),
top: 30, bottom: 30, left: 12, right: 12),
child: Icon(FluentIcons.refresh),
),
),
@ -197,7 +197,7 @@ class ToolsUI extends BaseUI<ToolsUIModel> {
const SizedBox(width: 8),
Button(
child: const Padding(
padding: EdgeInsets.all(8.0),
padding: EdgeInsets.all(6),
child: Icon(FluentIcons.folder_open),
),
onPressed: () => model.openDir(model.scInstalledPath))
@ -234,7 +234,7 @@ class ToolsUI extends BaseUI<ToolsUIModel> {
const SizedBox(width: 8),
Button(
child: const Padding(
padding: EdgeInsets.all(8.0),
padding: EdgeInsets.all(6),
child: Icon(FluentIcons.folder_open),
),
onPressed: () => model.openDir(model.rsiLauncherInstalledPath))

View File

@ -64,6 +64,8 @@ dependencies:
hexcolor: ^3.0.1
dart_rss: ^3.0.1
html: ^0.15.4
protobuf: ^3.1.0
grpc: ^3.2.4
dependency_overrides:
http: ^1.1.2

1
update_grpc.bat Normal file
View File

@ -0,0 +1 @@
protoc --dart_out=grpc:lib/generated/grpc -I../sctoolbox_grpc/protos/ ../sctoolbox_grpc/protos/*.proto