Skip to content

Commit

Permalink
git tag v1.0.5+5
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTServ committed Mar 17, 2024
1 parent c68451b commit 3669a88
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.5+5]

* share gateway QR

## [1.0.5+4]

* update
Expand Down
102 changes: 89 additions & 13 deletions lib/gateway/GatewayQrPage.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:openiothub_api/openiothub_api.dart';
import 'package:openiothub_grpc_api/proto/manager/publicApi.pb.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:openiothub_constants/openiothub_constants.dart';
import 'package:wechat_kit/wechat_kit.dart';

class GatewayQrPage extends StatefulWidget {
const GatewayQrPage({super.key});
Expand All @@ -14,12 +20,34 @@ class GatewayQrPage extends StatefulWidget {
class _GatewayQrPageState extends State<GatewayQrPage> {
String qRCodeForMobileAdd = "https://iothub.cloud";

StreamSubscription<WechatResp>? _share;

void _listenShareMsg(WechatResp resp) {
// final String content = 'share: ${resp.errorCode} ${resp.errorMsg}';
if (resp.errorCode == 0) {
showToast("分享成功!");
} else {
showToast("分享失败!");
}
}

@override
void initState() {
_generateJwtQRCodePair();
if (_share == null && (Platform.isAndroid || Platform.isIOS)) {
_share = WechatKitPlatform.instance.respStream().listen(_listenShareMsg);
}
super.initState();
}

@override
void dispose() {
if (_share != null && (Platform.isAndroid || Platform.isIOS)) {
_share!.cancel();
}
super.dispose();
}

@override
Widget build(BuildContext context) {
// return Text("data");
Expand All @@ -30,10 +58,21 @@ class _GatewayQrPageState extends State<GatewayQrPage> {
// );
return Scaffold(
appBar: AppBar(
title: Text("作为网关"),
actions: <Widget>[],
title: Text("本机作为网关"),
actions: <Widget>[
// TODO 以图片或者小程序方式分享给其他人
IconButton(
icon: Icon(
Icons.share,
// color: Colors.white,
),
onPressed: () {
_shareAction();
}),
],
),
body: Container(
padding: const EdgeInsets.fromLTRB(0, 80, 0, 0),
child: ListView(children: [
Center(
child: QrImageView(
Expand All @@ -59,29 +98,66 @@ class _GatewayQrPageState extends State<GatewayQrPage> {

Future<void> _generateJwtQRCodePair() async {
// TODO 先检查本地存储有没有保存的网关配置,如果有则使用旧的启动
const Gateway_Jwt_KEY = "GATEWAY_JWT_KEY";
const QR_Code_For_Mobile_Add_KEY = "QR_Code_For_Mobile_Add";
SharedPreferences prefs = await SharedPreferences.getInstance();

if (prefs.containsKey(Gateway_Jwt_KEY) &&
prefs.containsKey(QR_Code_For_Mobile_Add_KEY)) {
var gatewayJwt = prefs.getString(Gateway_Jwt_KEY)!;
if (prefs.containsKey(SharedPreferencesKey.Gateway_Jwt_KEY) &&
prefs.containsKey(SharedPreferencesKey.QR_Code_For_Mobile_Add_KEY)) {
var gatewayJwt = prefs.getString(SharedPreferencesKey.Gateway_Jwt_KEY)!;
setState(() {
qRCodeForMobileAdd = prefs.getString(QR_Code_For_Mobile_Add_KEY)!;
qRCodeForMobileAdd =
prefs.getString(SharedPreferencesKey.QR_Code_For_Mobile_Add_KEY)!;
});
await GatewayLoginManager.LoginServerByToken(
gatewayJwt, "127.0.0.1", 55443);
gatewayJwt, Config.gatewayGrpcIp, Config.gatewayGrpcPort);
} else {
JwtQRCodePair? jwtQRCodePair = await PublicApi.GenerateJwtQRCodePair();
setState(() {
qRCodeForMobileAdd = jwtQRCodePair.qRCodeForMobileAdd;
});
// TODO 保存网关(网格ID)到本地存储,当前刷新二维码的时候清楚前面的存储保存最新的网关配置
prefs.setString(Gateway_Jwt_KEY, jwtQRCodePair.gatewayJwt);
prefs.setString(
QR_Code_For_Mobile_Add_KEY, jwtQRCodePair.qRCodeForMobileAdd);
await GatewayLoginManager.LoginServerByToken(
jwtQRCodePair.gatewayJwt, "127.0.0.1", 55443);
SharedPreferencesKey.Gateway_Jwt_KEY, jwtQRCodePair.gatewayJwt);
prefs.setString(SharedPreferencesKey.QR_Code_For_Mobile_Add_KEY,
jwtQRCodePair.qRCodeForMobileAdd);
await GatewayLoginManager.LoginServerByToken(jwtQRCodePair.gatewayJwt,
Config.gatewayGrpcIp, Config.gatewayGrpcPort);
}
}

// 分享网关
_shareAction() async {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("分享到微信"),
content: Text("选择需方分享的位置"),
actions: <Widget>[
TextButton(
child: Text("分享链接到个人"),
onPressed: () {
WechatKitPlatform.instance.shareWebpage(
scene: WechatScene.kSession,
title: "云亿连网关分享",
description: "通过云亿连网关管理您的所有智能设备和私有云",
// thumbData:,
webpageUrl: qRCodeForMobileAdd,
);
Navigator.of(context).pop();
},
),
// TextButton(
// child: Text("分享到朋友圈"),
// onPressed: () {
// WechatKitPlatform.instance.shareWebpage(
// scene: WechatScene.kTimeline,
// title: "云亿连网关分享",
// description: "通过云亿连网关管理您的所有智能设备和私有云",
// // thumbData:,
// webpageUrl: qRCodeForMobileAdd,
// );
// Navigator.of(context).pop();
// },
// )
]));
}
}
32 changes: 16 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ packages:
dependency: transitive
description:
name: google_identity_services_web
sha256: "972ff30eebf6a5eab28be3e1e47a45df087ed64d5aefdac0df47758ecdec5385"
sha256: "9482364c9f8b7bd36902572ebc3a7c2b5c8ee57a9c93e6eb5099c1a9ec5265d8"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.1"
version: "0.3.1+1"
googleapis_auth:
dependency: transitive
description:
name: googleapis_auth
sha256: "772779fe28a8b70939eab9c390a5f8f46cbb59bda9f1f10ea60dd894eff59ff0"
sha256: cafc46446574fd42826aa4cd4d623c94482598fda0a5a5649bf2781bcbc09258
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.4.2"
version: "1.5.0"
grpc:
dependency: transitive
description:
Expand Down Expand Up @@ -436,10 +436,10 @@ packages:
dependency: "direct main"
description:
name: openiothub_constants
sha256: d7a245b7e039631c7e69335027ce1d4134129cf6372f33e532fc602726b65c1c
sha256: e8de1700201d5f1e2fe7d9a498e0162d9a2c503ba43eda614fbe769c12ab3f95
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
version: "1.0.1+3"
openiothub_grpc_api:
dependency: "direct main"
description:
Expand Down Expand Up @@ -777,10 +777,10 @@ packages:
dependency: transitive
description:
name: url_launcher_ios
sha256: "75bb6fe3f60070407704282a2d295630cab232991eb52542b18347a8a941df03"
sha256: "9149d493b075ed740901f3ee844a38a00b33116c7c5c10d7fb27df8987fb51d5"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.2.4"
version: "6.2.5"
url_launcher_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -849,10 +849,10 @@ packages:
dependency: transitive
description:
name: web
sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad"
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.0"
version: "0.5.1"
webview_flutter:
dependency: transitive
description:
Expand All @@ -865,10 +865,10 @@ packages:
dependency: transitive
description:
name: webview_flutter_android
sha256: "3e5f4e9d818086b0d01a66fb1ff9cc72ab0cc58c71980e3d3661c5685ea0efb0"
sha256: f038ee2fae73b509dde1bc9d2c5a50ca92054282de17631a9a3d515883740934
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.15.0"
version: "3.16.0"
webview_flutter_platform_interface:
dependency: transitive
description:
Expand All @@ -881,10 +881,10 @@ packages:
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: "9bf168bccdf179ce90450b5f37e36fe263f591c9338828d6bf09b6f8d0f57f86"
sha256: f12f8d8a99784b863e8b85e4a9a5e3cf1839d6803d2c0c3e0533a8f3c5a992a7
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.12.0"
version: "3.13.0"
wechat_kit:
dependency: "direct main"
description:
Expand Down Expand Up @@ -913,10 +913,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480"
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.2.0"
version: "5.3.0"
xdg_directories:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: openiothub_common_pages
description: openiothub_common_pages
version: 1.0.5+4
version: 1.0.5+5
homepage: https://github.com/OpenIoTHub

environment:
Expand Down

0 comments on commit 3669a88

Please sign in to comment.