Skip to content

Commit

Permalink
Merge pull request #318 from alexriss/master
Browse files Browse the repository at this point in the history
add option to close server and end electron process
  • Loading branch information
pfitzseb authored Dec 8, 2023
2 parents c3ed759 + 2ead5b7 commit 3628e47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AtomShell/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ..Blink
import Blink: js, id
import Blink: js, id, stopserve
import JSExpr: JSString, jsstring
import Base: position, size, close

Expand Down Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions src/content/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3628e47

Please sign in to comment.