diff --git a/lib/src/gh_snitch.dart b/lib/src/gh_snitch.dart index ff14665..e0dda9b 100644 --- a/lib/src/gh_snitch.dart +++ b/lib/src/gh_snitch.dart @@ -15,7 +15,7 @@ class GhSnitch { static GhSnitchInstance get _instance { return _ghSnitchDelegate ??= GhSnitchInstance.instance; } - + /// Listens to exceptions thrown in the app and reports them as issues on GitHub. /// /// This method sets up a Flutter error handler to catch uncaught exceptions and report them as issues on GitHub. @@ -69,7 +69,8 @@ class GhSnitch { String? screenShotBranch, List? labels, List? assignees, - int? milestone}) { + int? milestone, + String? userId}) { _handleNotInitialized(); return _instance.report( title: title, @@ -78,7 +79,8 @@ class GhSnitch { screenShotsBranch: screenShotBranch, labels: labels, assignees: assignees, - milestone: milestone); + milestone: milestone, + userId: userId); } /// Checks if the `GhSnitch` instance has been initialized or not. diff --git a/lib/src/utils/github_snitch_instance.dart b/lib/src/utils/github_snitch_instance.dart index 4285226..aa0f5e6 100644 --- a/lib/src/utils/github_snitch_instance.dart +++ b/lib/src/utils/github_snitch_instance.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'dart:developer'; import 'package:connectivity_plus/connectivity_plus.dart'; -import 'package:flutter_udid/flutter_udid.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:github_snitch/src/utils/extensions.dart'; @@ -35,6 +35,7 @@ class GhSnitchInstance { List? labels, List? assignees, int? milestone, + String? userId, bool fromCatch = false}) async { ConnectivityResult connectivity = await Connectivity().checkConnectivity(); if (!(connectivity == ConnectivityResult.none)) { @@ -50,12 +51,12 @@ class GhSnitchInstance { screenShotsBranch: screenShotsBranch!); url = "\n## ScreenShot \n![]($url)"; } - String deviceId = await FlutterUdid.udid; + String? id = userId ?? await deviceId; Map issueBody = { ownerBody: owner, repoBody: repo, bodyTitle: title, - bodyBody: '$body$url\n$deviceId', + bodyBody: '$body$url\n$id', }; if (assignees != null) { issueBody["assignees"] = assignees; @@ -242,11 +243,11 @@ class GhSnitchInstance { } /// Retrieves all the comments made on the issues reported by the current user. - Future getReportsComments() async { + Future getReportsComments({String? userId}) async { final Issue issues = Issue(); - String deviceId = await FlutterUdid.udid; - List userIssues = await getIssuesByUserID(deviceId); + String? id = userId ?? await deviceId; + List userIssues = await getIssuesByUserID(id ?? ''); for (Issue issue in userIssues) { String listCommentsEp = "$owner/$repo/issues/${issue.id}/comments"; GhResponse response = await ghRequest.request("GET", listCommentsEp); @@ -257,13 +258,14 @@ class GhSnitchInstance { } /// Submits a comment to the specified issue. - Future submitComment(String reportId, String comment) async { + Future submitComment(String reportId, String comment, + {String? userId}) async { bool commented = false; String submitCommentEp = "$owner/$repo/issues/$reportId/comments"; - String deviceId = await FlutterUdid.udid; + String? id = userId ?? await deviceId; Map commentBody = { commentsBodyField: - "$comment\n${deviceIdTemplate.replaceFirst(idMark, deviceId)}" + "$comment\n${deviceIdTemplate.replaceFirst(idMark, id ?? '')}" }; String commentBodyToString = json.encode(commentBody); GhResponse response = await ghRequest.request("POST", submitCommentEp, @@ -306,4 +308,24 @@ class GhSnitchInstance { } return null; } + + Future get deviceId async { + final deviceInfoPlugin = DeviceInfoPlugin(); + String? id; + if (kIsWeb) { + id = + (await deviceInfoPlugin.webBrowserInfo).userAgent.hashCode.toString(); + } else { + id = switch (defaultTargetPlatform) { + TargetPlatform.android => (await deviceInfoPlugin.androidInfo).id, + TargetPlatform.iOS => + (await deviceInfoPlugin.iosInfo).identifierForVendor, + TargetPlatform.linux => (await deviceInfoPlugin.linuxInfo).id, + TargetPlatform.windows => (await deviceInfoPlugin.windowsInfo).deviceId, + TargetPlatform.macOS => (await deviceInfoPlugin.macOsInfo).systemGUID, + TargetPlatform.fuchsia => null + }; + } + return id; + } } diff --git a/pubspec.yaml b/pubspec.yaml index b04a45e..4b1b3a1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,6 @@ environment: flutter: ">=1.17.0" dependencies: - flutter_udid: ^2.0.1 flutter: sdk: flutter http: ^0.13.5 @@ -16,6 +15,7 @@ dependencies: universal_io: ^2.0.4 string_similarity: ^2.0.0 connectivity_plus: ^4.0.1 + device_info_plus: ^9.0.2 dev_dependencies: flutter_test: