feat: prevent window close on sessions open (#227)
This commit is contained in:
parent
f457388b83
commit
60b9380fe2
@ -114,6 +114,7 @@ class Access extends Component {
|
|||||||
this.renderDisplay(sessionId, protocol, width, height);
|
this.renderDisplay(sessionId, protocol, width, height);
|
||||||
|
|
||||||
window.addEventListener('resize', this.onWindowResize);
|
window.addEventListener('resize', this.onWindowResize);
|
||||||
|
window.addEventListener('beforeunload', this.handleUnload);
|
||||||
window.onfocus = this.onWindowFocus;
|
window.onfocus = this.onWindowFocus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +122,7 @@ class Access extends Component {
|
|||||||
if (this.state.client) {
|
if (this.state.client) {
|
||||||
this.state.client.disconnect();
|
this.state.client.disconnect();
|
||||||
}
|
}
|
||||||
|
window.removeEventListener('beforeunload', this.handleUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendClipboard(data) {
|
sendClipboard(data) {
|
||||||
@ -528,6 +530,12 @@ class Access extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleUnload(e) {
|
||||||
|
var message = "要离开网站吗?";
|
||||||
|
(e || window.event).returnValue = message; //Gecko + IE
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
resize = async (sessionId, width, height) => {
|
resize = async (sessionId, width, height) => {
|
||||||
let result = await request.post(`/sessions/${sessionId}/resize?width=${width}&height=${height}`);
|
let result = await request.post(`/sessions/${sessionId}/resize?width=${width}&height=${height}`);
|
||||||
if (result.code !== 1) {
|
if (result.code !== 1) {
|
||||||
|
@ -166,6 +166,7 @@ class Term extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('resize', this.onWindowResize);
|
window.addEventListener('resize', this.onWindowResize);
|
||||||
|
window.addEventListener('beforeunload', this.handleUnload);
|
||||||
window.onunload = function () {
|
window.onunload = function () {
|
||||||
webSocket.close();
|
webSocket.close();
|
||||||
};
|
};
|
||||||
@ -176,6 +177,7 @@ class Term extends Component {
|
|||||||
if (webSocket) {
|
if (webSocket) {
|
||||||
webSocket.close()
|
webSocket.close()
|
||||||
}
|
}
|
||||||
|
window.removeEventListener('beforeunload', this.handleUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommands = async () => {
|
getCommands = async () => {
|
||||||
@ -251,6 +253,12 @@ class Term extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleUnload(e) {
|
||||||
|
var message = "要离开网站吗?";
|
||||||
|
(e || window.event).returnValue = message; //Gecko + IE
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
writeCommand = (command) => {
|
writeCommand = (command) => {
|
||||||
let webSocket = this.state.webSocket;
|
let webSocket = this.state.webSocket;
|
||||||
if (webSocket !== undefined) {
|
if (webSocket !== undefined) {
|
||||||
|
Loading…
Reference in New Issue
Block a user