Skip to content

Commit f0ccbf0

Browse files
committed
common interface for serving
1 parent a643d1b commit f0ccbf0

File tree

6 files changed

+423
-328
lines changed

6 files changed

+423
-328
lines changed

NetworkDynamicsInspector/ext/ElectronExt.jl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@ using Electron: Electron, windows
55
using Bonito: Bonito, HTTPServer
66

77
const ELECTRON_APP = Ref{Any}(nothing)
8+
const ELECTRON_DISP = Ref{Any}(nothing)
89

9-
function NDI.display_electron_app(restart)
10-
restart && close_windows()
11-
webapp = NDI.get_webapp()
10+
function NDI.serve_app(::NDI.ElectronDisp, app)
1211
disp = get_electron_display()
13-
display(disp, webapp)
12+
display(disp, app)
1413
nothing
1514
end
1615

16+
function NDI.close_display(::NDI.ElectronDisp; strict)
17+
if haswindow()
18+
@info "Close existing Windows"
19+
close.(windows(ELECTRON_APP[]))
20+
end
21+
if strict
22+
close_application()
23+
end
24+
end
25+
1726
function get_electron_display()
1827
window = get_electron_window()
19-
disp = HTTPServer.ElectronDisplay(window, HTTPServer.BrowserDisplay(; open_browser=false))
28+
# BUG: Electron display cannot be reused
29+
# if isnothing(ELECTRON_DISP[]) || window != ELECTRON_DISP[].window
30+
# disp = HTTPServer.ElectronDisplay(window, HTTPServer.BrowserDisplay(; open_browser=false))
31+
# ELECTRON_DISP[] = disp
32+
# else
33+
# ELECTRON_DISP[]
34+
# end
35+
return HTTPServer.ElectronDisplay(window, HTTPServer.BrowserDisplay(; open_browser=false))
2036
end
2137

2238
function get_electron_window()
@@ -50,13 +66,6 @@ function get_electron_app()
5066
end
5167
hasapp() = !isnothing(ELECTRON_APP[]) && ELECTRON_APP[].exists
5268

53-
function close_windows()
54-
if haswindow()
55-
@info "Close existing Windows"
56-
close.(windows(ELECTRON_APP[]))
57-
end
58-
end
59-
6069
function close_application()
6170
if hasapp()
6271
@info "Close Electron Application"

0 commit comments

Comments
 (0)