Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
auto_track_plugin
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
顾海波
2025-02-12 09:58:43 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c72261e64edbf586488de318acccca607907b8d3
c72261e6
1 parent
72abfdc3
【需求】补充上报信息
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
17 deletions
example/lib/main.dart
example/pubspec.lock
lib/auto_track/config/config.dart
lib/auto_track/config/manager.dart
lib/auto_track/config/queue.dart
pubspec.yaml
example/lib/main.dart
View file @
c72261e
...
...
@@ -19,6 +19,7 @@ class _MyAppState extends State<MyApp> {
void
initState
()
{
AutoTrack
()
.
config
(
AutoTrackConfig
(
buildContext:
context
,
host:
"https://sitigrs.boeart.cn"
,
appKey:
"KEY_oVfNOQLQ"
,
appSecret:
"w21tRLJt7LBVYJtD"
,
...
...
example/pubspec.lock
View file @
c72261e
...
...
@@ -17,6 +17,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.6.1"
args:
dependency: transitive
description:
name: args
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.0"
async:
dependency: transitive
description:
...
...
@@ -64,6 +72,23 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.18.0"
connectivity_plus:
dependency: transitive
description:
path: "packages/connectivity_plus/connectivity_plus"
ref: HEAD
resolved-ref: ff774d947bd15d9be08629e3ccfb29dda2e864bd
url: "https://gitee.com/openharmony-sig/flutter_plus_plugins"
source: git
version: "5.0.1"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.4"
crypto:
dependency: transitive
description:
...
...
@@ -80,6 +105,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.8"
dbus:
dependency: transitive
description:
name: dbus
sha256: "79e0c23480ff85dc68de79e2cd6334add97e48f7f4865d17686dd6ea81a47e8c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.11"
device_info_plus:
dependency: transitive
description:
...
...
@@ -183,6 +216,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
...
...
@@ -239,6 +280,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.12.0"
nm:
dependency: transitive
description:
name: nm
sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.0"
package_info_plus:
dependency: transitive
description:
...
...
@@ -264,6 +313,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.0"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.0.2"
platform:
dependency: transitive
description:
...
...
@@ -445,6 +502,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.5"
xml:
dependency: transitive
description:
name: xml
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
...
...
lib/auto_track/config/config.dart
View file @
c72261e
...
...
@@ -2,6 +2,7 @@ import 'dart:convert';
import
'package:auto_track/auto_track/utils/track_model.dart'
;
import
'package:crypto/crypto.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:uuid/uuid.dart'
;
...
...
@@ -9,6 +10,7 @@ typedef EventHandlerFunc = void Function(TrackModel);
class
AutoTrackConfig
{
AutoTrackConfig
({
this
.
buildContext
,
this
.
host
,
// 数据上报地址
this
.
uploadInterval
,
// 数据上报间隔
this
.
samplingRate
=
1
,
// 采样率
...
...
@@ -37,6 +39,8 @@ class AutoTrackConfig {
httpRequestConfig
??=
HttpRequestConfig
();
}
BuildContext
?
buildContext
;
String
?
host
;
String
?
appKey
;
String
?
appSecret
;
...
...
lib/auto_track/config/manager.dart
View file @
c72261e
...
...
@@ -24,6 +24,7 @@ class AutoTrackConfigManager {
PackageInfo
.
fromPlatform
().
then
(
(
value
)
{
_appVersion
=
value
.
version
;
_appName
=
value
.
appName
;
_pkgName
=
value
.
packageName
;
});
DeviceInfoPlugin
().
deviceInfo
.
then
((
value
)
{
_deviceInfo
=
value
.
data
;
...
...
@@ -38,6 +39,8 @@ class AutoTrackConfigManager {
String
_appName
=
''
;
String
get
appName
=>
_appName
;
String
_pkgName
=
''
;
String
get
pkgName
=>
_pkgName
;
BaseDeviceInfo
?
_baseDeviceInfo
;
BaseDeviceInfo
?
get
baseDeviceInfo
=>
_baseDeviceInfo
;
...
...
lib/auto_track/config/queue.dart
View file @
c72261e
...
...
@@ -7,9 +7,10 @@ import 'package:archive/archive.dart';
import
'package:auto_track/auto_track/config/manager.dart'
;
import
'package:auto_track/auto_track/utils/track_model.dart'
;
import
'package:device_info_plus/device_info_plus.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:path/path.dart'
as
path
;
import
'package:sqflite/sqflite.dart'
;
import
'package:connectivity_plus/connectivity_plus.dart'
;
import
'../log/logger.dart'
;
class
AutoTrackQueue
{
...
...
@@ -79,6 +80,7 @@ class AutoTrackQueue {
}
Future
<
void
>
flush
()
async
{
try
{
AutoTrackLogger
.
getInstance
().
debug
(
"@@@start flush"
);
if
(
database
==
null
)
{
...
...
@@ -90,6 +92,10 @@ class AutoTrackQueue {
List
<
Map
<
String
,
dynamic
>>
events
=
await
database
.
query
(
"track"
,
columns:
[
"id"
,
"event"
,
"date"
],
limit:
100
);
if
(
events
.
isEmpty
)
{
AutoTrackLogger
.
getInstance
().
debug
(
"@@@events is empty"
);
return
;
}
for
(
var
event
in
events
)
{
Track
model
=
Track
.
fromMap
(
event
);
...
...
@@ -110,6 +116,18 @@ class AutoTrackQueue {
AutoTrackConfigManager
.
instance
.
getToken
(
true
);
return
;
}
ConnectivityResult
connectivityResult
=
await
Connectivity
().
checkConnectivity
();
Map
<
ConnectivityResult
,
String
>
map
=
{
ConnectivityResult
.
mobile
:
'MOBILE'
,
ConnectivityResult
.
wifi
:
'WIFI'
,
ConnectivityResult
.
ethernet
:
'ETHERNET'
,
ConnectivityResult
.
vpn
:
'VPN'
,
ConnectivityResult
.
other
:
'OTHER'
,
ConnectivityResult
.
none
:
'NONE'
,
};
if
(
host
!=
null
)
{
List
<
Map
>
datas
=
[];
uploadList
.
forEach
((
event
)
{
...
...
@@ -140,6 +158,15 @@ class AutoTrackQueue {
manufacturer
=
'huawei'
;
}
}
Size
size
=
const
Size
(
0
,
0
);
if
(
config
.
buildContext
!=
null
)
{
size
=
Size
(
MediaQuery
.
of
(
config
.
buildContext
!).
size
.
width
*
MediaQuery
.
of
(
config
.
buildContext
!).
devicePixelRatio
,
MediaQuery
.
of
(
config
.
buildContext
!).
size
.
width
*
MediaQuery
.
of
(
config
.
buildContext
!).
devicePixelRatio
);
}
final
properties
=
{
'
\
$os
'
:
os
,
'
\
$os_version
'
:
os_version
,
...
...
@@ -150,23 +177,19 @@ class AutoTrackQueue {
'
\
$device_id
'
:
AutoTrackConfigManager
.
instance
.
deviceId
,
'
\
$timezone_offset
'
:
getZoneOffset
(),
"
\
$manufacturer
"
:
manufacturer
,
"
\
$screen_width
"
:
size
.
width
,
"
\
$screen_height
"
:
size
.
height
,
"
\
$app_id
"
:
AutoTrackConfigManager
.
instance
.
pkgName
,
"
\
$lib_version
"
:
"6.0.0"
,
"
\
$network_type
"
:
map
[
connectivityResult
],
"
\
$wifi
"
:
connectivityResult
==
ConnectivityResult
.
wifi
,
// "$carrier": "NONE",
// "$os_version": "13",
// "$model": "C310CS",
// "$os": "Android",
// "$screen_width": 1200,
// "$brand": "BOE",
// "$screen_height": 1920,
// "$device_id": "afa4c7a98b3f6467",
// "$app_name": "Ewin Reading",
// "$lib_version": "5.3.3",
// "$timezone_offset": -480,
// "$app_id": "com.ewin.tech.reading",
// "$mac": "020000000000",
// "$manufacturer": "BOE",
// "$sn": "C310CS014820000006",
// "$wifi": true,
// "$network_type": "WIFI",
// "$screen_orientation": "portrait",
// "$screen_brightness": 204,
// "$event_duration": 0,
...
...
@@ -196,7 +219,8 @@ class AutoTrackQueue {
final
httpClient
=
HttpClient
();
final
request
=
await
httpClient
.
postUrl
(
Uri
.
parse
(
host
+
UPLOAD
));
request
.
headers
.
set
(
HttpHeaders
.
contentTypeHeader
,
"application/json"
);
request
.
headers
.
set
(
HttpHeaders
.
contentTypeHeader
,
"application/json"
);
request
.
headers
.
set
(
"token"
,
token
);
// 设置 header
// 对数据进行压缩并进行 Base64 编码
...
...
@@ -227,13 +251,12 @@ class AutoTrackQueue {
}
else
{
//批量删除
for
(
var
event
in
events
)
{
await
database
.
delete
(
"track"
,
where:
"id = ?"
,
whereArgs:
[
event
[
'id'
]]);
await
database
.
delete
(
"track"
,
where:
"id = ?"
,
whereArgs:
[
event
[
'id'
]]);
}
}
}
catch
(
e
)
{
AutoTrackLogger
.
getInstance
().
debug
(
"JSON 解析错误:
$e
"
);
}
}
else
{
AutoTrackLogger
.
getInstance
().
debug
(
...
...
@@ -243,6 +266,9 @@ class AutoTrackQueue {
AutoTrackLogger
.
getInstance
().
debug
(
"网络请求错误:
$e
"
);
}
}
}
catch
(
e
)
{
AutoTrackLogger
.
getInstance
().
debug
(
"上报出错"
);
}
}
int
getZoneOffset
()
{
...
...
pubspec.yaml
View file @
c72261e
...
...
@@ -26,7 +26,10 @@ dependencies:
uuid
:
^4.3.3
archive
:
^3.3.7
# 确保使用最新版本
sqflite
:
^2.3.0
connectivity_plus
:
git
:
url
:
https://gitee.com/openharmony-sig/flutter_plus_plugins
path
:
packages/connectivity_plus/connectivity_plus
...
...
Please
register
or
login
to post a comment