Skip to content

Commit 3f3b7dc

Browse files
author
Chris Warren-Smith
committed
ANDROID: replace MUI based portal with native js implementation
1 parent e872bb6 commit 3f3b7dc

7 files changed

Lines changed: 52 additions & 19 deletions

File tree

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2025-10-14 (12.32)
2+
ANDROID: replace react/mui based portal with native javascript solution
3+
14
2025-09-11 (12.31)
25
ANDROID: Implemented support for editing with the system keypad
36

src/platform/android/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ library:
5858

5959
# launch WebServerTest in intellij
6060
start-ui:
61-
(cd app/src/main/assets/webui && valgrind ../../../../../../web/sbasicw -p 3000 -a 'api' -o 'http://localhost:8080')
61+
(cd app/src/main/assets/webui && valgrind --leak-check=full ../../../../../../web/sbasicw -p 3000 -a 'api' -o 'http://localhost:8080')

src/platform/android/app/src/main/assets/webui/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@
1414
<h1>SmallBASIC</h1>
1515
<a href="https://smallbasic.github.io" target="_blank">smallbasic.github.io</a>
1616
</div>
17+
<div class="toolbar hidden" id="toolbar">
18+
<button class="btn btn-small btn-icon" id="upload-btn">
19+
📤 UPLOAD
20+
</button>
21+
<button class="btn btn-small btn-icon" id="download-btn" disabled>
22+
📥 DOWNLOAD
23+
</button>
24+
<button class="btn btn-small btn-icon" id="delete-btn" disabled>
25+
🗑️ DELETE
26+
</button>
27+
<div id="selection-info" style="margin-left: auto; color: #666;"></div>
28+
</div>
1729
<div class="main-content" id="main-content"></div>
1830
<input type="file" id="file-upload" multiple class="hidden">
31+
<a class="hidden" id="file-download"></a>
1932
</body>
2033
</html>

src/platform/android/app/src/main/assets/webui/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ body {
3636
}
3737

3838
.main-content {
39-
height: calc(100vh - 88px);
39+
height: calc(100vh - 8em);
4040
width: 100%;
4141
overflow: auto;
4242
}

src/platform/android/app/src/main/assets/webui/main.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@
5050

5151
function renderFileList(container) {
5252
container.innerHTML = `
53-
<div class="toolbar">
54-
<button class="btn btn-small btn-icon" id="upload-btn">
55-
📤 UPLOAD
56-
</button>
57-
<button class="btn btn-small btn-icon" id="download-btn" disabled>
58-
📥 DOWNLOAD
59-
</button>
60-
<button class="btn btn-small btn-icon" id="delete-btn" disabled>
61-
🗑️ DELETE
62-
</button>
63-
<div id="selection-info" style="margin-left: auto; color: #666;"></div>
64-
</div>
6553
<div class="table-container">
6654
<table>
6755
<thead>
@@ -87,6 +75,9 @@
8775
</div>
8876
`;
8977

78+
const toolbar = document.getElementById('toolbar');
79+
toolbar.classList.remove('hidden');
80+
9081
renderTableRows();
9182
updateToolbarState();
9283
setupFileListEventListeners();
@@ -396,7 +387,7 @@
396387
params = fileParams.join('&');
397388
}
398389

399-
const link = document.createElement('a');
390+
const link = document.getElementById('file-download');
400391
link.href = `./api/download?${params}`;
401392
link.download = filename;
402393
link.click();

src/platform/web/main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
#include <cstdlib>
1414
#include <cstring>
1515
#include <cstdio>
16+
#include <string>
1617

1718
#include "include/osd.h"
1819
#include "common/sbapp.h"
1920
#include "common/device.h"
2021
#include "platform/web/canvas.h"
2122
#include "platform/web/proxy.h"
2223

24+
using namespace std;
25+
2326
static Canvas g_canvas;
2427
static uint32_t g_start = 0;
2528
static uint32_t g_maxTime = 2000;
@@ -29,8 +32,8 @@ static bool g_json = false;
2932
static char *execBas = nullptr;
3033
static MHD_Connection *g_connection;
3134
static StringList g_cookies;
32-
static String g_path;
33-
static String g_data;
35+
static string g_path;
36+
static string g_data;
3437

3538
static struct option OPTIONS[] = {
3639
{"file-permitted", no_argument, nullptr, 'f'},

src/platform/web/proxy.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#include <config.h>
1010

11+
#include <microhttpd.h>
12+
#include <curl/curl.h>
1113
#include <cstring>
1214
#include <string>
1315
#include <vector>
1416
#include <sstream>
15-
#include <microhttpd.h>
16-
#include <curl/curl.h>
1717

1818
constexpr int BUFFER_SIZE = 128;
1919
static const char *g_path = nullptr;
@@ -43,6 +43,20 @@ static MHD_Result get_cookies(void *cls, enum MHD_ValueKind kind, const char *ke
4343
return MHD_YES;
4444
}
4545

46+
// reads the microhttpd request URL args
47+
static MHD_Result get_url_arg(void *cls, enum MHD_ValueKind kind, const char *key, const char *value) {
48+
auto *args = static_cast<string*>(cls);
49+
if (key && value) {
50+
if (!(*args).empty()) {
51+
*args += "&";
52+
}
53+
*args += key;
54+
*args += "=";
55+
*args += value;
56+
}
57+
return MHD_YES;
58+
}
59+
4660
// copy the curl proxy cookies back to the microhttpd response
4761
static void set_cookies(MHD_Response *response, curl_slist *cookies) {
4862
// assumes cookies use the netscape 7 field tab separated format
@@ -108,6 +122,12 @@ MHD_Response *proxy_request(MHD_Connection *connection, const char *path, const
108122
string url;
109123
url.append(g_host).append("/").append(path);
110124

125+
string url_args;
126+
MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, get_url_arg, &url_args);
127+
if (!url_args.empty()) {
128+
url.append("?").append(url_args);
129+
}
130+
111131
string response;
112132
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
113133
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
@@ -131,6 +151,9 @@ MHD_Response *proxy_request(MHD_Connection *connection, const char *path, const
131151
set_cookies(result, receiveCookies);
132152
}
133153

154+
if (receiveCookies) {
155+
curl_slist_free_all(receiveCookies);
156+
}
134157
return result;
135158
}
136159

0 commit comments

Comments
 (0)