Skip to content

Commit

Permalink
always pass the pd-external-version to avoid version issues
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesneimog committed Nov 24, 2024
1 parent 6741734 commit 0f37c2d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
30 changes: 26 additions & 4 deletions Resources/Pd/pd4web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
static bool global_pd4web_check = false;
static t_class *pd4web_class;

#define PD4WEB_EXTERNAL_VERSION "2.2.1"

// ─────────────────────────────────────
class Pd4Web {
public:
Expand All @@ -44,6 +46,7 @@ class Pd4Web {
// compilation config
bool cancel;
std::string patch;
std::string version;
bool verbose;
bool gui;
bool debug;
Expand All @@ -57,6 +60,13 @@ class Pd4Web {
static bool pd4web_terminal(Pd4Web *x, std::string cmd, bool detached = false,
bool sucessMsg = false, bool showMessage = false,
bool clearNewline = false) {

post("[pd4web] Running command: %s", cmd.c_str());

if (x->running) {
pd_error(x, "[pd4web] Another command is running.");
return false;
}
x->running = true;

#if defined(_WIN32) || defined(_WIN64)
Expand Down Expand Up @@ -135,6 +145,10 @@ static bool pd4web_terminal(Pd4Web *x, std::string cmd, bool detached = false,
}
if (sucessMsg && exitCode == 0) {
post("[pd4web] Command executed successfully.");
} else if (exitCode != 0) {
x->running = false;
x->result = false;
pd_error(nullptr, "[pd4web] Command failed with exit code %d", exitCode);
}
CloseHandle(hRead);
CloseHandle(pi.hProcess);
Expand Down Expand Up @@ -191,6 +205,7 @@ static bool pd4web_terminal(Pd4Web *x, std::string cmd, bool detached = false,
if (exitCode != 0) {
x->running = false;
x->result = false;
pd_error(nullptr, "[pd4web] Command failed with exit code %d", exitCode);
} else {
x->running = false;
if (sucessMsg) {
Expand Down Expand Up @@ -445,13 +460,16 @@ static void pd4web_update(Pd4Web *x, t_symbol *s, int argc, t_atom *argv) {

// ─────────────────────────────────────
static void pd4web_compile(Pd4Web *x) {
x->running = true;
if (x->running) {
pd_error(x, "[pd4web] Compilation already running");
return;
}
if (!x->isReady) {
pd_error(x, "[pd4web] pd4web is not ready");
x->running = false;
return;
}
std::string cmd = x->pd4web + " --pd-external ";
std::string cmd = x->pd4web + " --pd-external";
cmd += " --pd-external-version \"" + x->version + "\" ";
if (x->verbose) {
cmd += " --verbose ";
}
Expand All @@ -478,9 +496,12 @@ static void pd4web_compile(Pd4Web *x) {
cmd += x->patch;
}

if (x->running) {
pd_error(x, "[pd4web] Compilation already running");
return;
}
pd_error(x, "[pd4web] Compiling patch on background, please wait...");
pd4web_terminal(x, cmd.c_str(), true, true, true, false);

return;
}

Expand Down Expand Up @@ -524,6 +545,7 @@ static void *pd4web_new(t_symbol *s, int argc, t_atom *argv) {
x->gui = true;
x->zoom = 2;
x->tpl = 0;
x->version = PD4WEB_EXTERNAL_VERSION;

x->server = new httplib::Server();
if (!x->server->is_valid()) {
Expand Down
10 changes: 10 additions & 0 deletions Sources/pd4web/Pd4Web.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,23 @@ def options_flags(self, parser):
type=str,
help="Pure Data version to use",
)

# Pd Object
parser.add_argument(
"--pd-external",
required=False,
default=False,
action="store_true",
help="If is it pd4web external",
)

parser.add_argument(
"--pd-external-version",
required=False,
default=importlib_metadata.version("pd4web"),
type=str,
help="Version of the pd4web external being used",
)

## User
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pd4web"
version = "2.2.0"
version = "2.2.1"
description = "pd4web compiles PureData patches with external objects for Wasm, allowing to run entire patches in web browsers."
authors = ["Charles K. Neimog <charlesneimog@outlook.com>"]
readme = "README.md"
Expand Down

0 comments on commit 0f37c2d

Please sign in to comment.