signal-desktop/js/views/settings_view.js

261 lines
9.3 KiB
JavaScript
Raw Normal View History

2016-02-19 00:13:53 +00:00
/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
const { OS } = window.Signal;
const { Settings } = window.Signal.Types;
2016-02-19 00:13:53 +00:00
var CheckboxView = Whisper.View.extend({
initialize: function(options) {
this.name = options.name;
this.defaultValue = options.defaultValue;
this.event = options.event;
this.populate();
},
events: {
'change': 'change'
},
change: function(e) {
var value = e.target.checked;
storage.put(this.name, value);
console.log(this.name, 'changed to', value);
if (this.event) {
this.$el.trigger(this.event);
}
},
populate: function() {
var value = storage.get(this.name, this.defaultValue);
this.$('input').prop('checked', !!value);
},
});
2016-08-29 07:03:37 +00:00
var RadioButtonGroupView = Whisper.View.extend({
initialize: function(options) {
this.name = options.name;
this.defaultValue = options.defaultValue;
this.event = options.event;
2016-08-29 07:03:37 +00:00
this.populate();
},
2016-02-19 00:13:53 +00:00
events: {
2016-08-29 07:03:37 +00:00
'change': 'change'
2016-02-19 00:13:53 +00:00
},
change: function(e) {
var value = this.$(e.target).val();
2016-08-29 07:03:37 +00:00
storage.put(this.name, value);
console.log(this.name, 'changed to', value);
if (this.event) {
this.$el.trigger(this.event);
}
2016-02-19 00:13:53 +00:00
},
2016-08-29 07:03:37 +00:00
populate: function() {
var value = storage.get(this.name, this.defaultValue);
this.$('#' + this.name + '-' + value).attr('checked', 'checked');
},
});
Whisper.SettingsView = Whisper.View.extend({
className: 'settings modal expand',
2016-08-29 07:03:37 +00:00
templateName: 'settings',
initialize: function() {
New design for import/install, 'light' import (#2053) - A new design for the import flow. It features: - Icons at the top of every screen - Gray background, blue buttons, thinner text - Simpler copy - A new design for the install flow. It features: - Immediate entry into the QR code screen - Animated dots to show that we're loading the QR code from the server - Fewer screens: 1) QR 2) device name 3) sync-in-progress - When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow. - Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow. - A new design for the (dev-only) standalone registration view - When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows. - The device name (chosen on initial setup) is now shown in the settings panel - At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports. - `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export. - `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import. - On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast. - Disappearing messages are now excluded when exporting - Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
this.deviceName = textsecure.storage.user.getDeviceName();
2016-08-29 07:03:37 +00:00
this.render();
new RadioButtonGroupView({
el: this.$('.notification-settings'),
defaultValue: 'message',
name: 'notification-setting'
});
new RadioButtonGroupView({
el: this.$('.theme-settings'),
2016-09-30 11:11:22 +00:00
defaultValue: 'android',
name: 'theme-setting',
event: 'change-theme'
2016-08-29 07:03:37 +00:00
});
if (Settings.isAudioNotificationSupported()) {
new CheckboxView({
el: this.$('.audio-notification-setting'),
defaultValue: false,
name: 'audio-notification'
});
}
new CheckboxView({
el: this.$('.menu-bar-setting'),
defaultValue: false,
name: 'hide-menu-bar',
event: 'change-hide-menu'
});
if (textsecure.storage.user.getDeviceId() != '1') {
var syncView = new SyncView().render();
this.$('.sync-setting').append(syncView.el);
}
2016-02-19 00:13:53 +00:00
},
2016-08-29 07:03:37 +00:00
events: {
'click .close': 'remove',
'click .clear-data': 'onClearData',
2016-08-29 07:03:37 +00:00
},
2016-02-19 00:13:53 +00:00
render_attributes: function() {
return {
New design for import/install, 'light' import (#2053) - A new design for the import flow. It features: - Icons at the top of every screen - Gray background, blue buttons, thinner text - Simpler copy - A new design for the install flow. It features: - Immediate entry into the QR code screen - Animated dots to show that we're loading the QR code from the server - Fewer screens: 1) QR 2) device name 3) sync-in-progress - When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow. - Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow. - A new design for the (dev-only) standalone registration view - When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows. - The device name (chosen on initial setup) is now shown in the settings panel - At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports. - `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export. - `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import. - On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast. - Disappearing messages are now excluded when exporting - Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
deviceNameLabel: i18n('deviceName'),
deviceName: this.deviceName,
2016-09-23 12:12:07 +00:00
theme: i18n('theme'),
notifications: i18n('notifications'),
notificationSettingsDialog: i18n('notificationSettingsDialog'),
2016-02-19 00:13:53 +00:00
settings: i18n('settings'),
disableNotifications: i18n('disableNotifications'),
2016-02-19 00:13:53 +00:00
nameAndMessage: i18n('nameAndMessage'),
noNameOrMessage: i18n('noNameOrMessage'),
nameOnly: i18n('nameOnly'),
audioNotificationDescription: i18n('audioNotificationDescription'),
isAudioNotificationSupported: Settings.isAudioNotificationSupported(),
themeAndroidDark: i18n('themeAndroidDark'),
hideMenuBar: i18n('hideMenuBar'),
clearDataHeader: i18n('clearDataHeader'),
clearDataButton: i18n('clearDataButton'),
clearDataExplanation: i18n('clearDataExplanation'),
};
},
onClearData: function() {
var clearDataView = new ClearDataView().render();
$('body').append(clearDataView.el);
},
});
var CLEAR_DATA_STEPS = {
CHOICE: 1,
DELETING: 2,
};
var ClearDataView = Whisper.View.extend({
templateName: 'clear-data',
className: 'full-screen-flow overlay',
events: {
'click .cancel': 'onCancel',
'click .delete-all-data': 'onDeleteAllData',
},
initialize: function() {
this.step = CLEAR_DATA_STEPS.CHOICE;
},
onCancel: function() {
this.remove();
},
onDeleteAllData: function() {
console.log('Deleting everything!');
this.step = CLEAR_DATA_STEPS.DELETING;
this.render();
window.wrapDeferred(Backbone.sync('closeall')).then(function() {
console.log('All database connections closed. Starting delete.');
this.clearAllData();
}.bind(this), function(error) {
console.log('Something went wrong closing all database connections.');
this.clearAllData();
}.bind(this));
},
clearAllData: function() {
var finishCount = 0;
var finish = function() {
finishCount += 1;
console.log('Deletion complete, finishCount is now', finishCount);
if (finishCount > 1) {
console.log('Deletion complete! Restarting now...');
window.restart();
}
};
var request = window.indexedDB.deleteDatabase('signal');
// None of the three of these should happen, since we close all database
// connections first. However, testing indicates that even if one of these
// handlers fires, the database is still deleted on restart.
request.onblocked = function(event) {
console.log('Error deleting database: Blocked.');
finish();
};
request.onupgradeneeded = function(event) {
console.log('Error deleting database: Upgrade needed.');
finish();
};
request.onerror = function(event) {
console.log('Error deleting database.');
finish();
};
request.onsuccess = function(event) {
console.log('Database deleted successfully.');
finish();
};
Whisper.events.once('deleteAllLogsComplete', function() {
console.log('Log deleted successfully.');
finish();
});
window.deleteAllLogs();
},
render_attributes: function() {
return {
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
header: i18n('deleteAllDataHeader'),
body: i18n('deleteAllDataBody'),
cancelButton: i18n('cancel'),
deleteButton: i18n('deleteAllDataButton'),
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
deleting: i18n('deleteAllDataProgress'),
2016-02-19 00:13:53 +00:00
};
}
});
var SyncView = Whisper.View.extend({
templateName: 'syncSettings',
className: 'syncSettings',
events: {
'click .sync': 'sync'
},
enable: function() {
this.$('.sync').text(i18n('syncNow'));
this.$('.sync').removeAttr('disabled');
},
disable: function() {
this.$('.sync').attr('disabled', 'disabled');
this.$('.sync').text(i18n('syncing'));
},
onsuccess: function() {
storage.put('synced_at', Date.now());
console.log('sync successful');
this.enable();
this.render();
},
ontimeout: function() {
console.log('sync timed out');
this.$('.synced_at').hide();
this.$('.sync_failed').show();
this.enable();
},
sync: function() {
this.$('.sync_failed').hide();
if (textsecure.storage.user.getDeviceId() != '1') {
this.disable();
var syncRequest = window.getSyncRequest();
syncRequest.addEventListener('success', this.onsuccess.bind(this));
syncRequest.addEventListener('timeout', this.ontimeout.bind(this));
} else {
console.log("Tried to sync from device 1");
}
},
render_attributes: function() {
var attrs = {
sync: i18n('sync'),
syncNow: i18n('syncNow'),
syncExplanation: i18n('syncExplanation'),
syncFailed: i18n('syncFailed')
};
var date = storage.get('synced_at');
if (date) {
date = new Date(date);
attrs.lastSynced = i18n('lastSynced');
attrs.syncDate = date.toLocaleDateString();
attrs.syncTime = date.toLocaleTimeString();
}
return attrs;
}
});
2016-02-19 00:13:53 +00:00
})();