From 2ead5b746fe8c709d8187b3a6a8d7e4bff9653a1 Mon Sep 17 00:00:00 2001 From: Alex Riss <00alexx@riss.at> Date: Wed, 6 Dec 2023 11:50:44 +0100 Subject: [PATCH] add option to close server and end electron process --- src/AtomShell/process.jl | 2 +- src/AtomShell/window.jl | 10 ++++++++-- src/content/server.jl | 11 ++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/AtomShell/process.jl b/src/AtomShell/process.jl index f028287..83839ec 100644 --- a/src/AtomShell/process.jl +++ b/src/AtomShell/process.jl @@ -105,7 +105,7 @@ handlers(shell::Electron) = shell.handlers function initcbs(shell) enable_callbacks!(shell) @async begin - while active(shell) + while active(shell) && !eof(shell.sock) # check for eof to prevent errors during shutdown @errs handle_message(shell, JSON.parse(shell.sock)) end end diff --git a/src/AtomShell/window.jl b/src/AtomShell/window.jl index 113a6a7..961a1c3 100644 --- a/src/AtomShell/window.jl +++ b/src/AtomShell/window.jl @@ -1,5 +1,5 @@ using ..Blink -import Blink: js, id +import Blink: js, id, stopserve import JSExpr: JSString, jsstring import Base: position, size, close @@ -254,8 +254,14 @@ tools(win::Window) = front(win::Window) = @dot win showInactive() -close(win::Window) = +function close(win::Window; quit=false) @dot win close() + if quit + close(win.shell) + stopserve() + end + +end # Window content APIs diff --git a/src/content/server.jl b/src/content/server.jl index e260b98..06cc354 100644 --- a/src/content/server.jl +++ b/src/content/server.jl @@ -62,11 +62,16 @@ http_default = Mux.notfound()) const serving = Ref(false) +const server = Ref{Mux.HTTP.Servers.Server}() function serve() serving[] && return serving[] = true - @async begin - Mux.serve(Mux.App(http_default), Mux.App(ws_handler), ip"127.0.0.1", port[]) - end + server[] = Mux.serve(Mux.App(http_default), Mux.App(ws_handler), ip"127.0.0.1", port[]) +end + +function stopserve() + serving[] || return + serving[] = false + close(server[]) end