Skip to content

Commit 4585d31

Browse files
committed
ANDROID: fix web page regression
1 parent 7387ff5 commit 4585d31

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/platform/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 19
1111
targetSdkVersion 34
12-
versionCode 60
12+
versionCode 61
1313
versionName '12.27'
1414
resourceConfigurations += ['en']
1515
}

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,8 @@ protected Response getFile(String remoteHost, String path, boolean asset) throws
10951095
String name = "webui/" + path;
10961096
long length = getFileLength(name);
10971097
log("Opened " + name + " " + length + " bytes");
1098-
result = new Response(getAssets().open(name), length);
1098+
String contentType = path.endsWith("js") ? "text/javascript" : "text/html";
1099+
result = new Response(getAssets().open(name), length, contentType);
10991100
if ("index.html".equals(path) && isHostNotPermitted(remoteHost)) {
11001101
requestHostPermission(remoteHost);
11011102
}

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/WebServer.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public abstract class WebServer {
4444
private static final int SC_NOT_AUTHORISED = 401;
4545
private static final int SC_NOT_FOUND = 404;
4646
private static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
47+
private static final String TEXT_HTML = "text/html";
4748

4849
public WebServer() {
4950
super();
@@ -641,24 +642,35 @@ public class Response {
641642
private final InputStream inputStream;
642643
private final long length;
643644
private final int errorCode;
645+
private final String contentType;
646+
647+
public Response(InputStream inputStream, long length, String contentType) {
648+
this.inputStream = inputStream;
649+
this.length = length;
650+
this.errorCode = SC_OKAY;
651+
this.contentType = contentType;
652+
}
644653

645654
public Response(InputStream inputStream, long length) {
646655
this.inputStream = inputStream;
647656
this.length = length;
648657
this.errorCode = SC_OKAY;
658+
this.contentType = TEXT_HTML;
649659
}
650660

651661
public Response(byte[] bytes) {
652662
this.inputStream = new ByteArrayInputStream(bytes);
653663
this.length = bytes.length;
654664
this.errorCode = SC_OKAY;
665+
this.contentType = TEXT_HTML;
655666
}
656667

657668
public Response(int errorCode) throws IOException {
658669
byte[] bytes = ("Error: " + errorCode).getBytes(UTF_8);
659670
this.inputStream = new ByteArrayInputStream(bytes);
660671
this.length = bytes.length;
661672
this.errorCode = errorCode;
673+
this.contentType = TEXT_HTML;
662674
}
663675

664676
/**
@@ -670,7 +682,7 @@ void send(Socket socket, String cookie) throws IOException {
670682
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
671683
String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String.valueOf(errorCode);
672684
out.write(("HTTP/1.0 " + code + "\r\n").getBytes(UTF_8));
673-
out.write("Content-type: text/html\r\n".getBytes(UTF_8));
685+
out.write(("Content-type: " + contentType + "\r\n").getBytes(UTF_8));
674686
out.write(contentLength.getBytes(UTF_8));
675687
if (cookie != null) {
676688
out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes(UTF_8));

src/platform/android/webui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"scripts": {
2525
"start": "vite --host",
26-
"build": "GENERATE_SOURCEMAP=false vite build && rm ../app/src/main/assets/webui/static/js/main.* && cp -R build/* ../app/src/main/assets/webui/",
26+
"build": "GENERATE_SOURCEMAP=false vite build && rm -rf ../app/src/main/assets/webui/* && cp -R dist/* ../app/src/main/assets/webui/",
2727
"update": "npm update && ncu -u && npm install && npm audit fix"
2828
},
2929
"eslintConfig": {

0 commit comments

Comments
 (0)