Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1f1237fa4 | ||
|
|
c1e58c2360 |
No files matched your search
@@ -43,7 +43,7 @@ jobs:
|
||||
- name: Build Site
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make docs-site
|
||||
make docs-site CMAKE=/usr/bin/cmake
|
||||
test -f build/site/examples/02_buttons/index.html
|
||||
test -f build/site/examples/02_buttons/index.js
|
||||
test -f build/site/examples/02_buttons/index.wasm
|
||||
|
||||
@@ -91,14 +91,14 @@ jobs:
|
||||
- name: Build And Test
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make clean
|
||||
make all
|
||||
make test
|
||||
make clean CMAKE=/usr/bin/cmake
|
||||
make all CMAKE=/usr/bin/cmake
|
||||
make test CMAKE=/usr/bin/cmake
|
||||
|
||||
- name: Package Static Library
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make dist-static VERSION="${{ steps.ref.outputs.tag }}"
|
||||
make dist-static CMAKE=/usr/bin/cmake VERSION="${{ steps.ref.outputs.tag }}"
|
||||
archive="$(find dist -maxdepth 1 -type f -name flint-*-static.tar.gz | head -n 1)"
|
||||
test -n "$archive"
|
||||
echo "FLINT_STATIC_ARCHIVE=$archive" >> "$GITHUB_ENV"
|
||||
|
||||
@@ -169,11 +169,11 @@ src/ui/ui_icon_names.c: $(ICON_FILES) scripts/embed-icons.sh include/ui_icon_typ
|
||||
$(EMBED_ASSETS_C): $(EMBED_ASSET_FILES) $(FLINT_FONT_OUTPUTS) scripts/embed-assets.sh include/embedded_assets.h | $(BUILD_DIR)
|
||||
sh scripts/embed-assets.sh $@ $(EMBED_ASSETS) $(FLINT_FONT_OUTPUTS)
|
||||
|
||||
$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR)
|
||||
$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) $(FLINT_LIBOQS_A) $(FLINT_CURL_PROTOCOL_CHECK)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c | $(BUILD_DIR)
|
||||
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c | $(BUILD_DIR) $(FLINT_LIBOQS_A) $(FLINT_CURL_PROTOCOL_CHECK)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ int SetFileDialogCurrentDir(FileDialog *dlg, const char *path);
|
||||
/* Set an explicit theme scope; pass NULL or empty to follow the current UI theme. */
|
||||
void SetFileDialogThemeScope(const char *scope);
|
||||
|
||||
/* Return the resolved desktop helper name: zenity, kdialog, yad, or none. */
|
||||
/* Return the resolved backend name: web, zenity, kdialog, yad, or none. */
|
||||
const char *GetFileDialogBackendName(void);
|
||||
|
||||
/* FLINT_FILE_DIALOG_BACKEND can force auto, zenity, kdialog, yad, or none. */
|
||||
@@ -50,7 +50,8 @@ int LoadFilteredFileDialog(FileDialog *dlg, const char *title, const char *filte
|
||||
/* Select folder dialog - returns 1 if folder selected, 0 if cancelled */
|
||||
int SelectFileDialogFolder(FileDialog *dlg, const char *title);
|
||||
|
||||
/* Compatibility wrappers. Desktop GTK dialogs complete before Begin* returns. */
|
||||
/* Compatibility wrappers. Desktop helpers complete before Begin* returns;
|
||||
web dialogs complete through UpdateFileDialog(). */
|
||||
void BeginLoadFileDialog(FileDialog *dlg, const char *title);
|
||||
void BeginLoadFilteredFileDialog(FileDialog *dlg, const char *title, const char *filter);
|
||||
void BeginSaveFileDialog(FileDialog *dlg, const char *title, const char *default_filename);
|
||||
|
||||
@@ -6,22 +6,112 @@
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
static int web_file_dialog_next_id = 1;
|
||||
|
||||
static void
|
||||
web_clear_dialog_result(FileDialog *dlg)
|
||||
{
|
||||
if(dlg == NULL)
|
||||
return;
|
||||
EM_ASM({
|
||||
if(Module.__flintFileDialogResults)
|
||||
delete Module.__flintFileDialogResults[String($0)];
|
||||
}, dlg);
|
||||
}
|
||||
|
||||
static void
|
||||
reset_dialog_result(FileDialog *dlg, FileDialogMode mode, const char *title,
|
||||
const char *filter, const char *default_filename)
|
||||
{
|
||||
if(dlg == NULL)
|
||||
return;
|
||||
web_clear_dialog_result(dlg);
|
||||
dlg->active = 0;
|
||||
dlg->mode = mode;
|
||||
dlg->confirmed = 0;
|
||||
dlg->result_path[0] = '\0';
|
||||
dlg->result_path[0] = 0;
|
||||
snprintf(dlg->title, sizeof(dlg->title), "%s", title != NULL ? title : "");
|
||||
snprintf(dlg->filter, sizeof(dlg->filter), "%s", filter != NULL ? filter : "");
|
||||
snprintf(dlg->default_name, sizeof(dlg->default_name), "%s",
|
||||
default_filename != NULL ? default_filename : "");
|
||||
}
|
||||
|
||||
static void
|
||||
begin_web_load_dialog(FileDialog *dlg, const char *title, const char *filter)
|
||||
{
|
||||
if(dlg == NULL)
|
||||
return;
|
||||
reset_dialog_result(dlg, FILE_DIALOG_LOAD, title, filter, NULL);
|
||||
dlg->active = 1;
|
||||
snprintf(dlg->result_path, sizeof(dlg->result_path), "/tmp/flint-file-dialog-%d",
|
||||
web_file_dialog_next_id++);
|
||||
if(web_file_dialog_next_id <= 0)
|
||||
web_file_dialog_next_id = 1;
|
||||
|
||||
EM_ASM({
|
||||
const key = String($0);
|
||||
const resultPath = UTF8ToString($1);
|
||||
const rawAccept = $2 ? UTF8ToString($2) : "";
|
||||
const results = Module.__flintFileDialogResults = Module.__flintFileDialogResults || {};
|
||||
results[key] = {status: 0};
|
||||
|
||||
const normalizeAccept = (value) => String(value || "")
|
||||
.split(",")
|
||||
.map((entry) => entry.trim())
|
||||
.filter(Boolean)
|
||||
.map((entry) => entry.startsWith("*.") ? entry.substring(1) : entry)
|
||||
.join(",");
|
||||
|
||||
const input = document.createElement("input");
|
||||
let settled = false;
|
||||
const finish = (status) => {
|
||||
if(settled)
|
||||
return;
|
||||
settled = true;
|
||||
results[key] = {status};
|
||||
input.remove();
|
||||
};
|
||||
|
||||
input.type = "file";
|
||||
input.accept = normalizeAccept(rawAccept);
|
||||
input.style.display = "none";
|
||||
input.onchange = async function() {
|
||||
try {
|
||||
if(!input.files || input.files.length === 0) {
|
||||
finish(2);
|
||||
return;
|
||||
}
|
||||
const bytes = new Uint8Array(await input.files[0].arrayBuffer());
|
||||
try { FS.mkdirTree("/tmp"); } catch(e) {}
|
||||
try { FS.unlink(resultPath); } catch(e) {}
|
||||
FS.writeFile(resultPath, bytes);
|
||||
finish(1);
|
||||
} catch(e) {
|
||||
console.error("Flint web file dialog failed:", e);
|
||||
finish(3);
|
||||
}
|
||||
};
|
||||
input.addEventListener("cancel", () => finish(2));
|
||||
|
||||
document.body.appendChild(input);
|
||||
const finishCancelledAfterFocus = () => {
|
||||
setTimeout(() => {
|
||||
if(!settled && (!input.files || input.files.length === 0))
|
||||
finish(2);
|
||||
}, 500);
|
||||
};
|
||||
window.addEventListener("focus", finishCancelledAfterFocus, {once: true});
|
||||
try {
|
||||
input.click();
|
||||
} catch(e) {
|
||||
console.error("Flint web file dialog could not open:", e);
|
||||
finish(3);
|
||||
}
|
||||
}, dlg, dlg->result_path, dlg->filter);
|
||||
}
|
||||
|
||||
void
|
||||
InitFileDialog(FileDialog *dlg)
|
||||
{
|
||||
@@ -46,13 +136,13 @@ SetFileDialogThemeScope(const char *scope)
|
||||
const char *
|
||||
GetFileDialogBackendName(void)
|
||||
{
|
||||
return "none";
|
||||
return "web";
|
||||
}
|
||||
|
||||
void
|
||||
BeginLoadFilteredFileDialog(FileDialog *dlg, const char *title, const char *filter)
|
||||
{
|
||||
reset_dialog_result(dlg, FILE_DIALOG_LOAD, title, filter, NULL);
|
||||
begin_web_load_dialog(dlg, title, filter);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -64,7 +154,7 @@ BeginLoadFileDialog(FileDialog *dlg, const char *title)
|
||||
int
|
||||
LoadFilteredFileDialog(FileDialog *dlg, const char *title, const char *filter)
|
||||
{
|
||||
reset_dialog_result(dlg, FILE_DIALOG_LOAD, title, filter, NULL);
|
||||
BeginLoadFilteredFileDialog(dlg, title, filter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,15 +193,38 @@ SelectFileDialogFolder(FileDialog *dlg, const char *title)
|
||||
int
|
||||
UpdateFileDialog(FileDialog *dlg)
|
||||
{
|
||||
int status;
|
||||
|
||||
if(dlg == NULL)
|
||||
return 0;
|
||||
return dlg->confirmed ? 1 : 0;
|
||||
if(!dlg->active)
|
||||
return dlg->confirmed ? 1 : 0;
|
||||
|
||||
status = EM_ASM_INT({
|
||||
const results = Module.__flintFileDialogResults || {};
|
||||
const result = results[String($0)];
|
||||
return result ? (result.status | 0) : 0;
|
||||
}, dlg);
|
||||
if(status == 0)
|
||||
return -1;
|
||||
|
||||
dlg->active = 0;
|
||||
if(status == 1) {
|
||||
dlg->confirmed = 1;
|
||||
web_clear_dialog_result(dlg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dlg->confirmed = 0;
|
||||
dlg->result_path[0] = 0;
|
||||
web_clear_dialog_result(dlg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
GetFileDialogPath(FileDialog *dlg)
|
||||
{
|
||||
if(dlg == NULL || dlg->result_path[0] == '\0')
|
||||
if(dlg == NULL || dlg->result_path[0] == 0)
|
||||
return NULL;
|
||||
return dlg->result_path;
|
||||
}
|
||||
@@ -119,8 +232,10 @@ GetFileDialogPath(FileDialog *dlg)
|
||||
void
|
||||
CloseFileDialog(FileDialog *dlg)
|
||||
{
|
||||
if(dlg != NULL)
|
||||
if(dlg != NULL) {
|
||||
web_clear_dialog_result(dlg);
|
||||
memset(dlg, 0, sizeof(FileDialog));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user