community-cordova-plugin-wifi 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +32 -11
- package/package.json +2 -1
- package/plugin.xml +1 -2
- package/src/android/WifiPlugin.java +147 -1
- package/types/index.d.ts +32 -0
- package/www/plugin.js +10 -0
- package/src/android/PingTask.java +0 -56
package/.idea/workspace.xml
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
9
9
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
10
10
|
<change beforePath="$PROJECT_DIR$/plugin.xml" beforeDir="false" afterPath="$PROJECT_DIR$/plugin.xml" afterDir="false" />
|
|
11
|
+
<change beforePath="$PROJECT_DIR$/src/android/PingTask.java" beforeDir="false" />
|
|
11
12
|
<change beforePath="$PROJECT_DIR$/src/android/WifiPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiPlugin.java" afterDir="false" />
|
|
13
|
+
<change beforePath="$PROJECT_DIR$/types/index.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/types/index.d.ts" afterDir="false" />
|
|
14
|
+
<change beforePath="$PROJECT_DIR$/www/plugin.js" beforeDir="false" afterPath="$PROJECT_DIR$/www/plugin.js" afterDir="false" />
|
|
12
15
|
</list>
|
|
13
16
|
<option name="SHOW_DIALOG" value="false" />
|
|
14
17
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -24,14 +27,12 @@
|
|
|
24
27
|
"assignee": "EYALIN"
|
|
25
28
|
}
|
|
26
29
|
}</component>
|
|
27
|
-
<component name="GithubPullRequestsUISettings">
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</option>
|
|
34
|
-
</component>
|
|
30
|
+
<component name="GithubPullRequestsUISettings">{
|
|
31
|
+
"selectedUrlAndAccountId": {
|
|
32
|
+
"url": "https://github.com/EYALIN/community-cordova-plugin-cpu.git",
|
|
33
|
+
"accountId": "554cb47e-af38-4ebf-8263-4816fa246779"
|
|
34
|
+
}
|
|
35
|
+
}</component>
|
|
35
36
|
<component name="MarkdownSettingsMigration">
|
|
36
37
|
<option name="stateVersion" value="1" />
|
|
37
38
|
</component>
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"keyToString": {
|
|
49
50
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
50
51
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
52
|
+
"RunOnceActivity.git.unshallow": "true",
|
|
51
53
|
"WebServerToolWindowFactoryState": "false",
|
|
52
54
|
"git-widget-placeholder": "main",
|
|
53
55
|
"last_opened_file_path": "/Volumes/Development/Git/forked/community-cordova-plugin-wifi/src/android",
|
|
@@ -57,7 +59,7 @@
|
|
|
57
59
|
"node.js.selected.package.tslint": "(autodetect)",
|
|
58
60
|
"nodejs_package_manager_path": "npm",
|
|
59
61
|
"settings.editor.selected.configurable": "preferences.lookFeel",
|
|
60
|
-
"ts.external.directory.path": "/Applications/WebStorm.app/Contents/plugins/javascript-
|
|
62
|
+
"ts.external.directory.path": "/Applications/WebStorm.app/Contents/plugins/javascript-plugin/jsLanguageServicesImpl/external",
|
|
61
63
|
"vue.rearranger.settings.migration": "true"
|
|
62
64
|
}
|
|
63
65
|
}</component>
|
|
@@ -70,6 +72,13 @@
|
|
|
70
72
|
<recent name="$PROJECT_DIR$/src" />
|
|
71
73
|
</key>
|
|
72
74
|
</component>
|
|
75
|
+
<component name="SharedIndexes">
|
|
76
|
+
<attachedChunks>
|
|
77
|
+
<set>
|
|
78
|
+
<option value="bundled-js-predefined-d6986cc7102b-09060db00ec0-JavaScript-WS-251.29188.1" />
|
|
79
|
+
</set>
|
|
80
|
+
</attachedChunks>
|
|
81
|
+
</component>
|
|
73
82
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
74
83
|
<component name="TaskManager">
|
|
75
84
|
<task active="true" id="Default" summary="Default task">
|
|
@@ -103,7 +112,11 @@
|
|
|
103
112
|
<workItem from="1724268174858" duration="4603000" />
|
|
104
113
|
<workItem from="1725518446319" duration="57000" />
|
|
105
114
|
<workItem from="1725611591287" duration="21000" />
|
|
106
|
-
<workItem from="1731667624026" duration="
|
|
115
|
+
<workItem from="1731667624026" duration="1162000" />
|
|
116
|
+
<workItem from="1751262475820" duration="4500000" />
|
|
117
|
+
<workItem from="1768033742670" duration="45000" />
|
|
118
|
+
<workItem from="1768033992593" duration="17000" />
|
|
119
|
+
<workItem from="1768035366231" duration="829000" />
|
|
107
120
|
</task>
|
|
108
121
|
<task id="LOCAL-00001" summary="update plugin">
|
|
109
122
|
<option name="closed" value="true" />
|
|
@@ -201,7 +214,15 @@
|
|
|
201
214
|
<option name="project" value="LOCAL" />
|
|
202
215
|
<updated>1723350242605</updated>
|
|
203
216
|
</task>
|
|
204
|
-
<
|
|
217
|
+
<task id="LOCAL-00013" summary="* add export to all interfaces">
|
|
218
|
+
<option name="closed" value="true" />
|
|
219
|
+
<created>1731669745130</created>
|
|
220
|
+
<option name="number" value="00013" />
|
|
221
|
+
<option name="presentableId" value="LOCAL-00013" />
|
|
222
|
+
<option name="project" value="LOCAL" />
|
|
223
|
+
<updated>1731669745130</updated>
|
|
224
|
+
</task>
|
|
225
|
+
<option name="localTasksCounter" value="14" />
|
|
205
226
|
<servers />
|
|
206
227
|
</component>
|
|
207
228
|
<component name="TypeScriptGeneratedFilesManager">
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
4
|
id="community-cordova-plugin-wifi"
|
|
5
|
-
version="1.0.
|
|
5
|
+
version="1.0.9">
|
|
6
6
|
<name>Cordova Plugin Wifi</name>
|
|
7
7
|
<description></description>
|
|
8
8
|
<license>MIT</license>
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
|
|
38
38
|
<source-file src="src/android/WifiPlugin.java" target-dir="src/android" />
|
|
39
39
|
<source-file src="src/android/IpInfoUtils.java" target-dir="src/android" />
|
|
40
|
-
<source-file src="src/android/PingTask.java" target-dir="src/android" />
|
|
41
40
|
<source-file src="src/android/WifiDetailsUtils.java" target-dir="src/android" />
|
|
42
41
|
<source-file src="src/android/WifiUtils.java" target-dir="src/android" />
|
|
43
42
|
</platform>
|
|
@@ -2,6 +2,7 @@ package wifiplugin;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.net.ConnectivityManager;
|
|
5
|
+
import android.net.DhcpInfo;
|
|
5
6
|
import android.net.Network;
|
|
6
7
|
import android.net.NetworkCapabilities;
|
|
7
8
|
import android.net.NetworkRequest;
|
|
@@ -10,6 +11,7 @@ import android.net.wifi.WifiConfiguration;
|
|
|
10
11
|
import android.net.wifi.WifiInfo;
|
|
11
12
|
import android.net.wifi.WifiManager;
|
|
12
13
|
import android.os.Build;
|
|
14
|
+
import android.text.format.Formatter;
|
|
13
15
|
import androidx.annotation.RequiresApi;
|
|
14
16
|
import android.net.wifi.WifiNetworkSpecifier;
|
|
15
17
|
import android.net.NetworkSpecifier;
|
|
@@ -39,7 +41,7 @@ public class WifiPlugin extends CordovaPlugin {
|
|
|
39
41
|
String address = args.getString(0);
|
|
40
42
|
int count = args.getInt(1);
|
|
41
43
|
int timeout = args.getInt(2);
|
|
42
|
-
|
|
44
|
+
// PingTask.ping(address, count, timeout, callbackContext, cordova);
|
|
43
45
|
return true;
|
|
44
46
|
} else if ("getIpInfo".equals(action)) {
|
|
45
47
|
IpInfoUtils.getIpInfo(cordova, callbackContext);
|
|
@@ -79,6 +81,9 @@ public class WifiPlugin extends CordovaPlugin {
|
|
|
79
81
|
} else if ("wifiToggle".equals(action)) {
|
|
80
82
|
wifiToggle(callbackContext);
|
|
81
83
|
return true;
|
|
84
|
+
} else if ("getNetworkDiagnostics".equals(action)) {
|
|
85
|
+
getNetworkDiagnostics(callbackContext);
|
|
86
|
+
return true;
|
|
82
87
|
}
|
|
83
88
|
return false;
|
|
84
89
|
}
|
|
@@ -279,4 +284,145 @@ WifiManager wifiManager = (WifiManager) cordova.getActivity().getApplicationCont
|
|
|
279
284
|
wifiManager.disconnect();
|
|
280
285
|
callbackContext.success("Disconnected from Wi-Fi network");
|
|
281
286
|
}
|
|
287
|
+
|
|
288
|
+
private void getNetworkDiagnostics(CallbackContext callbackContext) {
|
|
289
|
+
cordova.getThreadPool().execute(() -> {
|
|
290
|
+
try {
|
|
291
|
+
JSONObject diagnostics = new JSONObject();
|
|
292
|
+
Context context = cordova.getActivity().getApplicationContext();
|
|
293
|
+
|
|
294
|
+
// Get connectivity information
|
|
295
|
+
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
296
|
+
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
297
|
+
|
|
298
|
+
// Connection status
|
|
299
|
+
JSONObject connectionStatus = new JSONObject();
|
|
300
|
+
boolean isConnectedToInternet = false;
|
|
301
|
+
boolean isConnectedToWifi = false;
|
|
302
|
+
String connectionType = "None";
|
|
303
|
+
|
|
304
|
+
if (connectivityManager != null) {
|
|
305
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
306
|
+
Network network = connectivityManager.getActiveNetwork();
|
|
307
|
+
if (network != null) {
|
|
308
|
+
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
|
|
309
|
+
if (networkCapabilities != null) {
|
|
310
|
+
isConnectedToInternet = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
|
|
311
|
+
networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
|
|
312
|
+
isConnectedToWifi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
|
|
313
|
+
|
|
314
|
+
if (isConnectedToWifi) {
|
|
315
|
+
connectionType = "WiFi";
|
|
316
|
+
} else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
|
317
|
+
connectionType = "Cellular";
|
|
318
|
+
} else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
|
|
319
|
+
connectionType = "VPN";
|
|
320
|
+
} else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) {
|
|
321
|
+
connectionType = "Ethernet";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
|
327
|
+
isConnectedToInternet = activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
328
|
+
if (activeNetworkInfo != null) {
|
|
329
|
+
connectionType = activeNetworkInfo.getTypeName();
|
|
330
|
+
isConnectedToWifi = activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
connectionStatus.put("isConnectedToInternet", isConnectedToInternet);
|
|
336
|
+
connectionStatus.put("isConnectedToWifi", isConnectedToWifi);
|
|
337
|
+
connectionStatus.put("connectionType", connectionType);
|
|
338
|
+
connectionStatus.put("isWifiEnabled", wifiManager != null && wifiManager.isWifiEnabled());
|
|
339
|
+
diagnostics.put("connectionStatus", connectionStatus);
|
|
340
|
+
|
|
341
|
+
// WiFi details (if connected)
|
|
342
|
+
if (isConnectedToWifi && wifiManager != null) {
|
|
343
|
+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
344
|
+
DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
|
|
345
|
+
|
|
346
|
+
JSONObject wifiDetails = new JSONObject();
|
|
347
|
+
wifiDetails.put("ssid", wifiInfo.getSSID().replace("\"", ""));
|
|
348
|
+
wifiDetails.put("bssid", wifiInfo.getBSSID());
|
|
349
|
+
wifiDetails.put("ipAddress", Formatter.formatIpAddress(wifiInfo.getIpAddress()));
|
|
350
|
+
wifiDetails.put("macAddress", wifiInfo.getMacAddress());
|
|
351
|
+
wifiDetails.put("linkSpeed", wifiInfo.getLinkSpeed());
|
|
352
|
+
wifiDetails.put("linkSpeedUnit", "Mbps");
|
|
353
|
+
wifiDetails.put("rssi", wifiInfo.getRssi());
|
|
354
|
+
wifiDetails.put("frequency", wifiInfo.getFrequency());
|
|
355
|
+
wifiDetails.put("channel", getChannelFromFrequency(wifiInfo.getFrequency()));
|
|
356
|
+
wifiDetails.put("gateway", Formatter.formatIpAddress(dhcpInfo.gateway));
|
|
357
|
+
wifiDetails.put("dns1", Formatter.formatIpAddress(dhcpInfo.dns1));
|
|
358
|
+
wifiDetails.put("dns2", Formatter.formatIpAddress(dhcpInfo.dns2));
|
|
359
|
+
wifiDetails.put("networkId", wifiInfo.getNetworkId());
|
|
360
|
+
|
|
361
|
+
// Signal quality
|
|
362
|
+
int signalLevel = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 5);
|
|
363
|
+
String signalQuality;
|
|
364
|
+
if (signalLevel >= 4) signalQuality = "excellent";
|
|
365
|
+
else if (signalLevel >= 3) signalQuality = "good";
|
|
366
|
+
else if (signalLevel >= 2) signalQuality = "fair";
|
|
367
|
+
else signalQuality = "poor";
|
|
368
|
+
wifiDetails.put("signalLevel", signalLevel);
|
|
369
|
+
wifiDetails.put("signalQuality", signalQuality);
|
|
370
|
+
|
|
371
|
+
diagnostics.put("wifiDetails", wifiDetails);
|
|
372
|
+
} else {
|
|
373
|
+
diagnostics.put("wifiDetails", JSONObject.NULL);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Network performance indicators
|
|
377
|
+
JSONObject performance = new JSONObject();
|
|
378
|
+
if (isConnectedToWifi && wifiManager != null) {
|
|
379
|
+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
380
|
+
int rssi = wifiInfo.getRssi();
|
|
381
|
+
int linkSpeed = wifiInfo.getLinkSpeed();
|
|
382
|
+
|
|
383
|
+
// Overall network health score (0-100)
|
|
384
|
+
int healthScore = 0;
|
|
385
|
+
if (rssi >= -50) healthScore += 40;
|
|
386
|
+
else if (rssi >= -60) healthScore += 30;
|
|
387
|
+
else if (rssi >= -70) healthScore += 20;
|
|
388
|
+
else healthScore += 10;
|
|
389
|
+
|
|
390
|
+
if (linkSpeed >= 100) healthScore += 40;
|
|
391
|
+
else if (linkSpeed >= 50) healthScore += 30;
|
|
392
|
+
else if (linkSpeed >= 20) healthScore += 20;
|
|
393
|
+
else healthScore += 10;
|
|
394
|
+
|
|
395
|
+
if (isConnectedToInternet) healthScore += 20;
|
|
396
|
+
|
|
397
|
+
performance.put("healthScore", healthScore);
|
|
398
|
+
|
|
399
|
+
// Determine status
|
|
400
|
+
String status;
|
|
401
|
+
if (healthScore >= 80) status = "excellent";
|
|
402
|
+
else if (healthScore >= 60) status = "good";
|
|
403
|
+
else if (healthScore >= 40) status = "fair";
|
|
404
|
+
else status = "poor";
|
|
405
|
+
performance.put("status", status);
|
|
406
|
+
} else {
|
|
407
|
+
performance.put("healthScore", 0);
|
|
408
|
+
performance.put("status", "disconnected");
|
|
409
|
+
}
|
|
410
|
+
diagnostics.put("performance", performance);
|
|
411
|
+
|
|
412
|
+
callbackContext.success(diagnostics);
|
|
413
|
+
} catch (Exception e) {
|
|
414
|
+
Log.e(TAG, "Error getting network diagnostics", e);
|
|
415
|
+
callbackContext.error("Error getting network diagnostics: " + e.getMessage());
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private int getChannelFromFrequency(int frequency) {
|
|
421
|
+
if (frequency >= 2412 && frequency <= 2484) {
|
|
422
|
+
return (frequency - 2412) / 5 + 1;
|
|
423
|
+
} else if (frequency >= 5170 && frequency <= 5825) {
|
|
424
|
+
return (frequency - 5170) / 5 + 34;
|
|
425
|
+
}
|
|
426
|
+
return -1;
|
|
427
|
+
}
|
|
282
428
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -78,6 +78,37 @@ export interface IpInfo {
|
|
|
78
78
|
zipcode?: string;
|
|
79
79
|
state?: string;
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
export interface NetworkDiagnostics {
|
|
83
|
+
connectionStatus: {
|
|
84
|
+
isConnectedToInternet: boolean;
|
|
85
|
+
isConnectedToWifi: boolean;
|
|
86
|
+
connectionType: string;
|
|
87
|
+
isWifiEnabled: boolean;
|
|
88
|
+
};
|
|
89
|
+
wifiDetails: {
|
|
90
|
+
ssid: string;
|
|
91
|
+
bssid: string;
|
|
92
|
+
ipAddress: string;
|
|
93
|
+
macAddress: string;
|
|
94
|
+
linkSpeed: number;
|
|
95
|
+
linkSpeedUnit: string;
|
|
96
|
+
rssi: number;
|
|
97
|
+
frequency: number;
|
|
98
|
+
channel: number;
|
|
99
|
+
gateway: string;
|
|
100
|
+
dns1: string;
|
|
101
|
+
dns2: string;
|
|
102
|
+
networkId: number;
|
|
103
|
+
signalLevel: number;
|
|
104
|
+
signalQuality: string;
|
|
105
|
+
} | null;
|
|
106
|
+
performance: {
|
|
107
|
+
healthScore: number;
|
|
108
|
+
status: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
81
112
|
export default class WifiManager {
|
|
82
113
|
getWifiList(): Promise<WifiNetwork[]>;
|
|
83
114
|
getIpInfo(): Promise<IpInfo[]>;
|
|
@@ -94,5 +125,6 @@ export default class WifiManager {
|
|
|
94
125
|
getWifiStrength(): Promise<number>;
|
|
95
126
|
getSignalStrength(): Promise<number>;
|
|
96
127
|
ping(address: string, count: number, timeout: number, successCallback: (response: PingResponse) => void, errorCallback: (error: any) => void): void;
|
|
128
|
+
getNetworkDiagnostics(): Promise<NetworkDiagnostics>;
|
|
97
129
|
|
|
98
130
|
}
|
package/www/plugin.js
CHANGED
|
@@ -96,6 +96,16 @@ class WifiManager {
|
|
|
96
96
|
exec(resolve, reject, PLUGIN_NAME, 'getConnectedDevices', []);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get comprehensive network diagnostics
|
|
102
|
+
* @returns {Promise<Object>} Network diagnostic information including connection status, WiFi details, and performance metrics
|
|
103
|
+
*/
|
|
104
|
+
getNetworkDiagnostics() {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
exec(resolve, reject, PLUGIN_NAME, 'getNetworkDiagnostics', []);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
module.exports = new WifiManager();
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
package wifiplugin;
|
|
2
|
-
|
|
3
|
-
import org.apache.cordova.CallbackContext;
|
|
4
|
-
import org.apache.cordova.PluginResult;
|
|
5
|
-
import java.io.BufferedReader;
|
|
6
|
-
import java.io.InputStreamReader;
|
|
7
|
-
import org.json.JSONObject;
|
|
8
|
-
import org.apache.cordova.CordovaInterface;
|
|
9
|
-
|
|
10
|
-
public class PingTask {
|
|
11
|
-
|
|
12
|
-
public static void ping(String address, int count, int timeout, CallbackContext callbackContext, CordovaInterface cordova) {
|
|
13
|
-
cordova.getThreadPool().execute(() -> {
|
|
14
|
-
try {
|
|
15
|
-
String command = "/system/bin/ping -c " + count + " -W " + timeout + " " + address;
|
|
16
|
-
Process process = Runtime.getRuntime().exec(command);
|
|
17
|
-
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
18
|
-
|
|
19
|
-
int linesRead = 0;
|
|
20
|
-
String line;
|
|
21
|
-
String fullResponse = "";
|
|
22
|
-
while ((line = reader.readLine()) != null) {
|
|
23
|
-
int progress = (int) (((double) linesRead / count) * 100);
|
|
24
|
-
linesRead++;
|
|
25
|
-
JSONObject progressUpdate = new JSONObject();
|
|
26
|
-
// Ensure progress does not exceed 100
|
|
27
|
-
progress = Math.min(progress, 100); // Cap progress at 100
|
|
28
|
-
progressUpdate.put("line", line);
|
|
29
|
-
if (fullResponse != null && !fullResponse.isEmpty()) {
|
|
30
|
-
fullResponse = fullResponse + "\n" + line;
|
|
31
|
-
} else {
|
|
32
|
-
fullResponse = line;
|
|
33
|
-
}
|
|
34
|
-
progressUpdate.put("line", line);
|
|
35
|
-
progressUpdate.put("fullResponse", fullResponse);
|
|
36
|
-
progressUpdate.put("progress", progress);
|
|
37
|
-
PluginResult progressResult = new PluginResult(PluginResult.Status.OK, progressUpdate);
|
|
38
|
-
progressResult.setKeepCallback(true);
|
|
39
|
-
callbackContext.sendPluginResult(progressResult);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
process.waitFor();
|
|
43
|
-
JSONObject finalResult = new JSONObject();
|
|
44
|
-
finalResult.put("line", "");
|
|
45
|
-
finalResult.put("fullResponse", fullResponse);
|
|
46
|
-
finalResult.put("progress", 100);
|
|
47
|
-
finalResult.put("status", "completed");
|
|
48
|
-
finalResult.put("linesRead", linesRead);
|
|
49
|
-
PluginResult result = new PluginResult(PluginResult.Status.OK, finalResult);
|
|
50
|
-
callbackContext.sendPluginResult(result);
|
|
51
|
-
} catch (Exception e) {
|
|
52
|
-
callbackContext.error("Error during ping: " + e.getMessage());
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|