Skip to content

Commit 151bfeb

Browse files
authored
Merge pull request #2876 from msupply-foundation/2867-android-offline
Android issues when running offline
2 parents 8445b07 + d0afd57 commit 151bfeb

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

client/packages/android/app/src/main/assets/capacitor.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"appId": "org.openmsupply.client",
3-
"appName": "openmsupply-client",
3+
"appName": "Open mSupply",
44
"webDir": "../host/dist/",
55
"bundledWebRuntime": false,
66
"android": {

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,12 @@ private String getHostAddress(NsdServiceInfo serviceInfo, Boolean isLocal){
366366
} catch (Exception ex) {
367367
Log.e(OM_SUPPLY, ex.toString());
368368
}
369-
return serviceInfo.getHost().getHostAddress();
369+
InetAddress host = serviceInfo.getHost();
370+
// this will happen if there is no network interface available
371+
if (host == null) {
372+
return "127.0.0.1";
373+
}
374+
return host.getHostAddress();
370375
}
371376

372377
private JSObject serviceInfoToObject(NsdServiceInfo serviceInfo) {
@@ -513,7 +518,8 @@ public FrontEndHost(JSObject data) {
513518
* e.g. https://127.0.0.1:8000
514519
*/
515520
public String getUrl() {
516-
return data.getString("protocol") + "://" + data.getString("ip") + ":" + data.getString("port");
521+
String host = data.getBool("isLocal") ? "localhost" : data.getString("ip");
522+
return data.getString("protocol") + "://" + host + ":" + data.getString("port");
517523
}
518524

519525
/**
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
3-
<string name="app_name">openmsupply-client</string>
4-
<string name="title_activity_main">openmsupply-client</string>
3+
<string name="app_name">Open mSupply</string>
4+
<string name="title_activity_main">Open mSupply</string>
55
<string name="package_name">org.openmsupply.client</string>
66
<string name="custom_url_scheme">org.openmsupply.client</string>
77
</resources>

client/packages/android/capacitor.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CapacitorConfig } from '@capacitor/cli';
55

66
const config: CapacitorConfig = {
77
appId: 'org.openmsupply.client',
8-
appName: 'openmsupply-client',
8+
appName: 'Open mSupply',
99
// This is only needed for `npx cap copy` to work, and it does have to point to actual bundle
1010
// bundle is server by remote server (local or discovered) or through webpack if debugging (see comment below)
1111
webDir: '../host/dist/',

client/packages/host/src/components/Android.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const Android = () => {
126126
// this page is not for web users! begone!
127127
if (!getNativeAPI()) navigate(RouteBuilder.create(AppRoute.Login).build());
128128
getPreference('mode', '"none"').then(setLocalMode);
129-
}, []);
129+
}, [navigate]);
130130

131131
useEffect(() => {
132132
if (mode === NativeMode.Server) {
@@ -145,7 +145,7 @@ export const Android = () => {
145145
.build()
146146
);
147147
}
148-
}, [mode, previousServer, connectToPreviousFailed]);
148+
}, [mode, previousServer, connectToPreviousFailed, navigate]);
149149

150150
if (mode === NativeMode.None)
151151
return (

client/packages/host/src/components/Login/LoginLayout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const LoginLayout = ({
4040
flex="1 0 50%"
4141
sx={{
4242
backgroundImage: (theme: Theme) => theme.mixins.gradient.primary,
43-
padding: '0 80px 7% 80px',
43+
padding: '0 5% 7%',
4444
}}
4545
display="flex"
4646
alignItems="flex-start"
@@ -52,8 +52,8 @@ export const LoginLayout = ({
5252
sx={{
5353
color: (theme: Theme) => theme.typography.login.color,
5454
fontSize: {
55-
xs: '38px',
56-
sm: '38px',
55+
xs: '28px',
56+
sm: '30px',
5757
md: '48px',
5858
lg: '64px',
5959
xl: '64px',

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "open-msupply",
33
"//": "Main version for the app, should be in semantic version format (any release candidate or test build should be separated by '-' i.e. 1.1.1-rc1 or 1.1.1-test",
4-
"version": "1.6.00",
4+
"version": "1.6.01",
55
"private": true,
66
"scripts": {
77
"start": "cd ./server && cargo run & cd ./client && yarn start-local",
88
"build": "cd ./client && yarn build && cd ../server && cargo build --release",
99
"test": "cd ./server && ulimit -n 1000 && cargo test && cd ../client && yarn test"
1010
}
11-
}
11+
}

0 commit comments

Comments
 (0)