From 2e86e73afb7edea262a1ec3783e24e7cf762b629 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Wed, 15 Nov 2023 16:08:30 +0100 Subject: [PATCH] Auto-open started app, fix open app on close, auto-register, auto-start --- Project.toml | 2 +- .../applications/ApplicationsController.jl | 26 +++++++++++-------- routes.jl | 8 +++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index e80a8356..e0c6e8dd 100755 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GenieBuilder" uuid = "c9453c14-af8a-11ec-351d-c7c9a2035d70" authors = ["Adrian Salceanu"] -version = "0.16.12" +version = "0.16.13" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/app/resources/applications/ApplicationsController.jl b/app/resources/applications/ApplicationsController.jl index a221dbeb..74d7cc5d 100755 --- a/app/resources/applications/ApplicationsController.jl +++ b/app/resources/applications/ApplicationsController.jl @@ -234,15 +234,19 @@ function create(app::Application; name::AbstractString = "", path::AbstractStrin (:status => OKSTATUS) |> json end -function create(app::Nothing; name::AbstractString = "", path::AbstractString = pwd(), autostart::Bool = true, autoregister::Bool = true) - isdir(path) || mkpath(path) - - create_output = create(GenieBuilder.app!(name, path)) +function create(app::Nothing; name::AbstractString = "", path::AbstractString = pwd()) + try + isdir(path) || mkpath(path) + register(name, path; autostart = false) - register_output = "" - autoregister && (register_output = register(name, path; autostart)) + app = GenieBuilder.app!(name, path) + create(app) + start(app) - isempty(register_output) ? create_output : register_output + return (:status => OKSTATUS) |> json + catch ex + return (:status => FAILSTATUS, :error => ex) |> json + end end create(name::AbstractString = "", path::AbstractString = pwd()) = create(findone(Application; name = isempty(name) ? name_from_path(path) : name)) @@ -417,7 +421,10 @@ function start(app::Application) using GenieFramework.Genie; Core.eval(Main, :(const UserApp = $(@__MODULE__))); Genie.genie(context = @__MODULE__); - up(; async = false, open_browser = true); + up(; async = true, open_browser = true); + while true + sleep(1) + end '`; dir = fullpath(app), detach = false) cmd = addenv(cmd, "PORT" => app.port, "WSPORT" => app.port, @@ -433,9 +440,6 @@ function start(app::Application) app.error = "" save!(app) - - sleep(3) - GenieBuilder.openbrowser(app) catch ex @error ex notify("failed:start", app.id, FAILSTATUS, ERROR_STATUS) diff --git a/routes.jl b/routes.jl index 86e6aa5f..e7598901 100755 --- a/routes.jl +++ b/routes.jl @@ -39,10 +39,10 @@ status(app::Union{Application,Nothing}) = ApplicationsController.status(app) # starts the app function start(app::Application) - @async begin - sleep(15) - openbrowser(app) - end + # @async begin + # sleep(15) + # openbrowser(app) + # end ApplicationsController.start(app) end