andrewbaxter / wongus

Desktop widgets at the speed of internet standards
ISC License
3 stars 0 forks source link

wongus.run_command not working #2

Open darman96 opened 1 month ago

darman96 commented 1 month ago

I already got another problem :D When I call wongus.run_command nothing seems to happen. I don't get any errors either.

index.html

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script type="application/javascript" src="script.js"></script>
        <link rel="stylesheet" href="style.css" />
    </head>

    <body>
        <div><button id="btn">Hello, wongus!</button></div>
    </body>
</html>

script.js

document.addEventListener("DOMContentLoaded", async () => {
  const button = document.getElementById("btn");
  button.addEventListener("click", () =>
    wongus.run_command({ command: ["alacritty"] }),
  );
});

I also tried window.wongus.run_command

andrewbaxter commented 1 month ago

Oh! I'm glad you're taking me up on that :D

I only have two ideas here off the top of my head:

To elaborate on the second point, I was originally thinking if you wanted to spawn a detached program you'd use something like systemd-run to do it, but I think that's probably excessive (and it messes with environment variables). I'll try to add a spawn_detached method or something that which handles this use case better tomorrow.

andrewbaxter commented 1 month ago

I can't remember if you found it already, but right clicking on the panel you should be able to open the developer tools and view the console that way.

darman96 commented 1 month ago

hmm, it just worked now.. although I'm pretty sure I ran the exact same code when it didn't.

The spawn_detached sounds like a good idea though.

andrewbaxter commented 1 month ago

Yeah okay, I'll get on that asap - let's leave this issue open for that maybe? Let me know if it happens again though or if you come across any other issues too.

darman96 commented 1 month ago

Btw. what do you think about adding a url option to the config so you could run a node app locally? Could you still inject the wongus api into something like this?

andrewbaxter commented 1 month ago

I moved that to a new issue https://github.com/andrewbaxter/wongus/issues/3 - I'm not sure if you wanted it or were just curious but just in case.

andrewbaxter commented 1 month ago

Okay, I added wongus.run_independent which takes roughly the same arguments as run_command here: https://github.com/andrewbaxter/wongus/commit/1345633f5855a3814f3fcc0f869191f06f96a9f5

I haven't tried it but it was a small change so I'm hopeful there's no issues. Just FYI though, if you run a command that way and it exits with an error (after starting, I think) you won't get any notification. You can always try with run_command, then once that's working switch to run_independent to avoid it getting killed after a timeout.

andrewbaxter commented 1 month ago

I'm not sure if run_detached would be a better name than run_independent...