Skip to content

Commit 5a4c22f

Browse files
committed
Merge branch 'main' into v1.5.02
2 parents 83141d5 + 5d818d4 commit 5a4c22f

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

client/packages/android/app/src/main/java/org/openmsupply/client/CertWebViewClient.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,14 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
199199
// will not only reload, but will open the URL in a browser tab
200200
// for local URLs we don't want this to happen!
201201
Uri url = request.getUrl();
202-
if (url.toString().startsWith(nativeApi.getServerUrl())) {
203-
return false;
202+
try {
203+
if (url.toString().startsWith(nativeApi.getServerUrl())) {
204+
return false;
205+
}
206+
}
207+
catch(Exception e){
208+
Log.e(TAG,e.getMessage());
204209
}
205-
206210
return bridge.launchIntent(url);
207211
}
208212
}

client/packages/android/app/src/main/java/org/openmsupply/client/NativeApi.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -349,30 +349,39 @@ public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
349349

350350
// Attempt to get a non-loopback address for the local server
351351
// and fallback to loopback if there is an error
352-
private String getLocalAddress(NsdServiceInfo serviceInfo){
352+
private String getHostAddress(NsdServiceInfo serviceInfo, Boolean isLocal){
353353
try {
354-
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
355-
NetworkInterface intf = en.nextElement();
356-
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
357-
InetAddress inetAddress = enumIpAddr.nextElement();
358-
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {
359-
return inetAddress.getHostAddress();
354+
if (isLocal) {
355+
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
356+
NetworkInterface intf = en.nextElement();
357+
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
358+
InetAddress inetAddress = enumIpAddr.nextElement();
359+
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {
360+
return inetAddress.getHostAddress();
361+
}
360362
}
361363
}
362364
}
363-
} catch (SocketException ex) {
365+
return serviceInfo.getHost().getHostAddress();
366+
} catch (Exception ex) {
364367
Log.e(OM_SUPPLY, ex.toString());
365368
}
366-
return serviceInfo.getHost().getHostAddress();
369+
finally {
370+
// with no network available the getHostAddress() will
371+
// throw an Exception - in this case default to local loopback
372+
// as no other network is reachable!
373+
return "127.0.0.1";
374+
}
367375
}
376+
368377
private JSObject serviceInfoToObject(NsdServiceInfo serviceInfo) {
369378
String serverHardwareId = parseAttribute(serviceInfo, discoveryConstants.HARDWARE_ID_KEY);
370379
Boolean isLocal = serverHardwareId.equals(discoveryConstants.hardwareId);
371380
return new JSObject()
372381
.put("protocol", parseAttribute(serviceInfo, discoveryConstants.PROTOCOL_KEY))
373382
.put("clientVersion", parseAttribute(serviceInfo, discoveryConstants.CLIENT_VERSION_KEY))
374383
.put("port", serviceInfo.getPort())
375-
.put("ip", isLocal ? getLocalAddress(serviceInfo) : serviceInfo.getHost().getHostAddress())
384+
.put("ip", getHostAddress(serviceInfo, isLocal))
376385
.put("hardwareId", serverHardwareId)
377386
.put("isLocal", isLocal);
378387

@@ -499,7 +508,7 @@ public FrontEndHost(JSObject data) {
499508
// so that we can display the local server IP for users to connect to the API
500509
if (data.getBool("isLocal") && (ip.equals("127.0.0.1") || ip.equals("localhost"))) {
501510
NsdServiceInfo serviceInfo = createLocalServiceInfo();
502-
data.put("ip", getLocalAddress(serviceInfo));
511+
data.put("ip", getHostAddress(serviceInfo, true));
503512
}
504513
this.data = data;
505514
}

client/packages/common/src/intl/locales/en/common.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"button.create-a-new-one": "Create a new one",
1515
"button.delete-lines": "Delete selected lines",
1616
"button.export": "Export",
17-
"button.import-fridge-tag": "Import fridge tag",
17+
"button.import-fridge-tag": "Import Fridge-tag",
1818
"button.initialise": "Initialise",
1919
"button.language": "Language",
2020
"button.more": "More",

0 commit comments

Comments
 (0)