Skip to content

Commit 9df5d2f

Browse files
authored
Use websockets to detect tab close (#223)
* run a websocket + http server * this might just work * choose a websocket port and connect to it * connect on hostname * version bump * websocket server is not shutting down * giving up on websockets * port text handlers to aiohttp * set up websocket on the same port * able to shut down, but getting a stack trace * maybe SIGINT works * pare back * port image endpoints * drop websockets dependency * drop SERVER * cleanup * bump JS version
1 parent 2ca1937 commit 9df5d2f

7 files changed

Lines changed: 645 additions & 234 deletions

File tree

poetry.lock

Lines changed: 430 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "webdiff"
7-
version = "1.2.0"
7+
version = "1.3.0"
88
description = "Two-column web-based git difftool"
99
license = "Apache-2.0"
1010
readme = "README.md"
@@ -30,6 +30,7 @@ binaryornot = "*"
3030
pillow = "*"
3131
PyGithub = "2.3.0"
3232
unidiff = "==0.7.4"
33+
aiohttp = "^3.9.5"
3334

3435
[tool.poetry.group.dev.dependencies]
3536
pytest = "^7.1.3"

test-gitwebdiff.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#!/bin/bash
22
export DEBUG=true
33
export WEBDIFF_PORT=6001
4-
export WEBDIFF_NO_OPEN=true
54

6-
sleep 1 && open 'http://localhost:6001' &
7-
8-
npx nodemon \
9-
-w webdiff \
10-
--ext py,html,js \
11-
-x poetry run webdiff/gitwebdiff.py $*
5+
poetry run webdiff/gitwebdiff.py $*

ts/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ const App = () => (
1414

1515
injectStylesFromConfig();
1616
ReactDOM.render(<App />, document.getElementById('application'));
17+
18+
const host = window.location.host;
19+
const websocket = new WebSocket(`ws://${host}/ws`);
20+
websocket.onmessage = msg => {
21+
// no op
22+
};
23+
websocket.onopen = e => {
24+
websocket.send('hello!');
25+
};

ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webdiff",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "client-side code for webdiff",
55
"main": "index.js",
66
"author": "Dan Vanderkam (danvdk@gmail.com)",

0 commit comments

Comments
 (0)