add a setting to preserve redirect-to-drive behaviour from the home page

disable it by default
pull/1/head
ansuz 4 years ago
parent 1fe57c7e03
commit 3fbb771b9c

@ -12,7 +12,7 @@ define([
// Make sure we don't display non-translated content (empty button)
$main.find('#data').removeClass('hidden');
if (LocalStore.isLoggedIn()) {
if (LocalStore.isLoggedIn() && LocalStore.getDriveRedirectPreference()) {
if (window.location.pathname === '/') {
window.location = '/drive/';
return;

@ -10,6 +10,7 @@ define(['/customize/application_config.js'], function (AppConfig) {
oldStorageKey: 'CryptPad_RECENTPADS',
storageKey: 'filesData',
tokenKey: 'loginToken',
prefersDriveRedirectKey: 'prefersDriveRedirect',
displayPadCreationScreen: 'displayPadCreationScreen',
deprecatedKey: 'deprecated',
MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 5,

@ -1103,6 +1103,11 @@ define([
postMessage('BURN_PAD', data);
};
common.setDriveRedirectPreference = function (data, cb) {
LocalStore.setDriveRedirectPreference(data && data.value);
cb();
};
common.changePadPassword = function (Crypt, Crypto, data, cb) {
var href = data.href;
var oldPassword = data.oldPassword;
@ -2506,6 +2511,11 @@ define([
}
if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); }
var prefersDriveRedirect = data[Constants.prefersDriveRedirectKey];
if (typeof(prefersDriveRedirect) === 'boolean') {
LocalStore.setDriveRedirectPreference(prefersDriveRedirect);
}
initialized = true;
channelIsReady();
});

@ -3167,6 +3167,10 @@ define([
initialized = false;
}
var redirect = Constants.prefersDriveRedirectKey;
var redirectPreference = Util.find(store, [ 'proxy', 'settings', 'general', redirect, ]);
ret[redirect] = redirectPreference;
callback(ret);
});

@ -76,6 +76,16 @@ define([
return window.CP_logged_in || typeof getUserHash() === "string";
};
LocalStore.getDriveRedirectPreference = function () {
try {
return JSON.parse(localStorage[Constants.redirectToDriveKey]);
} catch (err) { return; }
};
LocalStore.setDriveRedirectPreference = function (bool) {
localStorage.setItem(Constants.redirectToDriveKey, Boolean(bool));
};
LocalStore.login = function (hash, name, cb) {
if (!hash) { throw new Error('expected a user hash'); }
if (!name) { throw new Error('expected a user name'); }

@ -615,6 +615,7 @@ define([
newTemplate: Array.isArray(Cryptpad.initialPath)
&& Cryptpad.initialPath[0] === "template",
feedbackAllowed: Utils.Feedback.state,
prefersDriveRedirect: Utils.LocalStore.getDriveRedirectPreference(),
isPresent: parsed.hashData && parsed.hashData.present,
isEmbed: parsed.hashData && parsed.hashData.embed,
oldVersionHash: parsed.hashData && parsed.hashData.version < 2, // password

@ -14,6 +14,7 @@ define([
'/api/config',
'/common/make-backup.js',
'/common/common-feedback.js',
'/common/common-constants.js',
'/common/jscolor.js',
'/bower_components/file-saver/FileSaver.min.js',
@ -35,7 +36,8 @@ define([
AppConfig,
ApiConfig,
Backup,
Feedback
Feedback,
Constants
) {
var saveAs = window.saveAs;
var APP = window.APP = {};
@ -72,7 +74,8 @@ define([
'cp-settings-thumbnails',
'cp-settings-drive-backup',
'cp-settings-drive-import-local',
'cp-settings-trim-history'
'cp-settings-trim-history',
'cp-settings-redirect',
//'cp-settings-drive-reset'
],
'cursor': [ // Msg.settings_cat_cursor
@ -841,6 +844,49 @@ define([
return $div;
};
Messages.settings_driveRedirectTitle = "DRIVE REDIRECT TITLE"; // XXX redirect
Messages.settings_driveRedirectHint = "DRIVE REDIRECT HINT"; // XXX redirect
Messages.settings_driveRedirect = "DRIVE REDIRECT"; // XXX redirect
create['redirect'] = function () {
if (!common.isLoggedIn()) { return; }
var $div = $('<div>', { 'class': 'cp-settings-redirect cp-sidebarlayout-element' });
$('<span>', { 'class': 'label' }).text(Messages.settings_driveRedirectTitle).appendTo($div);
$('<span>', { 'class': 'cp-sidebarlayout-description' })
.append(Messages.settings_driveRedirectHint)
.appendTo($div);
var $ok = $('<span>', { 'class': 'fa fa-check', title: Messages.saved });
var $spinner = $('<span>', { 'class': 'fa fa-spinner fa-pulse' });
var $cbox = $(UI.createCheckbox('cp-settings-redirect',
Messages.settings_driveRedirect,
false, { label: { class: 'noTitle' } }));
var $checkbox = $cbox.find('input').on('change', function() {
$spinner.show();
$ok.hide();
var val = $checkbox.is(':checked') || false;
common.setAttribute(['general', Constants.prefersDriveRedirectKey, val, function() {
$spinner.hide();
$ok.show();
sframeChan.query("Q_SET_DRIVE_REDIRECT_PREFERENCE", {
value: val,
}, console.log);
});
});
$cbox.appendTo($div);
$ok.hide().appendTo($cbox);
$spinner.hide().appendTo($cbox);
if (privateData.prefersDriveRedirect === true) {
$checkbox[0].checked = true;
}
return $div;
};
create['resettips'] = function() {
var $div = $('<div>', { 'class': 'cp-settings-resettips cp-sidebarlayout-element' });

@ -78,6 +78,9 @@ define([
}
cb();
});
sframeChan.on('Q_SET_DRIVE_REDIRECT_PREFERENCE', function (data, cb) {
Cryptpad.setDriveRedirectPreference(data, cb);
});
};
var category;
if (window.location.hash) {

Loading…
Cancel
Save