Skip to content

Commit 062611f

Browse files
committed
resize electron on screenshot
1 parent 3f2a1c6 commit 062611f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

NetworkDynamicsInspector/src/serving.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ function has_electron_window end
132132
function get_electron_app end
133133
function get_electron_window end
134134

135-
function save_electron_screenshot(path=joinpath(@__DIR__, "screenshot.png"))
135+
function save_electron_screenshot(path=joinpath(@__DIR__, "screenshot.png"), resize=true)
136+
resize && _resize_electron_to_content()
137+
136138
path = isabspath(path) ? path : joinpath(pwd(), path)
137139
has_electron_window()|| error("No Electron window exists!")
138140
winid = get_electron_window().id
@@ -152,3 +154,28 @@ function save_electron_screenshot(path=joinpath(@__DIR__, "screenshot.png"))
152154
end
153155
nothing
154156
end
157+
158+
function _resize_electron_to_content()
159+
window = get_electron_window()
160+
js_max_h = """
161+
{
162+
let maxHeight = 0;
163+
Array.from(document.querySelectorAll('.graphplot-col, .timeseries-col')).forEach(el => {
164+
const height = el.offsetHeight;
165+
console.log(height)
166+
if (height > maxHeight) {
167+
maxHeight = height;
168+
}
169+
})
170+
maxHeight
171+
}
172+
"""
173+
y = run(window, js_max_h)
174+
175+
run(get_electron_app(), """
176+
{
177+
let win = BrowserWindow.fromId($(window.id))
178+
win.setSize(win.getSize()[0], $y)
179+
}
180+
""")
181+
end

0 commit comments

Comments
 (0)