Skip to content

Commit

Permalink
Merge pull request #545 from vidartf/tool-beacon
Browse files Browse the repository at this point in the history
Use sendBeacon to send close requests
  • Loading branch information
vidartf committed Sep 29, 2020
2 parents b707946 + ca3b311 commit 77cac58
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
python:
- 3.9-dev
- 3.8
- 3.7
- 3.6
- 3.5
sudo: false
dist: xenial
services:
Expand All @@ -13,7 +13,7 @@ env:
- GROUP=python
matrix:
include:
- python: 3.5
- python: 3.8
env: GROUP=js
cache:
pip: true
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ skip_branch_with_pr: true
environment:
nodejs_version: "8.15"
matrix:
- PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.x"
- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.x"
PYTHON_MAJOR: 3
PYTHON_ARCH: "64"
- PYTHON: "C:\\Python38-x64"
Expand Down
8 changes: 4 additions & 4 deletions nbdime/tests/test_cli_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def test_git_difftool(git_repo, unique_port, popen_with_terminator):
r = requests.get(url + '/difftool')
r.raise_for_status()
# close it
r = requests.post(url + '/api/closetool', headers={'exit_code': '0'})
r = requests.post(url + '/api/closetool', json={'exitCode': 0})
r.raise_for_status()
time.sleep(0.25)
# wait for exit
Expand Down Expand Up @@ -647,7 +647,7 @@ def test_git_mergetool(git_repo, unique_port, popen_with_terminator):
)
r.raise_for_status()
# close it
r = requests.post(url + '/api/closetool', headers={'exit_code': '0'})
r = requests.post(url + '/api/closetool', json={'exitCode': 0})
r.raise_for_status()
# wait for exit
process.wait()
Expand Down Expand Up @@ -709,7 +709,7 @@ def test_hg_diffweb(hg_repo, unique_port, popen_with_terminator):
r = requests.get(url + '/difftool')
r.raise_for_status()
# close it
r = requests.post(url + '/api/closetool', headers={'exit_code': '0'})
r = requests.post(url + '/api/closetool', json={'exitCode': 0})
r.raise_for_status()
time.sleep(0.25)
# wait for exit
Expand Down Expand Up @@ -743,7 +743,7 @@ def test_hg_mergetool(hg_repo, unique_port, popen_with_terminator):
)
r.raise_for_status()
# close it
r = requests.post(url + '/api/closetool', headers={'exit_code': '0'})
r = requests.post(url + '/api/closetool', json={'exitCode': 0})
r.raise_for_status()
# wait for exit
process.wait()
Expand Down
6 changes: 5 additions & 1 deletion nbdime/webapp/nbdimeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ def post(self):
400, 'This server cannot be closed remotely.')

# Fail if no exit code is supplied:
self.application.exit_code = int(self.request.headers.get('exit_code', 1))
fallback = int(self.request.headers.get('exit_code', 1))
try:
self.application.exit_code = json.loads(self.request.body).get('exitCode', fallback)
except json.JSONDecodeError:
self.application.exit_code = fallback

_logger.info('Closing server on remote request')
self.finish()
Expand Down
5 changes: 1 addition & 4 deletions packages/webapp/src/app/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,8 @@ export
function closeTool(exitCode=0) {
if (!toolClosed) {
toolClosed = true;
let xhttp = new XMLHttpRequest();
let url = '/api/closetool';
xhttp.open('POST', url, false);
xhttp.setRequestHeader('exit_code', exitCode.toString());
xhttp.send();
navigator.sendBeacon(url, JSON.stringify({exitCode}));
window.close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
],
}

setup_args['python_requires'] = '>=3.5'
setup_args['python_requires'] = '>=3.6'

setup_args['entry_points'] = {
'console_scripts': [
Expand Down

0 comments on commit 77cac58

Please sign in to comment.