Coder Social home page Coder Social logo

Comments (5)

johns10 avatar johns10 commented on May 27, 2024

I figured this out. Basically I just copied Bakeware.Script and then added my genserver to the child list:

defmodule ElixtronAgent.Application do
  use Application

  def start(_type, _args) do
    children = [
      %{id: Task, restart: :temporary, start: {Task, :start_link, [&__MODULE__.main/0]}},
      ElixtronAgent.Server
    ]

    opts = [strategy: :one_for_all, name: __MODULE__.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def parse_args(args) do
    {opts, word, _} =
      args
      |> OptionParser.parse(switches: [upcase: :open_browser])

    opts
  end

  def do_stuff(opts) do
    IO.inspect(opts)
    maybe_open_browser(opts[:open_browser])

    :ok
  end

  defp maybe_open_browser(nil), do: nil
  defp maybe_open_browser(_) do
    IO.puts("maybe_open_browser")
    ElixtronAgent.Server.open_browser()
  end

  def main() do
    get_argc!()
    |> get_args()
    |> parse_args()
    |> do_stuff()
    |> result_to_halt()
    |> :erlang.halt()
  catch
    error, reason ->
      IO.warn(
        "Caught exception in #{__MODULE__}.main/1: #{inspect(error)} => #{
          inspect(reason, pretty: true)
        }",
        __STACKTRACE__
      )

      :erlang.halt(1)
  end

  def get_argc!() do
    ...same
  end

  def get_args(argc) do
    ...same
  end

  def result_to_halt(result) do
    ...same
    
  end

end

from bakeware.

johns10 avatar johns10 commented on May 27, 2024

So, I've attached my own genserver to the application, and I'm running into a couple problems:

  1. Only handle_call seems to work. Not sure why, and haven't independently tested outside of the bakeware app, so might be spurrious.
  2. The genserver seems to restart on every call (I have a log message every time it starts, it throws every time I call the application).

Any ideas on these two issues?

from bakeware.

johns10 avatar johns10 commented on May 27, 2024

I think I may be calling the agent incorrectly. I've made this work with the dev version, because I can start it, and then send it rpc calls. I'm pretty sure that what I'm doing wrong is starting the agent every time. I don't actually know how to run it in production and then make RPC calls to it.

from bakeware.

johns10 avatar johns10 commented on May 27, 2024

@fhunleth @jjcarstens,

I got this working for an elixir talk I'll be giving tomorrow for ElixirToronto (https://www.meetup.com/TorontoElixir/events/278237262/). Feel free to join if you like.

Basically the goal is to use Elixtron as a background desktop application that accepts commands over a custom protocol (elixtron://Elixtron.open_browser()) that can be called directly from the browser. Those links can be authored by the live view, rendered on the page, and then calls are made directly to the assembled bakeware binary.

I put up a repo for my implementation here: https://github.com/johns10/elixtron, and here: https://github.com/johns10/elixtron_desktop

I got it pretty far in dev mode. I'd be interested in your feedback about how to tighten this up and deploy in production. I have some theories on the readme.

This is a fantastic library. I'm really happy with this implementation, and I'm hoping to ultimately replace my electron implementation of browser automation with it, and even to ship a self-contained desktop version of my liveview app that requires no internet connection.

Hoping to use it more in the future!

Regards,
John Davenport

from bakeware.

fhunleth avatar fhunleth commented on May 27, 2024

@johns10 That's awesome! Thanks for letting us know. I signed up for the meetup. I'm not sure if I'll be able to make it yet, but I'll try!

from bakeware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.