Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to close server and end electron process #318

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading