mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
Make "Connecting..." toast persistent until connection is established
This commit is contained in:
parent
4e00e5b358
commit
684fe7142d
4 changed files with 28 additions and 14 deletions
|
@ -38,6 +38,12 @@ class ServerConnection {
|
||||||
_connect() {
|
_connect() {
|
||||||
clearTimeout(this._reconnectTimer);
|
clearTimeout(this._reconnectTimer);
|
||||||
if (this._isConnected() || this._isConnecting()) return;
|
if (this._isConnected() || this._isConnecting()) return;
|
||||||
|
if (this._isReconnect) {
|
||||||
|
Events.fire('notify-user', {
|
||||||
|
message: Localization.getTranslation("notifications.connecting"),
|
||||||
|
persistent: true
|
||||||
|
});
|
||||||
|
}
|
||||||
const ws = new WebSocket(this._endpoint());
|
const ws = new WebSocket(this._endpoint());
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
ws.onopen = _ => this._onOpen();
|
ws.onopen = _ => this._onOpen();
|
||||||
|
@ -221,12 +227,10 @@ class ServerConnection {
|
||||||
_onDisconnect() {
|
_onDisconnect() {
|
||||||
console.log('WS: server disconnected');
|
console.log('WS: server disconnected');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Events.fire('notify-user', Localization.getTranslation("notifications.connecting"));
|
|
||||||
}, 100); //delay for 100ms to prevent flickering on page reload
|
|
||||||
clearTimeout(this._reconnectTimer);
|
|
||||||
this._reconnectTimer = setTimeout(_ => this._connect(), 1000);
|
|
||||||
Events.fire('ws-disconnected');
|
|
||||||
this._isReconnect = true;
|
this._isReconnect = true;
|
||||||
|
Events.fire('ws-disconnected');
|
||||||
|
this._reconnectTimer = setTimeout(_ => this._connect(), 1000);
|
||||||
|
}, 100); //delay for 100ms to prevent flickering on page reload
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVisibilityChange() {
|
_onVisibilityChange() {
|
||||||
|
|
|
@ -2044,9 +2044,12 @@ class Toast extends Dialog {
|
||||||
|
|
||||||
_onNotify(message) {
|
_onNotify(message) {
|
||||||
if (this.hideTimeout) clearTimeout(this.hideTimeout);
|
if (this.hideTimeout) clearTimeout(this.hideTimeout);
|
||||||
this.$el.innerText = message;
|
this.$el.innerText = typeof message === "object" ? message.message : message;
|
||||||
this.show();
|
this.show();
|
||||||
this.hideTimeout = setTimeout(_ => this.hide(), 5000);
|
|
||||||
|
if (typeof message === "object" && message.persistent) return;
|
||||||
|
|
||||||
|
this.hideTimeout = setTimeout(() => this.hide(), 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,12 @@ class ServerConnection {
|
||||||
_connect() {
|
_connect() {
|
||||||
clearTimeout(this._reconnectTimer);
|
clearTimeout(this._reconnectTimer);
|
||||||
if (this._isConnected() || this._isConnecting()) return;
|
if (this._isConnected() || this._isConnecting()) return;
|
||||||
|
if (this._isReconnect) {
|
||||||
|
Events.fire('notify-user', {
|
||||||
|
message: Localization.getTranslation("notifications.connecting"),
|
||||||
|
persistent: true
|
||||||
|
});
|
||||||
|
}
|
||||||
const ws = new WebSocket(this._endpoint());
|
const ws = new WebSocket(this._endpoint());
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
ws.onopen = _ => this._onOpen();
|
ws.onopen = _ => this._onOpen();
|
||||||
|
@ -232,12 +238,10 @@ class ServerConnection {
|
||||||
_onDisconnect() {
|
_onDisconnect() {
|
||||||
console.log('WS: server disconnected');
|
console.log('WS: server disconnected');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Events.fire('notify-user', Localization.getTranslation("notifications.connecting"));
|
|
||||||
}, 100); //delay for 100ms to prevent flickering on page reload
|
|
||||||
clearTimeout(this._reconnectTimer);
|
|
||||||
this._reconnectTimer = setTimeout(_ => this._connect(), 1000);
|
|
||||||
Events.fire('ws-disconnected');
|
|
||||||
this._isReconnect = true;
|
this._isReconnect = true;
|
||||||
|
Events.fire('ws-disconnected');
|
||||||
|
this._reconnectTimer = setTimeout(_ => this._connect(), 1000);
|
||||||
|
}, 100); //delay for 100ms to prevent flickering on page reload
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVisibilityChange() {
|
_onVisibilityChange() {
|
||||||
|
|
|
@ -2046,9 +2046,12 @@ class Toast extends Dialog {
|
||||||
|
|
||||||
_onNotify(message) {
|
_onNotify(message) {
|
||||||
if (this.hideTimeout) clearTimeout(this.hideTimeout);
|
if (this.hideTimeout) clearTimeout(this.hideTimeout);
|
||||||
this.$el.innerText = message;
|
this.$el.innerText = typeof message === "object" ? message.message : message;
|
||||||
this.show();
|
this.show();
|
||||||
this.hideTimeout = setTimeout(_ => this.hide(), 5000);
|
|
||||||
|
if (typeof message === "object" && message.persistent) return;
|
||||||
|
|
||||||
|
this.hideTimeout = setTimeout(() => this.hide(), 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue