client: make warn-on-close optional, default false

This commit is contained in:
mappu 2017-02-05 22:47:25 +13:00
parent aa8d89d14b
commit 763f5030d1

View File

@ -682,6 +682,7 @@ menu.reset = function() {
this.clear(); this.clear();
this.add(joinparts_getstr(), toggle_joinparts); this.add(joinparts_getstr(), toggle_joinparts);
this.add(desktop_notifications_fmtstr(), desktop_notifications_toggle); this.add(desktop_notifications_fmtstr(), desktop_notifications_toggle);
this.add(warnonclose_fmtstr(), warnonclose_toggle);
this.add(timestamp_display(), timestamp_toggle); this.add(timestamp_display(), timestamp_toggle);
}; };
@ -810,6 +811,8 @@ var timestamp_format_index = 0;
var mainchat_unread_count = 0; var mainchat_unread_count = 0;
var should_warn_on_close = false;
var timestamp_display = function() { var timestamp_display = function() {
return "Timestamp format: " + timestamp_names[timestamp_format_index]; return "Timestamp format: " + timestamp_names[timestamp_format_index];
}; };
@ -821,6 +824,17 @@ var timestamp_toggle = function(ev) {
$el.innerHTML = timestamp_display(); $el.innerHTML = timestamp_display();
}; };
var warnonclose_fmtstr = function() {
return (should_warn_on_close ? "☑" : "☐") + " Confirm closing window";
};
var warnonclose_toggle = function(ev) {
var $el = ev.target || ev.srcElement;
should_warn_on_close = !should_warn_on_close;
persistence_set("warnonclose", should_warn_on_close);
$el.innerHTML = warnonclose_fmtstr();
};
var desktop_notifications_enabled = false; var desktop_notifications_enabled = false;
var desktop_notifications_fmtstr = function() { var desktop_notifications_fmtstr = function() {
@ -982,7 +996,7 @@ window.onload = function() {
}; };
window.onbeforeunload = function (e) { window.onbeforeunload = function (e) {
if (hub_state === STATE_ACTIVE) { if (should_warn_on_close && hub_state === STATE_ACTIVE) {
// n.b. recent Firefox / Chrome don't display the custom message here. // n.b. recent Firefox / Chrome don't display the custom message here.
var confirmationMessage = "Still connected to the hub \"" + hub_hubname + "\".\nAre you sure you want to close?"; var confirmationMessage = "Still connected to the hub \"" + hub_hubname + "\".\nAre you sure you want to close?";
e.returnValue = confirmationMessage; e.returnValue = confirmationMessage;
@ -993,6 +1007,8 @@ window.onload = function() {
timestamp_format_index = persistence_get("timestamps", 0); timestamp_format_index = persistence_get("timestamps", 0);
should_warn_on_close = persistence_get("warnonclose");
desktop_notifications_enabled = persistence_get("popups"); desktop_notifications_enabled = persistence_get("popups");
if (desktop_notifications_enabled) { if (desktop_notifications_enabled) {
// prompt for permissions // prompt for permissions